vbs:
pid = 0
Set w = GetObject("winmgmts:")
Set p = w.ExecQuery("select * from win32_process where name='appName.exe'")
if p.Count = 0 then
msgbox "can not find the app by name。"
else
For Each i In p
pid = i.ProcessId
wscript.echo pid
Next
end if
bat:
for /f "delims=" %%i in ('cscript //nologo pid.vbs') do set "pid=%%i"
其中pid为返回的程序pid
pid = 0
Set w = GetObject("winmgmts:")
Set p = w.ExecQuery("select * from win32_process where name='appName.exe'")
if p.Count = 0 then
msgbox "can not find the app by name。"
else
For Each i In p
pid = i.ProcessId
wscript.echo pid
Next
end if
bat:
for /f "delims=" %%i in ('cscript //nologo pid.vbs') do set "pid=%%i"
其中pid为返回的程序pid