Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Problem with echo in batch script


23 Jul 2010   #1

Windows 7 Home Premium 64 Bit
 
 
Problem with echo in batch script

Morning i have a problem with batch script in Windows 7.
this is my code:
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
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.
at this point the variable %networkid% is not set.
to resolve this i use this script:
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
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)
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

My System SpecsSystem Spec
.

23 Jul 2010   #2

Windows 7 Home Premium 64 Bit
 
 

this appen only in the batch.. if i cut the part and insert into another batch this work
My System SpecsSystem Spec
23 Jul 2010   #3

Windows 8.1 Pro RTM x64
 
 

Quote   Quote: Originally Posted by korabio View Post
this appen only in the batch.. if i cut the part and insert into another batch this work
Hi Korabio,

I've had a quick look at this, and I'm slightly confused as to what you mean here. Which part do you cut?
My System SpecsSystem Spec
.


23 Jul 2010   #4

Windows 7 Home Premium 64 Bit
 
 

i cut the part that i need:
Code:
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
put in another batch file and do a call namefile.bat

now it work.. but i don't know why if is all in a batch file the echo result broken...

put in another
My System SpecsSystem Spec
23 Jul 2010   #5

Windows 7 Home Premium 64 Bit
 
 

the part is this:
Code:
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
now i cut this part, put in another file.bat and do a call file.bat and work... but i don't know why in the full script the echo is wrong...
My System SpecsSystem Spec
Reply

 Problem with echo in batch script




Thread Tools



Similar help and support threads for2: Problem with echo in batch script
Thread Forum
How to create batch script to lock workstation then log off. General Discussion
PDF file association REG or Batch Script Software
Admin privileges in batch script Software
Standard Windows batch script not working General Discussion
Remotely trigger batch script? By email? Network & Sharing
Help me with Batch script! Software

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:06 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33