powershell-后台启动任务

发布时间 2023-10-29 22:25:13作者: 小AT

win11中vbs的文件关联被去掉了,vbs文件不能双击执行,开机启动一个不显示窗口的任务无法完成;

解决办法:控制页面-》系统和安全-》计划任务--》执行命令

比如我们需要开机自启动wsl中的某个服务:

Set ws = WScript.CreateObject("WScript.Shell")        
ws.run "wsl -u root /etc/init.wsl"

替换到powershell中的效果为:


 # 运行程序:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  
 # 命令参数
-Command {Start-Process -FilePath "C:\Windows\System32\wsl.exe" -ArgumentList "-u root /etc/init.wsl" -WindowStyle Hidden}
附录

如何查看powershell的具体用法?Win+R,cmd,powershell /?

如何查看powershell的具体文件位置?Win+R,cmd,where powershell

参考文档:https://www.cnblogs.com/landhu/p/17045466.html