如何使用WMIC最小化Windows进程?

时间:2014-05-19 01:18:25

标签: batch-file command-line process minimize wmic

有没有办法使用WMIC从Windows 7批处理文件(或从命令行)启动进程?我基本上在寻找相当于START /MIN

而不是我需要它,但万一其他人可能,使用START /MAX的{​​{1}}等价物是什么?

3 个答案:

答案 0 :(得分:0)

您需要编写vbs脚本。来自http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/aa394375(v=vs.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

答案 1 :(得分:0)

无需搜索等效的start /min(除非有其他要求)。只需使用start /min

即可
wmic process call create "cmd /c start /min notepad.exe"

当然/max的工作方式相同。

答案 2 :(得分:0)

不使用wmic,但我认为它可以满足您的需求:

powershell.exe Start-Process -WindowStyle Minimized -PassThru notepad

输出包含PID:

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
     18       3     1232       1616       0,03  51784   1 notepad