我有一个流氓vbscript,它有点疯狂追踪输出,现在我有数千个消息框要关闭。我可以按住Enter键并关闭其中许多但仍需要几分钟。我可以重新启动但是我必须再次打开我的所有应用程序。有没有快速自动关闭所有消息框的方法。我试着查看任务管理器,但看起来产生这些盒子的过程已经很久了。有什么想法吗?
答案 0 :(得分:3)
不确定如何拥有孤立的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,如果你正在使用它。
答案 1 :(得分:2)
始终使用cscript.exe
代替wscript.exe
启动您的vbscript。 cscript输出到控制台,而不是GUI。或者,您可以使用Push The Freakin' Button等应用程序自动执行按钮点击。
如果您使用明确的MsgBox
来电,那么使用cscript对您没有帮助。要将cscript用作解决方案,您需要将MsgBox
更改为Wscript.Echo
次来电。
答案 2 :(得分:0)
这不会帮助您立即解决问题,但您可能希望将默认脚本主机更改为Cscript,这将在未来防止出现此问题。请参阅:this technet article。
答案 3 :(得分:0)
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
答案 4 :(得分:0)
要关闭所有窗口并一次性停止所有进程,为什么不打开命令提示符窗口并输入:
TASKKILL /F /IM cmd.exe /T
或
TASKKILL /F /IM wscript.exe /T
这将立即终止所有cmd.exe或wscript.exe进程...如果它必须在脚本中,您可以像WshShell.Run "TASKKILL /F /IM cmd.exe /T"
这更加简单有效......