簡體   English   中英

Windows 任務計划程序未從 Powershell 腳本啟動程序

[英]Windows Task Scheduler not starting program from Powershell script

我對 powershell 和服務器管理非常陌生。 我創建了一個簡單的 powershell 腳本來停止和啟動一個程序。 該腳本在我手動運行時可以正常工作,但是當 Windows 任務計划程序運行它時,如果程序正在運行,它將停止程序,但不會啟動它。

Windows 任務計划程序報告“此操作已成功完成。(0x0)”

我在腳本上設置了成績單,它也沒有報告任何錯誤。

我的任務設置如下;

User; Administrator
Run whether user is logged on or not
Run with highest privledges is checked
Configure for: Windows 7, Windows Server 2008 R2

扳機:

Start one time
Repeat every 5 minutes indefinitely

行動:

Program/script:
powershell.exe

Add arguments: -Executionpolicy Bypass -file "C:\DiscordIntegratorBot\restart.ps1"

restart.ps1 內容:

start-transcript "c:\temp\script.log"

$processname = Get-Process -Name "DiscordIntegratorBot"

if ($processname) {
  Stop-Process -Name $processname.Name -Force
}

Start-Process -FilePath "C:\DiscordIntegratorBot\DiscordIntegratorBot.exe"

stop-transcript

script.log 內容:

**********************
Windows PowerShell transcript start
Start time: 20200804113001
Username: NS1001457\Administrator
RunAs User: NS1001457\Administrator
Configuration Name: 
Machine: NS1001457 (Microsoft Windows NT 10.0.17763.0)
Host Application: powershell.exe -Executionpolicy Bypass -file C:\DiscordIntegratorBot\restart.ps1
Process ID: 6312
PSVersion: 5.1.17763.1007
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.1007
BuildVersion: 10.0.17763.1007
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is c:\temp\script.log
**********************
Windows PowerShell transcript end
End time: 20200804113001
**********************

我不知道現在可能是什么問題,並感謝任何幫助。

經過更多的谷歌搜索后,我能夠解決自己的問題..

將任務設置為“無論用戶是否登錄都運行”意味着應用程序在后台運行。 我正在檢查程序 GUI 是否彈出,而不是進程 window。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM