Reputation: 157
I have a developed a script that at some point in the code calls a VBScript that minimizes all current open Windows and displays a MsgBox. The script is set to run at startup so, other applications are also starting while the user logs in to the machine.
Batch code calling VBS – >
cscript //nologo lckPNot.vbs
lckPNot.vbs – >
set objShell = CreateObject("shell.application")
objShell.MinimizeAll
x=MsgBox ("Message Here.",0+48,"Notification")
The objShell.MinimizeAll
successfully minimizes all open current Windows however I face an issue once a window opens up after the objShell.MinimizeAll
and before the user provides his input to the MsgBox.
i.e. I need a way to say the following:
while MsgBox = Visible
Minimize All
Loop
If the above is not possible, I can also try to use the loop in the batch code itself, i.e. while lckPNot.vbs = Running Call KillProcesses.bat Loop
Where KillProcesses.bat
is another batch that kills all open tasks (instead of minimize) at a given point.
How can that be done?
Upvotes: 1
Views: 809
Reputation: 1995
Run the MsgBox in a separate process and check for that. Like this:
WaitOnMsgBox.vbs
Set oShell = CreateObject("Wscript.Shell")
Set oShApp = CreateObject("Shell.Application")
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Function ProcessExist(Exe,File)
ProcessExist = False
On Error Resume Next
Set oProcesses = oWMI.ExecQuery("SELECT * FROM Win32_Process")
For Each oProcess In oProcesses
If InStr(oProcess.CommandLine,Exe) Then
If InStr(oProcess.CommandLine,File) Then
ProcessExist = True
Exit Function
End If
End If
Next
On Error Goto 0
End Function
oShell.Run ".\MsgBox.vbs ""Message Here"" 0+48 ""Notification""",1,False
Do While ProcessExist("\WScript.exe","\MsgBox.vbs")
oShApp.MinimizeAll
WScript.Sleep 500
Loop
MsgBox.vbs
On Error Resume Next
Message = WScript.Arguments.Item(0)
Icon = Eval(WScript.Arguments.Item(1))
Title = WScript.Arguments.Item(2)
On Error Goto 0
MsgBox Message,Icon,Title
Upvotes: 1