- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设有一个名为 exampleService 的应用程序应在 Server1 上运行。如果该代码正在运行,则它会起作用。然而,当它不运行时,它就会崩溃。
$application = Get-Process -ComputerName Server1 -Name "exampleService"
如果应用程序未运行,我会遇到此崩溃。有没有更优雅的方法来确定它是否没有运行(不会崩溃)
Get-Process : Cannot find a process with the name "exampleService". Verify the process name and call the cmdlet again.
At line:1 char:16
+ $application = Get-Process -ComputerName Server1 -Name "exampleService"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Sampler:String) [Get-Process], ProcessCommandException
+ FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand
如果应用程序未运行,是否可以在服务器上启动该应用程序?
服务器正在运行 Windows Server 2012。PowerShell 命令正在从 Windows 7 64 位 PC 运行。
最佳答案
考虑使用-ErrorAction SilentlyContinue
来防止显示该错误。如果应用程序未运行,您可以在 If 语句中使用它来启动应用程序。
--更新为包括启动远程进程
If (-NOT (Get-Process -Computername Server1 -name "cmd" -ErrorAction SilentlyContinue)) {
Write-Host "Launch application"
$application = "c:\windows\system32\cmd.exe"
$start = ([wmiclass]"\\Server1\Root\CIMV2:win32_process").Create($application)
}
关于powershell - 如何判断特定 ProcessName 是否正在运行而不崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32397743/
我正在使用此代码来监视进程: var startWatch = new ManagementEventWatcher( "SELECT * FROM Win32_ProcessStartTra
假设有一个名为 exampleService 的应用程序应在 Server1 上运行。如果该代码正在运行,则它会起作用。然而,当它不运行时,它就会崩溃。 $application = Get-Proc
如果您使用单声道并使用 Process.ProcessName,您可能会在某些计算机上得到错误的结果。 例如,您可能会得到“kdeinit4”(在 SUSE 上看到)而不是进程名称“kwrite”。
我之前在 C# 中使用过 Process.GetProcessesByName("PROCESSNAME") 来检查特定项目是否正在运行。 我必须为旧的嵌入式 Windows XP 版本创建一个 C
我的问题:在给定 PID 的情况下,我可以使用什么来检索某个进程的 processName 或 packageName? 因为在我的任务管理器中,我想在使用 killBackgroundProcess
这个问题在这里已经有了答案: scanf() leaves the newline character in the buffer (7 个答案) 关闭 5 年前。 我的代码是 //header f
我正在通过 Validator 类验证我的 jaxb 对象。下面是我用来验证 jaxb 对象的代码。但是在验证它时我收到了这个错误。 jc = JAXBContext.newInstance(obj.
我是一名优秀的程序员,十分优秀!