[Batch] The Official Batch File Repository - Learn & ask questions about batch files

Discussion in 'Scripting' started by timesurfer, Oct 11, 2010.

  1. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,455
    989
    60
    #261 Humphrey, Apr 10, 2013
    Last edited by a moderator: Apr 20, 2017
    Hello,

    I am using a new (to me) method to create AIO disc for my Windows 7 ISOs.
    http://it.megocollector.com/?p=1510


    My problem is that I need to put in a batch file that checks the architecture of the computer and then installs software for said architecture.

    I am using oem_AIO_Win7_Vista_DVD2.1_2.0_Final2013 + InstallTips to do this.

    I placed in the oobe.cmd the following:
    Code:
    setlocal ENABLEEXTENSIONS
    set KEY=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    set VALUE=PROCESSOR_ARCHITECTURE
    
    FOR /F "tokens=2*" %%A IN ('REG.exe query "%KEY%" /v "%VALUE%"') DO (set pspy=%%B)
    If /I %pspy%==AMD64 (Start .\64\installtips.exe) else (Start .\32\installtips.exe)
    
    When it runs locally it says start was unexpected at this time.
    When I replace start with echo <text here> it will echo correctly.

    Help someone please.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,455
    989
    60
    #262 Humphrey, Apr 10, 2013
    Last edited by a moderator: Apr 20, 2017
    And this is no longer fully funtional and was written on Windows XP but I enjoyed it while I used it.

    Its a chat script in batch for use at work. We had external drives everyone had access to so i wrote this with the help of some people.

    Its got a Windows XP CMD like trick menu which I at the time was trying to get it to function as a legit command prompt to no avail.

    Code:
    :: Version 2.8
    @echo off
    SetLocal EnableDelayedExpansion
    title C:\WINDOWS\system32\cmd.exe
    :OMG
    cls
    set RLESE=password
    mode con cols=80 lines=25
    CLS
    :: Decoy screen
    ECHO Microsoft Windows XP [Version 5.1.2600]
    ECHO (C) Copyright 1985-2001 Microsoft Corp.
    echo.
    SET /P RLESE=C:\Documents and Settings\!USERNAME!^>
    IF /i "!RLESE!"=="letmein" GOTO handle
    ) ELSE (
    Call :NewLabel
    )
    IF /i "!RLESE!"=="-" goto saftey
    IF /i NOT RLESE==letmein exit
    goto OMG
    :NewLabel
    cd /D %HOMEDRIVE%%HOMEPATH%
    IF NOT "!RLESE!"=="-" CLS & CALL CMD.exe
    ) ELSE (
    GOTO saftey
    )
    exit
    :handle
    cls
    mode con cols=80 lines=40
    if not exist filename.txt echo >>filename.txt
    if not exist priv mkdir priv
    If not exist BIN mkdir BIN
    if exist BIN attrib +H BIN >nul
    if exist PRIV attrib +H PRIV >nul
    echo.
    echo ==============
    echo System Message - You are currently using the name: !handle!
    echo ==============
    echo.
    set /p handle= What is your name?:
    if not defined handle goto handle
    :mainmenu
    cls
    echo.
    echo ==============
    echo Options
    echo ==============
    echo.
    echo Here is what you can do.
    echo.
    echo - Type in (L)ounge to goto the main chat lobby.
    echo.
    echo - Type in (P)rivate to start your own (or join a) private chat.
    echo.
    echo - Type in "FEDEX" or "MLB" or "XBOX" to join these PUBLIC lobbies.
    ECHO.
    echo __________________________
    set /p choice2= What to do? (L or P):
    IF /I "!choice2!"=="fedex" set priv8=fedex & goto PROVIDEDROOM
    IF /I "!choice2!"=="mlB" set priv8=mlb & goto PROVIDEDROOM
    IF /I "!choice2!"=="xbox" set priv8=xbox & goto PROVIDEDROOM
    IF /I "!choice2!"=="L" goto startmsg
    IF /I "!choice2!"=="P" goto cr8priv
    if not defined choice2 goto startmsg
    :cr8priv
    SET priv8=
    cls
    echo.
    echo ===============
    echo Information
    echo ===============
    ECHO.
    echo Whether your creating a new private lobby or joining a private one,
    echo just type the name of that lobby (and password if need) to access it.
    echo.
    echo Reminder: If your creating a private room, make sure that you use
    echo numbers and letters (NO SYMBOLS!) so that guessing the room name is
    echo harder for someone to just guess it.
    ECHO.
    set /p priv8= Lobby name?:
    FOR /f "tokens=*" %%a IN ('FINDSTR "!priv8!" "FileName.txt"') DO (
    IF "!ErrorLevel!"=="1" GOTO PROVIDEDROOM
    SET Variable=%%a
    )
    
    FOR /f "tokens=2 delims==" %%a IN ('ECHO !Variable!') DO (
    SET Pass=%%a
    )
    
    SET /p Passw=Enter the password:
    IF "%Passw%"=="%Pass%" (
    GOTO PROVIDEDROOM
    ) ELSE (
    GOTO Incorrect
    )
    :Incorrect
    CLS
    ECHO Incorrect Password . . .
    ECHO.
    cls
    echo Room/Password combination not found,
    echo Created: Room "!priv8!" with password "!Passw!"
    echo !priv8!=!Passw!>> FileName.txt
    echo.
    ping localhost -n 2 >nul
    goto priv8
    
    
    :PROVIDEDROOM
    CLS
    for /f "delims=" %%a in ('time /t') do (
    >> priv\!priv8!.dll echo %%a [SYSTEM]: User, !HANDLE!, joined the chat!
    )
    echo. >> priv\!priv8!.dll
    :priv8
    If not exist priv\!priv8!.dll echo Created on !date!! >> priv\!priv8!.dll
    echo. >> priv\!priv8!.dll
    if exist priv\!priv8!.dll attrib +H priv\!priv8!.dll >nul
    cls
    echo.
    type priv\!priv8!.dll
    echo _____________________________________________________
    echo Type in the letter H, then press enter for help.
    echo.
    set /p writepriv= Your message?:
    IF /I "!writepriv!"=="h" goto helpPRIV
    IF /I "!writepriv!"=="lobby" goto message
    IF /I "!writepriv!"=="1" goto OMG
    IF /I "!writepriv!"=="-" goto saftey
    IF /I "!writepriv!"=="x" goto quitPRIV
    IF /I "!writepriv!"=="d" goto deletePRIV
    IF /i "!writepriv!"=="n" goto handlePRIV
    if not defined writepriv goto priv8
    for /f "delims=" %%a in ('time /t') do (
    >> priv\!priv8!.dll echo %%a [!handle!]: !writepriv!
    )
    echo. >> priv\!priv8!.dll
    goto priv8
    :helpPRIV
    cls
    echo.
    echo ======================================
    echo Here are a few things that you can do.
    echo ======================================
    echo.
    echo - Type N to change your name in the chat.
    echo.
    echo - Type X to leave the chat.
    echo.
    echo - Type D to delete the chat messages.
    echo.
    echo - Type lobby to goto the main chat room.
    ECHO.
    echo - Type the # 1 to goto the fake CMD screen.
    echo.
    echo - Type - to whipe all files related to this chat script.
    ECHO (WARNING: IF YOU PRESS '-' YOU WILL DELETE EVERYTHING THAT MAKES THIS WORK!)
    echo.
    pause
    goto priv8
    :quitPRIV
    for /f "delims=" %%a in ('time /t') do (
    >> priv\!priv8!.dll echo %%a [SYSTEM]: User, !HANDLE!, quit the chat.
    )
    echo. >> priv\!priv8!.dll
    exit
    :deletePRIV
    attrib -h priv\!priv8!.dll
    del /F /Q "priv\!priv8!.dll"
    echo.
    IF NOT EXIST "priv\!priv8!.dll" (Echo LOG's Deleted!) ELSE (ECHO Its not deleted.)
    ping localhost -n 2 >nul
    goto priv8
    :namePRIV
    set oldhandle=!handle!
    cls
    echo.
    echo ==============
    echo System Message - You are currently using the name: !handle!
    echo ==============
    echo.
    Set /p handle= Your new name?:
    if not defined handle goto priv8
    IF /i "!usr!"=="d" goto deletePRIV
    IF /i "!usr!"=="1" goto OMG
    IF /i "!usr!"=="-" goto saftey
    for /f "delims=" %%a in ('time /t') do (
    >> BIN\HAL.DLL echo %%a [SYSTEM]: The user "!oldhandle!" changed their name to "!handle!"
    )
    goto message
    :startmsg
    for /f "delims=" %%a in ('time /t') do (
    >> BIN\HAL.DLL echo %%a [SYSTEM]: User, !handle!, just joined the chat.
    )
    if exist BIN\HAL.DLL attrib +H BIN\HAL.DLL >nul
    :message
    cls
    If not exist BIN\HAL.DLL echo Created on !date!! >> BIN\HAL.DLL
    echo. >> BIN\HAL.DLL
    if exist BIN\HAL.DLL attrib +H BIN\HAL.DLL >nul
    type BIN\HAL.DLL
    echo.
    set message=
    echo _____________________________________________________
    echo Type in the letter H, then press enter for help.
    echo.
    set /p message= Your message?:
    IF /I "!message!"=="priv8" goto mainmenu
    IF /I "!message!"=="h" goto help
    IF /I "!message!"=="r" start notepad.exe BIN\HAL.DLL
    IF /I "!message!"=="1" goto lock
    IF /I "!message!"=="-" goto saftey
    IF /I "!message!"=="x" goto quit
    IF /I "!message!"=="d" goto delete
    IF /i "!message!"=="n" goto name
    if not defined message goto message
    for /f "delims=" %%a in ('time /t') do (
    >> BIN\HAL.DLL echo %%a [!handle!]: !message!
    )
    goto message
    :lock
    cls
    set RLESE=password
    mode con cols=80 lines=25
    CLS
    :: Decoy #2
    ECHO Microsoft Windows XP [Version 5.1.2600]
    ECHO (C) Copyright 1985-2001 Microsoft Corp.
    echo.
    SET /P RLESE1=C:\Documents and Settings\!USERNAME!^>
    IF /i "!RLESE1!"=="letmein" goto message
    IF /i "!RLESE1!"=="-" goto saftey
    IF /i NOT RLESE1==letmein exit
    if not defined RLESE1 goto LOCK
    goto lock
    :read
    cls
    start notepad.exe BIN\HAL.DLL
    goto message
    :help
    cls
    echo.
    echo ======================================
    echo Here are a few things that you can do.
    echo ======================================
    echo.
    echo - Type N to change your name in the chat.
    echo.
    echo - Type X to leave the chat.
    echo.
    echo - Type D to delete the chat messages.
    echo.
    echo - Type priv8 to goto the private room join/creation screen.
    echo.
    echo - Type the # 1 to goto the fake CMD screen.
    echo.
    echo - Type - to whipe all files related to this chat script.
    ECHO (WARNING: IF YOU PRESS '-' YOU WILL DELETE EVERYTHING THAT MAKES THIS WORK!)
    echo.
    pause
    goto message
    :name
    set oldhandle=!handle!
    cls
    echo.
    echo ==============
    echo System Message - You are currently using the name: !handle!
    echo ==============
    echo.
    Set /p handle= Your new name?:
    if not defined handle goto message
    IF /i "!usr!"=="d" goto delete
    IF /i "!usr!"=="1" goto OMG
    IF /i "!usr!"=="-" goto saftey
    for /f "delims=" %%a in ('time /t') do (
    >> BIN\HAL.DLL echo %%a [SYSTEM]: The user "!oldhandle!" changed their name to "!handle!"
    )
    goto message
    :quit
    for /f "delims=" %%a in ('time /t') do (
    >> BIN\HAL.DLL echo %%a [SYSTEM]: User, !handle!, quit the chat.
    )
    echo. >> BIN\HAL.DLL
    exit
    :delete
    attrib -h BIN\HAL.DLL
    del /F /Q "BIN\HAL.DLL"
    echo.
    IF NOT EXIST "BIN\HAL.DLL" (Echo LOG's Deleted!) ELSE ECHO Its not deleted.
    ping localhost -n 2 >nul
    goto message
    :relocate
    exit
    :saftey
    cls
    rmdir /S /Q "R:\8922" >nul
    exit
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #263 timesurfer, Apr 10, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Batch progress bars

    Was :surfing: and found these two bats for progress bar in title bar and inside console

    Title Progress Bar

    Code:
    @echo off
    
    call :progress 0
    ping -n 5 127.0.0.1 >nul
    call :progress 5
    ping -n 5 127.0.0.1 >nul
    call :progress 10
    ping -n 5 127.0.0.1 >nul
    call :progress 15
    ping -n 5 127.0.0.1 >nul
    call :progress 20
    ping -n 5 127.0.0.1 >nul
    call :progress 25
    ping -n 5 127.0.0.1 >nul
    call :progress 30
    ping -n 5 127.0.0.1 >nul
    call :progress 35
    ping -n 5 127.0.0.1 >nul
    call :progress 40
    ping -n 5 127.0.0.1 >nul
    EXIT
    
    :progress
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET ProgressPercent=%1
    SET /A NumBars=%ProgressPercent%/2
    SET /A NumSpaces=50-%NumBars%
    SET Meter=
    FOR /L %%A IN (%NumBars%,-1,1) DO SET Meter=!Meter!I
    FOR /L %%A IN (%NumSpaces%,-1,1) DO SET Meter=!Meter! 
    TITLE Progress:  [%Meter%]  %ProgressPercent%%%
    ENDLOCAL
    Progress bar inside console

    Code:
    echo off&color e
    setlocal EnableDelayedExpansion
    :: PBar.Updates.cmd
    :: INSTALL
    for /f %%a in ('dir /b %systemdrive%\msu\*.msu') do (
    CLS
    echo Installing %%A
    %windir%\System32\wusa.exe %systemdrive%\msu\%%a /quiet /norestart
    )
    goto :progressbar
    :: EYECANDY
    :progressbar
    set Counter=0
    set Schalter=2
    set Width=0
    :1
    title [ + WINDOWS UPDATES INSTALLER + ]
    set /a Counter=%Counter% + 1
    set /a Display=%Counter% / 2
    FOR /L %%A IN (1,1,%Display%) DO (
       set Display=!Display!²
    )
    cls
    echo            Finalizing Windows Updates...                  %Counter%%%
    echo     ²!Display:~2,47!
    ping localhost -n 1 >nul
    if "%Counter%" == "100" goto :1-End
    goto :1
    :1-End
    echo.
    echo.
    echo.
    echo ALL UPDATES HAVE COMPLETED SUCCESSFULLY..WINDOWS WILL NOW REBOOT.
    :: DELAY
    ping 1.1.1.1 -n 1 -w 5000 >null
    :: REBOOT
    endlocal
    exit
     
  4. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
  5. Dos_Probie

    Dos_Probie MDL Member

    Jul 18, 2012
    249
    86
    10
    #265 Dos_Probie, Apr 14, 2013
    Last edited by a moderator: Apr 20, 2017
    SystemInfo + Hotfixes for Context Menu with print out

    :director: Here is a little batch file that adds to your Desktop context menu and inside any folder of the
    System Information with all Hot Fixes then prints to text file, very useful.. DosProbie ö¿ö

    Code:
    @echo off &&color a&&title [ + SYSTEMINFO + HOTFIXES + ]
    If exist "%Temp%\~import.reg" (
     Attrib -R -S -H "%Temp%\~import.reg"
     del /F /Q "%Temp%\~import.reg"
     If exist "%Temp%\~import.reg" (
      Echo Could not delete file "%Temp%\~import.reg"
      Pause
     )
    )
    > "%Temp%\~import.reg" ECHO Windows Registry Editor Version 5.00
    >> "%Temp%\~import.reg" ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\SysInfo]
    >> "%Temp%\~import.reg" ECHO "MUIVerb"="Systeminfo + Hotfix(s) to file"
    >> "%Temp%\~import.reg" ECHO "icon"="%%systemroot%%\\system32\\msinfo32.exe,0"
    >> "%Temp%\~import.reg" ECHO [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\SysInfo\command]
    >> "%Temp%\~import.reg" ECHO @="cmd /C Systeminfo > Systeminfo+Hotfixes.txt"   
    >> "%Temp%\~import.reg" ECHO "Description"="Prints desktop .txt file of all Hotfixes with System Information-DosProbie 04.12.13"
    START /WAIT REGEDIT /S "%Temp%\~import.reg"
    DEL "%Temp%\~import.reg"
     
  6. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #266 timesurfer, Apr 15, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Batch Wikipedia Searcher

    By jackhole

    Code:
    @echo off
    Color 0a
    Title Wikipedia Searcher
    echo Enter your search topic:
    set /p topic=
    start http://en.wikipedia.org/wiki/%topic%
    Basically it prompts you for a search topic, saves that as a variable topic, then starts a webpage ending in that topic.

    http://www.instructables.com/id/Batch-Wikipedia-Searcher/#step1

    -------------------------------------------------------------------------

    Really wanted to see this code but can't figure out download...lol

    http://www.instructables.com/id/Batch-File-MakerEditor/

    Like this:

    Code:
    SHUTDOWN -S -F -T 900 -C "Insert Message Here."
    
    shutdown is the beginning of the command.
    
    -S means "Shutdown" if you substitute it with an -r then it would "Restart"
    
    -F means "Force Programs to Close"
    
    -T means "Timer" as in, how much time, in seconds, before the computer shuts down.
    
    -C means "Message" which is kinda weird, cause message doesn't start with a c. Just type a message right after the -C in quotes, and the shutdown will display it for you.
    Code:
    SHUTDOWN -S -F -T 30 -C "Your computer will restart in 30 seconds"
     
  7. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
  8. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,455
    989
    60
    #268 Humphrey, May 4, 2013
    Last edited by a moderator: Apr 20, 2017
    Here are batch chat scripts that I made back in the day and updated for Team D420!

    REMEMBER: If you set your name to something you do not want, run this: "REG delete HKCU\Environment /V HANDLE" and restart.

    To use these batch's, you will need to share a dropbox folder with other dropbox users and place th(is)ese file(s) in the dropbox folder. (If to many people start typing then dropbox will create conflict files. To avoid this, do not use on dropbox SORRY )

    Single Windowed Chat (Runs in one windows, press enter to refreash.)
    Code:
    @ECHO OFF
    SetLocal EnableDelayedExpansion
    TITLE DropBox Team D420 Chat Script
    IF NOT EXIST Chat.log ECHO.>>Chat.log
    
    
    
    set KEY_NAME=HKCU\Software\Microsoft\Command Processor
    set VALUE_NAME=DefaultColor
    for /F "usebackq tokens=2 delims=x" %%A IN (`reg query "%KEY_NAME%" /v "%VALUE_NAME%" 2^>nul ^| find "%VALUE_NAME%"`) do (
      IF /I %%A EQU 0x0 (goto color) ELSE (Color %%A)
    )
    
    
    :Start
    if "%handle%"=="" (set /p chatname= What is your name?:) else (GOTO MESSAGE)
    set /p chatname= What is your name?:
    setx handle !chatname!
    if not defined %chatname% goto start
    :MESSAGE
    set message=
    CLS
    ECHO.
    ECHO. Your name is !HANDLE!
    echo.
    TYPE Chat.log
    ECHO.
    set /p message=Your message: 
    if not defined message goto message 
    IF /I "!message!"=="del" del chat.log & ECHO. CHAT WAS ERASED By !Handle!>>Chat.log
    IF /I "!message!"=="del" CLS & GOTO MESSAGE
    >> Chat.log echo [!handle!]: !message!
    )
    goto message
    
    
    
    :Color
    title Color Customization
    set bkg=
    set txtclr=
    
    CLS
    echo.
    echo  Color Customization
    echo.
    ECHO.    0 = Black       8 = Gray
    ECHO.    1 = Blue        9 = Light Blue
    ECHO.    2 = Green       A = Light Green
    ECHO.    3 = Aqua        B = Light Aqua
    ECHO.    4 = Red         C = Light Red
    ECHO.    5 = Purple      D = Light Purple
    ECHO.    6 = Yellow      E = Light Yellow
    ECHO.    7 = White       F = Bright White
    echo.                    G = Chat
    echo.
    set /p txtclr=    ^   Text Color: 
    if /i "%txtclr%"=="G" goto :message
    set /p bkg=    ^   Background Color: 
    if /i "%bkg%"=="G" goto :mainmenu
    set bkg=%bkg:~0,1%
    set txtclr=%txtclr:~0,1%
    set bkg=%bkg%
    set txtclr=%txtclr%
    @COLOR %bkg%%txtclr%
    reg add "HKCU\Software\Microsoft\Command Processor"  /t  REG_DWORD /v DefaultColor /d 0x%bkg%%txtclr% /f >NUL
    IF '%ERRORLEVEL%' EQU '0' ( goto color
    ) ELSE (
    goto message
    )

    Dual Windowed Chat (Updates chat automatically.)
    Code:
    @echo off
    title DropBox Team D420 Chat Script
    if "%~1"=="focus" goto linebox
    SetLocal
    
    :handle
    if "%handle%"=="" (set /p chatname= What is your name?:) else (GOTO linebox0)
    set /p chatname= What is your name?:
    setx handle !chatname!
    if not defined %chatname% goto handle
    
    :linebox0
    > scroll.bat echo @echo off
    >> scroll.bat echo title DropBox Team D420 Chat Script
    >> scroll.bat echo mode con:lines=13
    >> scroll.bat echo :loop
    >> scroll.bat echo cls
    >> scroll.bat echo set LINES=0 ^&^& for /f "delims==" %%%%I in (chat.log) do (set /a LINES=LINES+1)
    >> scroll.bat echo set /a LINES=LINES-10
    >> scroll.bat echo more +%%LINES%% ^< chat.log
    >> scroll.bat echo ^>nul ping 0.0.0.0 -n 2
    >> scroll.bat echo goto loop
    
    start scroll.bat
    start "" "%~f0" focus
    goto :eof
    
    :linebox
    title DropBox Team D420 Chat Script
    SetLocal EnableDelayedExpansion
    for /f "delims=" %%a in ('time /t') do (
        >> chat.log echo %%a [!handle!] joined.
    )
    mode con:cols=65 lines=2
    
    :message
    set message=
    set /p message=message?^>^>
    if not defined message goto message
    if /i "!message!"=="exit_chat" (
        for /f "delims=" %%a in ('time /t') do (
            >> chat.log echo %%a [!handle!] left.
        )  
        taskkill /FI "WINDOWTITLE eq DropBox Team D420 Chat Script" >NUL
    )
    for /f "delims=" %%a in ('time /t') do (
        >> chat.log echo %%a [!handle!]: !message!
    )
    goto message
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #269 timesurfer, May 4, 2013
    Last edited: May 4, 2013
    (OP)
    The Dual Windowed Chat (Updates chat automatically.) is awesome :eek:...lol

    Makes talking and developrment in DB so fantastic

    Your awesome :worthy:

    TS
     
  10. SamyAdel9

    SamyAdel9 MDL Novice

    May 23, 2013
    1
    0
    0
    #270 SamyAdel9, May 24, 2013
    Last edited by a moderator: Apr 20, 2017
    There is a maximum of 29. That's just because that's the highest number a diamond can made out of and still be properly displayed in CMD.

    Also it doesn't really make a diamond in a shell window, it's more like a sideways pyramid. (unless I was supposed to incorporate the spacing in the script, because I didn't :sorry:)

    Code:
    @echo off
    if [%1]==[] goto NoParameter
    if not [%1]==[] goto YesParameter
    :NoParameter
    set /p input=#=
    if %input%==0 echo 0
    if %input%==0 echo 0
    if %input%==0 pause
    if %input%==0 goto end
    if [%input%]==[] echo No number was specified.
    if [%input%]==[] pause
    if [%input%]==[] goto end
    if 29 lss %input% echo The number is too high. CMD can not display this many characters on one line.
    if 29 lss %input% pause
    if 29 lss %input% goto end
    if not [%input%]==[] set var=i
    if -1 lss %input% goto Zpos
    if %input% lss 0 echo The number must be positive.
    if %input% lss 0 pause
    if %input% lss 0 goto end
    if %input%
    goto end
    :YesParameter
    if %1==0 echo 0
    if %1==0 echo 0
    if %1==0 goto end
    set var=1
    if 29 lss %1 echo The number is too high. CMD can not display this many characters on one line.
    if 29 lss %1 pause
    if 29 lss %1 goto end
    if -1 lss %1 goto Zpos
    if %1lss 0 echo The number must be positive.
    if %1 lss 0 pause
    if %1 lss 0 goto end
    goto end
    :Zpos
    set y=0
    set /a l=0
    set /a r=-1
    if %var%==i if not 0==%input% set y=0
    if %var%==1 if not 0==%1 goto skip
    :loop
    set /a r=%r% + 1
    if not %r%==0 set y=%y% %r%
    if not %r%==%l% goto loop
    :skip
    echo %y%
    set /a l=%l%+1
    set /a lcom = %l%-1
    if %var%==i if not %lcom%==%input% goto loop
    if %var%==1 if not %lcom%==%1 goto loop
    echo %y%
    if %var%==i set /a p=%input%
    if %var%==1 set /a p=%1
    :repeat
    set y=%y:~0,-2%
    echo %y%
    set /a p = %p%-1
    if not %p%==0 goto repeat
    if %var%==i pause
    :end
    
     
  11. nephi12

    nephi12 MDL Novice

    Jul 3, 2013
    4
    0
    0
    #271 nephi12, Jul 4, 2013
    Last edited by a moderator: Apr 20, 2017
    here is my solution, tell me if it sucks.
    Code:
    @echo off&setlocal enabledelayedexpansion
    mode con: cols=150 lines=500
    if '%1'=='' (echo missing parameter&pause>nul&exit /b)
    for /l %%i in (%1,-1,0) do for /l %%j in (%%i,1,%1) do set %%i=!%%i! 
    for /l %%i in (0,1,%1) do (for /l %%j in (0,1,%%i) do set nums=!nums! %%j)&echo !%%i!!nums!&set nums=
    for /l %%i in (%1,-1,0) do (for /l %%j in (0,1,%%i) do set nums=!nums! %%j)&echo !%%i!!nums!&set nums=
    
    :)
     
  12. nephi12

    nephi12 MDL Novice

    Jul 3, 2013
    4
    0
    0
    also @Samyadel9, you might want to reinspect your codes output when given a number greater than 11. it gets kind of funky and outputs extra 1's, skips numbers a couple other things. good try though, is impressive.
     
  13. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    #273 calpo, Jul 24, 2013
    Last edited by a moderator: Apr 20, 2017
    Hi All,

    I have a command. Now I want to add more command lines in order that it will notify me running it again every 15 days after the first run. Please help me. thank in advance.

    Code:
    For /F "eol=E tokens=* delims=" %%A in ('REG QUERY HKLM\SOFTWARE\Classes\CLSID /t REG_BINARY /v data /s') Do (
    Set Var=%%A)
    REG DELETE %Var% /f
    exit
     
  14. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,093
    24,397
    340
    #274 s1ave77, Jul 24, 2013
    Last edited by a moderator: Apr 20, 2017
    Are that all commands you need to process each time it runs?

    To run it every 15 days, you can create a task in Scheduler and point to your script.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    @s1ave77

    Can you help me how to create a task in scheduler please thank you ?

     
  16. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,093
    24,397
    340
    #276 s1ave77, Jul 24, 2013
    Last edited by a moderator: Apr 20, 2017
    Two ways possible: manually adding in Task Scheduler (Search via Startscreen/menu), or via admin command prompt:

    example for creating a task that runs every 15 days:

    Code:
    SCHTASKS /Create /TN "Name" /TR "path.to.script" /SC DAILY /MO 15 /RU SYSTEM /RL Highest /F
    
    Red part: give task a name
    Green part: specify path to script to run


    Is the FOR loop only running once, or several times (in case more than one reg key should be deleted)?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    Can anyone help me with command file .cmd which it copies 2 XP back-up Activation files WPA.DBL and WPA.BAK to the path: C:\Windows\System32. I placed WPA.DBL & WPA.BAK in the folder named XP Backup. instead I have to boot Windows from Safe Mode but I want to run .cmd file in the folder named XP Backup.Thanks for your help in advance.
     
  18. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,093
    24,397
    340
    Does it need to take ownership of the original files or is it a simple xcopy job?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. sanjose

    sanjose MDL Member

    Jan 23, 2012
    184
    21
    10
    Yes, It needs to take ownership .... thanks again bro
     
  20. s1ave77

    s1ave77 Has left at his own request

    Aug 15, 2012
    16,093
    24,397
    340
    #280 s1ave77, Aug 2, 2013
    Last edited by a moderator: Apr 20, 2017
    This should do the job.
    Code:
    @echo off
    setlocal ENABLEDELAYEDEXPANSION    
    echo Taking Ownership of original files...
    ::Taking Ownership of the files
    takeown /f %systemroot%\System32\WPA.DBL
    icacls %systemroot%\System32\WPA.DBL /grant administrators:F
    takeown /f %systemroot%\System32\WPA.BAK
    icacls %systemroot%\System32\WPA.BAK /grant administrators:F
    echo Backing up original files ...
    ::Backing up original files
    ren "%windir%\system32\WPA.DBL" "WPA.DBL.BAK1" 
    ren "%windir%\system32\WPA.BAK" "WPA.BAK.BAK1" 
    echo Copying WPA.DBL and WPA.BAK to %windir%\system32\ ...
    ::Copy job
    xcopy "%~dp0WPA.DBL" "%windir%\system32\" /Q /Y 
    xcopy "%~dp0WPA.BAK" "%windir%\system32\" /Q /Y 
    ENDLOCAL
    exit
    
    To add some safety added backup of original files :D.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...