Problem with echo in batch script

korabio

New member
Local time
5:23 PM
Messages
6
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 Computer

OS
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 Computer

OS
Windows 7 Home Premium 64 Bit
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dwarf Dwf/11/2012 r09/2013
OS
Windows 8.1 Pro RTM x64
CPU
Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.4GHz)
Motherboard
ASRock Z77 Extreme4-M
Memory
4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB)
Graphics Card(s)
MSI GeForce GTX770 Gaming OC 2GB
Sound Card
Realtek High Definition on board solution (ALC 898)
Monitor(s) Displays
ViewSonic VA1912w Widescreen (VGA)
Screen Resolution
1440x900
Hard Drives
OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0
PSU
XFX Pro Series 850W Semi-Modular
Case
Gigabyte IF233
Cooling
1 x 120mm Front Inlet 1 x 120mm Rear Exhaust
Keyboard
Microsoft Comfort Curve Keyboard 3000 (USB)
Mouse
Microsoft Comfort Mouse 3000 for Business (USB)
Internet Speed
NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2)
Antivirus
Avast! 8.0.1497
Browser
IE 11
Other Info
Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
WEI Score: 8.1/8.1/8.5/8.5/8.25
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter)
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 Computer

OS
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 Computer

OS
Windows 7 Home Premium 64 Bit
Back
Top