Search code examples
batch-filevbscriptwindows-8.1startup

How to run a script on startup in hidden mode


I have a batch file, named prova.bat, and I need to launch it at the startup of the computer, and I need to launch it in hidden mode (with no visible prompt).

I have found on the net solutions to launch the batch at the startup OR solutions to launch the batch in hidden mode, but not solutions to fix both my problems. I have tried with a VBScript and set the script to run at the startup (in the SystemConfiguration).

The OS where the batch have to run is Windows 8.1.

Here's the content of the VBScript (maybe it's something wrong in it):

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\app\app\prova.bat" & Chr(34), 0
Set WshShell = Nothing

Solution

  • This Vbscript can did the trick (Tested on Windows 7 32 bits)

    Hope will work on your Windows 8 ;)

    So the code is very easy to use : You just change two things on it :

    • PathApplication

    • ShortcutName


    Option Explicit
    Dim PathApplication,ShortcutName,VbsPath
    VbsPath = Wscript.ScriptFullName
    PathApplication = "C:\signcatcher\signcatcher\prova.bat"
    ShortcutName = "Hackoo"
    Call Shortcut(VbsPath,ShortcutName)
    Call Hidden_Run(Dblquote(PathApplication))
    '*********************************************************************************
    Sub Shortcut(PathApplication,ShortcutName)
        Dim objShell,StartFolder,objShortCut,MyTab
        Set objShell = CreateObject("WScript.Shell")
        MyTab = Split(PathApplication,"\")
        If ShortcutName = "" Then
            ShortcutName = MyTab(UBound(MyTab))
        End if
        StartFolder = objShell.SpecialFolders("Startup")
        Set objShortCut = objShell.CreateShortcut(StartFolder & "\" & ShortcutName & ".lnk")
        objShortCut.TargetPath = Dblquote(PathApplication)
        ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,-25"
        objShortCut.Save
    End Sub
    '*********************************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '*********************************************************************************
    Function Hidden_Run(MyProgram)
        Dim ws,Result
        Set ws = CreateObject("wscript.Shell")
        Result = ws.run(MyProgram,0,True) '0 to hide the program
        Hidden_Run = Result
    End Function
    '*********************************************************************************