如何在远程计算机上打开exe

问题描述 投票:1回答:1

我需要一个powershell脚本,我可以从主机运行,它将重新启动远程计算机上的exe(如excel或其他东西)。

我尝试过使用拥有,调用命令和psexec,但无济于事。我甚至想到了一种在主机上的方法,并尝试执行远程服务器上的脚本。我没有得到任何错误,这使得很难知道发生了什么/如果它发生了。

我在我的脚本中试过这个:&EXCEL.exe

我希望应用程序在远程计算机上打开。

powershell-v3.0 powershell-remoting
1个回答
0
投票

这解决了我的问题。我做了一个我最终做的通用版本:

$remoteComputer = "ComputerName"

$appLocation = "C:\Windows\notepad"

$taskName = "openNotepad"

$delay = (get-date).AddMinutes(1) #adds 1 minute to the current time

$newTime = get-date $delay -format HH:mm:ss #24 HR format

echo (get-date -Uformat %T)

echo $newTime #compare the time difference

$null = schtasks /create /s $remoteComputer /TN $taskName /TR $appLocation /SC ONCE /ST $newTime

start-sleep -s 65 #schtasks can't perform on the same minute, and needs a wait time before it will delete the task

$null = schtasks /delete /s $remoteComputer /TN $taskName /f
© www.soinside.com 2019 - 2024. All rights reserved.