如何自动关闭VBScript数以千计的MsgBox的
我有一个流氓vbscript有点疯狂的跟踪输出,现在我有成千上万的消息框关闭。我可以按住Enter键并关闭它们,但仍需要几分钟时间。我可以重新启动,但我必须再次打开所有的应用程序。是否有快速自动关闭所有消息框的方法?我尝试寻找任务管理器,但似乎产生这些盒子的过程早已结束。有任何想法吗?如何自动关闭VBScript数以千计的MsgBox的
不知道你怎么能有孤儿MSGBOX窗口,你仍然应该的Cscript.exe或WScript.exe的在你正在运行的进程列表。下面应该终止底层的进程并关闭你的msgbox:
strComputer = "."
strProcessToKill = "wscript.exe"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
SET colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")
FOR EACH objProcess in colProcess
objProcess.Terminate()
NEXT
显然,改变wscript.exe。到cscript.exe,如果这就是你使用的。
总是用cscript.exe
而不是wscript.exe
开始你的vbscript。 cscript输出到控制台,而不是GUI。或者,您可以使用应用程序(例如Push The Freakin' Button)来自动执行按钮点击。
如果您使用明确的MsgBox
调用,那么使用cscript不会对您有所帮助。要使用cscript作为解决方案,您需要将MsgBox
更改为Wscript.Echo
调用。
Public Class Form1
Private m_Title As String
'Windows API
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hWnd As Int32, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
Declare Function SendMessage Lib "USER32" _
Alias "SendMessageA" (ByVal hWnd As Int32, _
ByVal Msg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Int32
Private Const WM_CLOSE As Int32 = &H10
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
m_Title = "Auto Close Msg"
Me.Timer1.Interval = 2000 'timer1 placed on form
Me.Timer1.Start()
MsgBox("Auto close in 2 seconds", MsgBoxStyle.OkOnly, m_Title)
End Sub
Private Sub CloseMSGBOX()
'Use Windows API to find and close the message box
'
'http://msdn.microsoft.com/en-us/library/…
'#32770 The class for a dialog box.
'http://msdn.microsoft.com/en-us/library/…
'
'http://msdn.microsoft.com/en-us/library/…
'
Dim hWnd, retval As Int32
Dim WinTitle As String
WinTitle = m_Title '<- Title of Window
hWnd = FindWindow("#32770", WinTitle) 'Get the msgBox handle
retval = PostMessage(hWnd, WM_CLOSE, 0, 0) ' Close the msgBox
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Timer1.Tick
CloseMSGBOX()
End Sub
End Class
我发现这个代码here
'Declare'不受VBScript支持。 – 2011-09-10 17:37:00
也不是'Dim x As {Type}'。这个答案不是VBScript! –
要关闭所有的窗口并停止所有流程一气呵成,为什么不打开一个命令提示符窗口,然后输入:
TASKKILL /F /IM cmd.exe /T
或
TASKKILL /F /IM wscript.exe /T
这将立即终止所有的命令。 EXE或WScript.exe的过程...如果它是一个脚本中,你可以这样调用它WshShell.Run "TASKKILL /F /IM cmd.exe /T"
这是更为简单和有效的...
注意我没有使用cscript来运行vbs,但MsgBox cmds是硬编码的,直到它完成之后我才意识到这一点。 –