简体   繁体   English

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

[英]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 ?并不是我需要它,但万一其他人可能,使用WMICSTART /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).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

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.

相关问题 如何使用wmic获取特定进程的进程ID并检查错误? - How to get process ID of a specific process using wmic and check on error? 如何使用cmd在最小化窗口中启动Windows 10应用程序? - How do I start a Windows 10 app in a minimized window using cmd? 如何启动在Windows CE设备中最小化的批处理文件(使用另一个批处理或快捷方式)? - How to start a batch file minimized in a Windows CE device (using another batch or shortcut)? WMIC流程调用开始无法远程运行 - WMIC process call start not working remotely 如何使用WMIC从远程服务器启动应用程序 - How to start an application from a remote server using WMIC Windows批处理文件wmic获取Java进程的PID,如何将标记设置为变量以测试PID是否存在? -如果没有启动,则提示重新启动 - Windows batch-file wmic to get PID of a java process, how do I set tokens to a variable to test if PIDs exist? - start if not,else prompt for restart 如何在wmic进程的like子句中传递变量? - How to pass variable in like clause of wmic process? 如何使用wmic查找进程pid并使用taskkill将其杀死 - How to find a process pid with wmic and kill it with taskkill Wmic进程在for循环中调用未启动cmd - Wmic process call in for loop doesn't start the cmd 如何在 Windows 8 中启动使用任务计划程序最小化的批处理文件? - %comspec% 方法在 Windows 7 之后不再起作用 - How to start a batch file minimized with task scheduler in Windows 8? - %comspec% method not working anymore after Windows 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM