簡體   English   中英

如何啟動使用 WMIC 最小化的 Windows 進程?

[英]How to start a Windows process minimized using WMIC?

有沒有辦法使用WMIC從 Windows 7 批處理文件(或從命令行)啟動進程? 我基本上是在尋找等效的START /MIN

並不是我需要它,但萬一其他人可能,使用WMICSTART /MAX等效項是什么?

您需要編寫一個 vbs 腳本。 來自http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspxhttp://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

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

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

當然/max工作原理是一樣的。

不使用wmic ,但我認為它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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM