简体   繁体   中英

Startup script to run in background

I have the following bat file:

@echo off
start /min powershell "& 'C:\Admin\c.ps1'"
exit

I don't want to display the powershell window as this is an administrative script that runs on startup.

I was under the impression that using start /min will solve it, but It's still displaying.

PowrShell has a switch to launch itself hideen. That said, the console may be visible for a short period of time until it disappears. Since this is an administrative script, I would also recommend using the NonInteractive switch to prevent someone from interfering with it

@echo off
powershell -NonInteractive -File C:\Admin\c.ps1 
exit

If you can't afford the console to be visible at all, consider using a vbs file to launch powershell:

Set oShell = CreateObject("WSCript.Shell")
oShell.Run("powershell -NonInteractive -File C:\Admin\c.ps1",0,False)

如果您使用“任务计划程序”,“启动时运行一次”,则可以选择隐藏这样的窗口。

START command has option /b to start an application without creating a new window.

try

start /b powershell "& 'C:\Admin\c.ps1'"

You can use a VBScript to stop the window from appearing at all.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\Admin\c.ps1"), 0, True

Plus you can use this instead of the batch file, so there will be no cmd window either.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM