@echo ON
SETLOCAL EnableDelayedExpansion


%~d0
cd %~dp0


sc config sharedaccess start= demand
net stop sharedaccess
cscript "%~dp0/DisableICS.wsf"


wmic nic where "ProductName like '%%VMnet1%%'" get netconnectionid|more /s +1 > %TEMP%\adaptername.txt
<%TEMP%\adaptername.txt (
  set /p AdapterNameFromLine1=
)
del %temp%\adaptername.txt
for /f "tokens=* delims= " %%a in ('echo %AdapterNameFromLine1%') do (
	set AdapterNameFromLine1=%%~na
)
netsh interface ipv4 set address name="%AdapterNameFromLine1%" dhcp


wmic nic where "ProductName like '%%VMnet8%%'" get netconnectionid|more /s +1 > %TEMP%\adaptername.txt
<%TEMP%\adaptername.txt (
  set /p AdapterNameFromLine1=
)
del %temp%\adaptername.txt
for /f "tokens=* delims= " %%a in ('echo %AdapterNameFromLine1%') do (
	set AdapterNameFromLine1=%%~na
)
netsh interface ipv4 set address name="%AdapterNameFromLine1%" static 192.168.137.3 255.255.248.0
IF %errorlevel% NEQ 0 goto :exitwitherror


copy /B /D /Y /Z /L *.conf %ALLUSERSPROFILE%\VMware\
IF %errorlevel% NEQ 0 goto :exitwitherror


sc config VMnetDHCP start= disabled
sc stop VMnetDHCP

sc config "VMware NAT Service" start= auto
net stop "VMware NAT Service"
net start "VMware NAT Service"
IF %errorlevel% NEQ 0 goto :exitwitherror


timeout /t 3 /nobreak > NUL
exit /b 0

:exitwitherror
echo Waiting 30 seconds before exiting so you can look at errors!
timeout /t 30 /nobreak > NUL
exit /B %errorlevel%


:TRIM
SET %2=%1
GOTO :EOF
