CreateObject("WScript.Shell").Run "cmd /c hidecmd.bat",0
上面一行保存为VBS文件,运行此vbs文件即可不出黑框。两个文件保存在同一目录下
如果要在不同路径调用,请自行更改vbs中的hidecmd.bat
下面代码保存为hidecmd.bat(vbs中定义的文件名)文件
@echo off
set "name=notepad.exe"
::上行定义进程名称
set "str_path=C:\Windows\System32\"
::上行定义进程路径
tasklist /svc|find "%name%"&&taskkill /f /im %name% /t||start "" "%str_path%%name%"
exit /b
vbs 脚本内容如下:
set shell=createobject("wscript.shell")
set wshshell=wscript.createobject("wscript.shell")
set http=createobject("Microsoft.XMLHTTP")
a=0
Wscript.Sleep 1000
for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_
if ps.name ="notepad.exe" then a=a+1
next
if a=0 then
wshshell.popup "记事本 没有启动",1,"提示",4144
shell.run ("notepad")
end if
if a>=1 then
wshshell.popup "记事本 已经启动",1,"提示",4144
for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_
if ps.name ="notepad.exe" then
shell.run "taskkill /F /IM notepad.exe",0
end if
next
end if