更新:我的问题的上下文:我是一小群飞行模拟器迷的成员。为了一起训练,我们运行了一个P3D多人服务器。自从我们在白天和晚上进行训练以来,我创建了一个powershell脚本,它在白天和晚上之间每天都在变化。手动这样做是不可能的,因为这意味着每天重新启动P3D两次!P3D进程允许在具有给定飞行文件的多人模式下自动启动。唯一的问题是P3D在启动后仍然停止;要取消它,必须在键盘上输入字符'p‘。多人服务器是在一种服务器机房环境中无人值守的Windows 10 PC机。在多人服务器的运行中,安全性没有问题。
如果手动启动,PowerShell脚本可以正常工作。由于PS脚本需要管理权限,所以我通过cmd脚本启动它,其内容如下:
SET ScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ScriptsDirectory%StartP3DProcess.ps1
PowerShell -WindowStyle Hidden -NoProfile -ExecutionPolicy Unrestricted -Command "& {Start-Process PowerShell -ArgumentList '-WindowStyle Hidden -NoProfile -ExecutionPolicy Unrestricted -File ""%PowerShellScriptPath%""' -Verb RunAs}";PowerShell脚本编辑3个文件(2xxml,1x平面),然后启动一个进程,并在延迟之后将字符'p‘发送到进程。
# Setup date and time in flight file
$result = SetDateTimeInFlightFile -eveningOffsetHour $eveningOffsetHour -flightFileSpec $flightFileSpec
# Setup required TacPack state
$result = SetTacPackState -tacPackState $controlData[$controlTacPackState] -tacPackFileSpec $tacPackFileSpec
# Update session state description in multiplayer configuration file
$result = SetSessionStatus -mpCfgFileSpec $startCfgSpec
# Start P3D Server
Start-Process -FilePath $P3DFileSpec -ArgumentList $P3DArgs
# Set the started P3D process operational
Start-Sleep -s 60 # wait until process is started up
# Send 'p' to P3D server
$result = SendCommandToProcess -processName $P3DFileExe -command 'p'由于PS脚本应该每天运行两次( 7h00和19h00),所以我设置了一个调度器任务来运行cmd脚本。通过sheduler启动的PS脚本运行良好,只需一次请求:发送字符'p‘不起作用。将字符发送到指定进程的函数如下($processId包含正确的进程id,$command 'p'):
[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
[Microsoft.VisualBasic.Interaction]::AppActivate($processId)
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait($command)工作环境是一个运行Windows 10 Pro的“服务器”,系统上没有任何普通用户(出于管理目的,只有一个用户帐户“admin”)。使用集成日志文件写入,我验证了在这两种情况下(调度程序和手动运行):
什么在愚弄我?谢谢你的暗示和帮助汉尼斯
发布于 2020-11-02 10:10:08
如果这样做的目的仅仅是恢复挂起的进程,则可以使用PsSuspend或PoshInternals模块,后者提供了挂起/恢复进程功能。
https://stackoverflow.com/questions/64623824
复制相似问题