0

I followed a guide to create a batch file so I can delay a program from starting up for a few seconds. (I didn't want to use a 3rd party tool)

The thing is I don't want to see that cmd window for X seconds until it launches that program. Any ideas?

Here is the code I am using within the .bat file:

@ECHO OFF
TIMEOUT /t 3 > nul
START "" "C:\program.exe"
3
  • Why not launch the batch file or the program itself using Task Scheduler. You have an option to hide the console there
    – Ganesh R.
    May 24, 2015 at 15:49
  • I know "hide" is an option within TaskScheduler however .bat's still show the CMD window whether it's selected or not.
    – user431052
    May 24, 2015 at 15:59
  • It's not clear what you mean by not see the command window until the program launches. So you want the program to launch with the command window hidden, and then you want the command window to appear? showing what? C:\> ? And out of interest, Why?
    – barlop
    May 24, 2015 at 18:15

1 Answer 1

0

This visual basic script does 3 things.

~ Grabs the current directory of where .VBS is stored and takes a file name.
~ Runs the given file w/ Admin privileges. (doesn't prompt for UAC)
~ Runs the file silently, without the CMD you mention.

bElevate = False
if WScript.Arguments.Count > 0 Then If WScript.Arguments(WScript.Arguments.Count-1) <> "|" then bElevate = True
if bElevate Or WScript.Arguments.Count = 0 Then ElevateUAC
REM run the following script with admin privilages. start point.

Set fso = CreateObject("Scripting.FileSystemObject")
GetTheParent = fso.GetParentFolderName(Wscript.ScriptFullName)

Set WshShell = WScript.CreateObject ("WScript.Shell")
WshShell.Run GetTheParent & ("\CUSTOMNAMEOFBAT.bat") 
WScript.Sleep 500

REM the above script will be run with admin privilages. end point.
Sub ElevateUAC
    sParms = " |"
    If WScript.Arguments.Count > 0 Then
            For i = WScript.Arguments.Count-1 To 0 Step -1
            sParms = " " & WScript.Arguments(i) & sParms
        Next
    End If
    Set oShell = CreateObject("Shell.Application")
    oShell.ShellExecute "wscript.exe", WScript.ScriptFullName & sParms, , "runas", 1
    WScript.Quit
End Sub

Copy/Paste the following code and save as .VBS. Put the .vbs script in the same directory as your .bat and change "CUSTOMNAMEOFBAT" (on end of line 11) to the name of your .bat.

Not the answer you're looking for? Browse other questions tagged .