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
korabio

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
korabio

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
Dwarf

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
korabio

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
korabio

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
Thread Forum
W10 TP : Old Windows Update Batch/Script
Hi, I need you for obtain a batch for apply this custom : Retrouvez votre bon vieux Windows Update sous Windows 10 - Le comptoir du hardware Can you help me ? Thanks Have a good day !
Windows Updates & Activation
How to run cmd.exe elevated in batch script
Hi All, I am writing a dos batch file for windows7 and it has many commands which need elevated access to run. For elevation I am using elevate.exe. I am doing like below - set Elevation=elevate -wait cmd.exe /c %Elevation% "cd /d %CD% && xcopy /E /Y ...." %Elevation% "cd /d %CD% &&...
General Discussion
batch script help
dear all any help to make batch script this the reason i want to make a batch file is to help me update the online games in 60 computers by overwriting or copying big files in one click from 1 source computer... instead of turning on all 60 computers and updating all online games, he'll just...
General Discussion
Admin privileges in batch script
Hallo, I wrote a Script that uninstalls an application, move some files and install an Application. The Script is working if I start it as Admin (right click - run as Admin ...). Everything works fine. But I want to have it working without the "run as". The script is only used in a...
Software
Help me with Batch script!
Hi, Can somebody assist me with a .bat file I am trying to create? This is what I have now: start /d "C:\Users\Me\Desktop\ghost" ghost.exe start /d "C:\Users\Me\Desktop" Poweroff.exe C:\Windows\System32\powercfg.exe /setactive e428f8a5-615e-488f-b7f7-1ed39450e522The first 2 lines start...
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 23:01.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App