问题
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
回答1:
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
'*********************************************************************************
回答2:
the easiest way is to use start up folder - %appdata%\Microsoft\Windows\Start Menu\Programs\Startup
.You can choose a method to start your batch in hidden/background mode.Probably best choice is win32process as it offers a lot of options.So just put a script in start up folder a script like:
@call "c:\tools\win32process.bat" "C:\signcatcher\signcatcher\prova.bat" -showWindows 0 -directory "C:\signcatcher\signcatcher"
where you'll have to change the actual path to win32process.bat
来源:https://stackoverflow.com/questions/30671266/how-to-run-a-script-on-startup-in-hidden-mode