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

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

  1. Deb_Rider

    Deb_Rider MDL Senior Member

    Aug 21, 2010
    417
    66
    10
    thanks timesurfer....
    Very interesting and helpfull.....
     
  2. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #82 timesurfer, Nov 17, 2010
    Last edited: Nov 24, 2010
    (OP)
    Anyone if you know a cmd good enough to teach about it or give decent description/examples then post it here and I'll link it to first page as part of the "repo"
     
  3. Cool8818

    Cool8818 MDL Novice

    Jan 18, 2010
    18
    1
    0
    hi guys How can hide Command window when batch file runs

    this is my xp.bat file thank you

    "C:\wxxx\xp.bat"
     
  4. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    You have to launch cmd.exe from an application that sets the SW_HIDE flag.

    For example hstart.

    ;)
     
  5. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    Nice one thank you Calistoga
     
  6. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #86 timesurfer, Dec 21, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Here are cmds to post demonstrations for the batch repo 1st post if anyone's interested

    Creating Menu -- CHOICE, GOTO
    Using arguments -- SHIFT
    Subroutines -- CALL
    Remarks -- REM
    Hide Stuff -- NUL
    Find String -- FINDSTR

    Here is simple cmd nul that hides cmds as they are run in cmd prompt

    Code:
    @echo off
    echo.Please wait while status is being done
    >nul slmgr /dlv
    pause
    This way you can make your batch so it doesn't show cmds just what you want it to say. The NUL cmd should have it's own complete post as to it's total usage so any one interested who knows that cmd do it
     
  7. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    #87 Calistoga, Dec 28, 2010
    Last edited by a moderator: Apr 20, 2017
    NUL is the name of a special "file" that discards all information that is attempted written to it, while reporting "write succeeded" to the caller. It's often referred to as a "Black Hole". Look at it as a bottomless trash can.

    In other words, it behaves the same way as a normal file on your hard drive and is often used for disposing of an unwanted data Stream.

    The equivalent in Linux operating systems is the /dev/null file.

    Consider the following example:
    Code:
    echo "Good bye cruel world" >> NUL
    The text "Good bye cruel world" will be echo'ed into the NUL file and will effectively be gone forever. That could make a nice comic lol, "You want me to write this data? You do? All right, watch me write your data with this LIGHTER"

    In this following example, NUL has been substituted with example.txt
    Code:
    echo "What a wonderful world" >> example.txt
    In this scenario, the text will be written to the example.txt file and will be available for reading by other applications later.
     
  8. Guegs

    Guegs MDL Novice

    Dec 27, 2010
    3
    0
    0
    I am using the Windows Scheduler to run a batch file at a specific time. When it is running, the command prompt will prompt out for about a quarter of a second to show it is running. I want to hide the command prompt window so that it runs without me even knowing it.

    I have tried putting @ECHO OFF as the first line in the batch file, but this still opened the command prompt window executing the command.

    Is this even possible?
     
  9. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #89 timesurfer, Dec 31, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    This task should run silent

    Code:
    schtasks /create /tn "YourTaskName" /tr "%SystemDrive%\Wherever\Your.bat" /sc daily /mo 1 /ru ""
    Just change the number 1 to whatever days you need task to run

    If you need hours or minutes look in links in first post to find how to put those things at end of the batch
     
  10. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #90 timesurfer, Dec 31, 2010
    Last edited by a moderator: Apr 20, 2017
    (OP)
    You should be able to use this

    Code:
    /st 04:20:00 /ru
     
  11. anemeros

    anemeros MDL Developer

    Aug 12, 2009
    81
    280
    0
    Yes, it's possible to hide the command prompt window in a scheduled task. All you need to do is have it run under a different account than you are logged in as — such as the Local System (S-1-5-18), using /RU SYSTEM.
     
  12. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #92 timesurfer, Jan 5, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Here are both IR4 and IORRT tasks that both run hidden/silent :eek:

    Code:
    schtasks /create /tn "Rearm" /tr "'C:\Windows\system32\cmd.exe' /c cscript.exe /b C:\Windows\System32\slmgr.vbs /rearm && net stop sppsvc && net start sppsvc" /sc daily /mo 30 /ru "" /f
    Code:
    schtasks /create /tn "IORRT" /tr "%SystemDrive%\IORRT\IORRT.bat" /sc daily /mo 1 /ru ""
     
  13. sulasno

    sulasno MDL Novice

    Jan 8, 2011
    7
    0
    0
    How do I create a batch file to delete all *.exe except for 1 exe file ?

    presently I am renaming the exe file to something else before deleting the exe files;

    eg
    ren c:\example\donotdelete.exe donotdelete.zip
    del /q c:\example\*.exe
    ren c:\example\donotdelete.zip donotdelete.exe
     
  14. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    #94 Calistoga, Jan 8, 2011
    Last edited by a moderator: Apr 20, 2017
    @sulasno

    This for-loop should do the job :)
    Code:
    @echo off
    
    for %%i in (C:\Example\*.exe) do if not "%%i"=="donotdelete.exe" del /q "%%i"
    
    pause

    Edit: This example is wrong, check this post (#96 in this thread) for the solution.
     
  15. sulasno

    sulasno MDL Novice

    Jan 8, 2011
    7
    0
    0
    #95 sulasno, Jan 8, 2011
    Last edited by a moderator: Apr 20, 2017
    @Calistoga

    this is the actual batch

    Code:
    @echo off
    
    for %%i in "C:\Documents and Settings\username\APLN\iopus\*.exe" do if not "%%i"=="Downloader.exe" del /q "%%i"
    
    pause
    no files are being deleted;

    I tried changing %%i to %%x but still no exe files are being deleted
     
  16. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    421
    199
    10
    #96 Calistoga, Jan 8, 2011
    Last edited by a moderator: Apr 20, 2017
    Oops sorry there bud, I did a mistake in the code.

    Does this work properly?
    Code:
    @echo off
    
    cd  /d "C:\Documents and Settings\username\APLN\iopus\"
    
    for %%i in (*.exe) do if not "%%i"=="Downloader.exe" del /q "%%i"
    
    pause
     
  17. sulasno

    sulasno MDL Novice

    Jan 8, 2011
    7
    0
    0
    Thank you very much
     
  18. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    #98 rEApEAt, Jan 10, 2011
    Last edited by a moderator: Apr 20, 2017
    No solution yet? :) Here is diamond.bat:

    Code:
    @echo off
    if not "%1"=="5" goto nojoy
    if "%1"=="5" goto diamond
    
    :nojoy
    echo.
    echo No diamond found! Try again...
    goto end
    
    :diamond
    echo.
    echo       0 
    echo      0 1 
    echo     0 1 2 
    echo    0 1 2 3 
    echo   0 1 2 3 4 
    echo  0 1 2 3 4 5 
    echo  0 1 2 3 4 5 
    echo   0 1 2 3 4 
    echo    0 1 2 3 
    echo     0 1 2 
    echo      0 1 
    echo       0
    goto end
    
    :end
    Cheers :)
     
  19. rEApEAt

    rEApEAt MDL Senior Member

    Jan 5, 2011
    355
    170
    10
    #99 rEApEAt, Jan 11, 2011
    Last edited by a moderator: Apr 20, 2017
    Well, well... The code above is extremely easy and scarcely needs an explanation. "%1" corresponds to the first argument; "%2" would correspond to the second argument and so on. You can use anything as an argument, including "professional-alike" arguments like "/A", "-R" and so on.

    Note that using letters instead of numbers will force you to take account of uppercase and lowercase letters. If you don't want the user to be bothered with uppercase/lowercase alternatives, or with minor questions like using "/" or "-" in an argument, you may turn things easier to him this way:

    Code:
    if "%1"=="/R" goto diamond
    if "%1"=="/r" goto diamond
    if "%1"=="-R" goto diamond
    if "%1"=="-r" goto diamond
    Now let's propose a small variation of the challenge above. Rewrote the code of "diamond.bat" in order to obtain this output:

    Code:
    Here is your diamond:
    
           0 
          0 1 
         0 1 2 
        0 1 2 3 
       0 1 2 3 4 
      0 1 2 3 4 5 
      0 1 2 3 4 5 
       0 1 2 3 4 
        0 1 2 3 
         0 1 2 
          0 1 
           0
    But in such way that it will replace the word "diamond" with any name you may choose to rename the batch file itself.
     
  20. DARKOR04

    DARKOR04 MDL Tester/Developer

    Jul 5, 2010
    497
    909
    10
    #100 DARKOR04, Jan 30, 2011
    Last edited by a moderator: Apr 20, 2017
    you missed the 'pause' to make a stop and display, and yet it did not work that way....