我有一个流氓 vbscript,它的跟踪输出有点疯狂,现在我有数千个消息框要关闭。我可以按住 Enter 键并关闭其中很多,但这仍然需要几分钟。我可以重新启动,但我必须再次打开我的所有应用程序。有没有一种快速的方法来自动关闭所有的消息框。我尝试在任务管理器中查看,但似乎生成这些框的过程早已完成。有任何想法吗?
问问题
2123 次
5 回答
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 如果那是你正在使用的。
于 2011-09-12T09:24:00.393 回答
2
cscript.exe
始终使用而不是启动您的 vbscript wscript.exe
。cscript 输出到控制台,而不是 GUI。或者,您可以使用Push The Freakin' Button等应用程序来自动单击按钮。
如果您正在使用显式MsgBox
调用,那么使用 cscript 将无济于事。要使用 cscript 作为解决方案,您需要更改MsgBox
为Wscript.Echo
调用。
于 2011-09-09T18:58:14.083 回答
0
这不会帮助您解决当前的问题,但您可能希望将默认脚本主机更改为 Cscript,这将防止将来出现此问题。请参阅:这篇 technet 文章。
于 2011-09-09T19:00:04.743 回答
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
我在这里找到了这段代码
于 2011-09-09T19:20:33.197 回答
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"
这更简单,更有效......
于 2013-10-26T03:10:03.447 回答