New
#1
Problem with echo in batch script
Morning i have a problem with batch script in Windows 7.
this is my code:
The first part of the script disable uac then at the computer restart i search for the network card of the pc in the registry. when i found it (in the file id.txt in the point rem *1) i change some values to enable the wake on lan properties.Code:@echo off set mypath=c:\tools if not exist "%mypath%\architet.txt" goto check3264 find /I "x64-based PC" "%mypath%\architet.txt" >nul 2>&1 if %errorlevel% EQU 0 (set architet=64) ELSE (set architet=32) goto uacok :check3264 echo Find Windows 7 32 or 64 Bit systeminfo.exe >"%mypath%\architet.txt" 2>&1 find /I "x64-based PC" "%mypath%\architet.txt" >nul 2>&1 if %errorlevel% EQU 0 ( echo 64bit Found set architet=64 echo Disable UAC "%mypath%\file\hstart64.exe" /RUNAS "WScript //Nologo c:\tools\uac.js" goto restart ) ELSE ( echo 32bit Found set architet=32 echo Disable UAC "%mypath%\file\hstart.exe" /RUNAS "WScript //Nologo c:\tools\uac.js" goto restart ) :uacok rem find if pc is Eeetop 2010 if exist "%windir%\EeeTOP.scr" ( echo EeeTop ET2010 Found echo Removing components del /F /Q "%windir%\EeeTOP.scr" wmic nic list brief >"%mypath%\net.txt" type "%mypath%\net.txt" | findstr /I "ethernet 802.3" | findstr /v /I wireless >"%mypath%\net2.txt" 2>&1 For /f "tokens=3" %%F in (%mypath%\net2.txt) Do echo 000%%F>"%mypath%\id.txt" 2>&1 rem *1 For /f "tokens=*" %%G in (%mypath%\id.txt) Do set networkid=%%G REG ADD "HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "*DeviceSleepOnDisconnect" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "*WakeOnMagicPacket" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "*WakeOnPattern" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "WakeFromS5" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "WakeOnLink" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "*DeviceSleepOnDisconnect" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "*WakeOnMagicPacket" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "*WakeOnPattern" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "WakeFromS5" /t REG_SZ /d 1 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\%networkid%" /v "WakeOnLink" /t REG_SZ /d 1 /f >nul 2>&1 ) echo. echo Folder Permissions md c:\logs >nul 2>&1 cacls c:\logs /E /C /G users:F >nul 2>&1 cacls c:\tools /E /C /G users:F >nul 2>&1 rem Check Version of MySoftware reg query HKLM\Software\MySoftware /v Type >"%mypath%\ver.txt" 2>&1 findstr /I "full" "%mypath%\ver.txt" >nul if %errorlevel% EQU 0 ( echo Full Version just installed ) reg query HKLM\Software\MySoftware /v Version >"%mypath%\ver.txt" 2>&1 if %errorlevel% EQU 1 ( goto okvers ) findstr /I "version" "%mypath%\ver.txt" >nul 2>&1 For /f "tokens=3" %%G in (%mypath%\ver.txt) Do (set version=%%G) if %version% GEQ 2.2 ( color 04 echo Version %versione% - Upgrade not needed goto end ) :okvers REG ADD "HKLM\SYSTEM\ControlSet001\Control\Lsa" /v forceguest /t REG_DWORD /d 00000000 /f >nul 2>&1 REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Lsa" /v forceguest /t REG_DWORD /d 00000000 /f >nul 2>&1 if /I %username%==trasp ( echo User %username% ok ) ELSE ( echo User Wrong echo Creating User net user trasp mypassword /ADD /comment:"User for Login" /expires:never /fullname:"trasp" /passwordchg:no >nul 2>&1 net localgroup Administrators trasp /ADD >nul 2>&1 goto erroruser ) .... :restart color 04 echo. echo UAC Disabled echo press a key to restart echo after restart launch c:\tools\install.bat pause shutdown /r /t 10 /c "restarting..." /f :end
at this point the variable %networkid% is not set.
to resolve this i use this script:
this work and set correctly the variable but next when i try to take a echo (for example i need to do a net localgroup administrators >c:\tools\admin.txt)Code:setlocal enabledelayedexpansion For /f "tokens=*" %%G in (%mypath%\id.txt) Do set networkid=%%G REG ADD "HKLM\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\!networkid!" /v "*DeviceSleepOnDisconnect" /t REG_SZ /d 1 /f >nul 2>&1 endlocal
the echo that i obtain to my txt file is:
"0007
Operation completed"
where 0007 is the output of the variable %networkid%
I don't know what is the problem but this work in windows xp but not in windows 7 64 bit (i don't test it in 32bit).
Thanks for your answer