Problem with echo in batch script


  1. Posts : 6
    Windows 7 Home Premium 64 Bit
       #1

    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 Computer


  2. Posts : 6
    Windows 7 Home Premium 64 Bit
    Thread Starter
       #2

    this appen only in the batch.. if i cut the part and insert into another batch this work
      My Computer


  3. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #3

    korabio said:
    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


  4. Posts : 6
    Windows 7 Home Premium 64 Bit
    Thread Starter
       #4

    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


  5. Posts : 6
    Windows 7 Home Premium 64 Bit
    Thread Starter
       #5

    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


 

  Related Discussions
Our Sites
Site Links
About 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 07:45.
Find Us