我想阻止用户使用 PowerShell 在 Windows 中运行
已在运行的程序/服务的另一个实例。
例如:我打开了记事本,然后在几分钟内我想禁用打开记事本的选项,因为它已经在运行。
到目前为止,我可以检测程序是否打开,如果没有,我可能会为用户打开它(附加代码)。
$processName = Get-Process notepad -ErrorAction SilentlyContinue
if ( $processName ) {
Write-Host 'Process is already running!'
#stop another instance of notepad to be opened, since it is already running
}
else {
$userChoice = Read-Host 'Process is not running, should I start it? (Y/N) '
if ($userChoice -eq 'Y') {
Start-Process notepad
}
else {
Write-Host 'No Problem!'
}
}
但是,如何禁用用户打开另一个相同实例的选项?
任何相同的线索都会有所帮助。