[英]How to start a Windows process minimized using WMIC?
Is there a way to start a process from a Windows 7 batch file (or from the command-line) using WMIC
?有没有办法使用WMIC
从 Windows 7 批处理文件(或从命令行)启动进程? I am basically looking for the equivalent of START /MIN
.我基本上是在寻找等效的START /MIN
。
And not that I need it, but in case someone else might, what would be the START /MAX
equivalent using WMIC
?并不是我需要它,但万一其他人可能,使用WMIC
的START /MAX
等效项是什么?
You'll need to write a vbs script.您需要编写一个 vbs 脚本。 From http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/aa394375(v=vs.85).aspx来自http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspx和http://msdn.microsoft.com/en-us/library/aa394375(v=vs.aspx) 85).aspx
Const SW_NORMAL = 1
strComputer = "."
strCommand = "Notepad.exe"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
' Configure the Notepad process to show a window
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = SW_NORMAL
' Create Notepad process
Set objProcess = objWMIService.Get("Win32_Process")
intReturn = objProcess.Create _
(strCommand, Null, objConfig, intProcessID)
If intReturn <> 0 Then
Wscript.Echo "Process could not be created." & _
vbNewLine & "Command line: " & strCommand & _
vbNewLine & "Return value: " & intReturn
Else
Wscript.Echo "Process created." & _
vbNewLine & "Command line: " & strCommand & _
vbNewLine & "Process ID: " & intProcessID
End If
There is no need to search for a equivalent of start /min
(unless there are additional requirements).无需搜索等效的start /min
(除非有其他要求)。 Just use start /min
只需使用start /min
wmic process call create "cmd /c start /min notepad.exe"
Of course /max
works the same.当然/max
工作原理是一样的。
Not using wmic
, but I think it does what you need:不使用wmic
,但我认为它wmic
您的需求:
powershell.exe Start-Process -WindowStyle Minimized -PassThru notepad
Output contains PID:输出包含 PID:
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
18 3 1232 1616 0,03 51784 1 notepad
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.