ObjShell.Popup - Minimized - VBScript

Hi All,

I am trying to run a script which has popups kind of telling the user that the script is still active. The issue that I am running into is that the popups are minimized. Is there a way to have it open on the main screen?
Here is the code.

Const TIMEOUT = 6
Set ObjShell = WScript.CreateObject ("WScript.Shell")
ObjShell.Popup ' This is a Test", TIMEOUT
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
How are you running the script, from a command prompt with CSCRIPT, from Task Scheduler, just double clicking the VBS, etc?

Vicki05Author Commented:
I am double clicking the vbscript. In the vbscript I need to show some kind of progress popups.
Bill PrewIT / Software Engineering ConsultantCommented:
I assume that this line is just a typo in this question, not in the actual code:

ObjShell.Popup ' This is a Test", TIMEOUT

and really looks like:

ObjShell.Popup "This is a Test", TIMEOUT

With that change here I ran it and the popup appears on the screen.  If you test just this small code does it work, or not?

It may be that something else in your VBS script is placing the main process window minimized, could that be possible?  Or is the user potentially minimizing that window?

OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Vicki05Author Commented:
Hi Bill,

You are correct, I did test the script and I am calling a batch file which I think is causing the popup to run minimized.

  Set NewShell = WScript.CreateObject("WScript.Shell")
  SourceDrive = left(NewShell.CurrentDirectory,1)
  Set fso = CreateObject("Scripting.FileSystemObject")      
  Newshell.run "\Test\Test1.bat"
  Set NewShell = nothing

once this runs, the popup runs minimized. Any way to work around this?
Bill PrewIT / Software Engineering ConsultantCommented:
Not sure if this will work, but try:

Newshell.run "\Test\Test1.bat", 1

Also, depending on what you are doing, this might be a good use of a HTA approach rather than just VBS.  HTA basically provides a UI with the script you are executing and you could update that with status as the process executed.

If you think that could be useful let me know and I'll provide a small example of it in action.  Most of the VBS code you have should still be useful.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vicki05Author Commented:
Awesome Bill,

The solution you provided solved my issue. If it is not to much hassle, could you please provide me a small example of the HTA approach you are suggesting?
Vicki05Author Commented:
Thanks for all your help again. I really am grateful for your quick response.
Bill PrewIT / Software Engineering ConsultantCommented:
Sorry for the delay Vicki, a little harder to find a "simple" example that would be similar to what you would be interested in, may have to work something up...

Vicki05Author Commented:
I would appreciate all the help. Currently I am using the ObjShell.Popup method, but there is a delay sometimes I do not see a next one for 30 seconds.
Bill PrewIT / Software Engineering ConsultantCommented:
Here's a sample you can test and maybe build off of.  It displays the current time and a status message that you can update as the main process runs.

I did a simple "processing" job, just calculating prime numbers up to 60, and added a delay of 1 second after each found prime, so the screen didn't close out too quick.

Hopefully this gives you the idea...

Save as a .HTA file, and then just type the name at a command prompt, or double click it from File Explorer.

<title>Check File Status</title>
    applicationname="Check File Status"

<script language="VBScript">
Dim timerID

' Logic to execute at startup
Sub Window_OnLoad
    ' Set window size
    window.resizeTo 400,250

    ' Display current time

    ' Setup timer to call UpdateTime every second
    timerID = window.setInterval("UpdateTime", 1000)

    ' Execute main logic
End Sub

Sub UpdateTime()
    ' Update current time on window
    CurrentTime.InnerHTML = Now
End Sub

Sub DoProcess()

    ' Generate prime number less than 6-
    PrimeMax = 60

    ' Check each number up to max
    For i=1 to PrimeMax

        ' Assume it's a primt for now
        IsPrime = True

        ' 1 through 3 are given to be prime
        If  i >= 4 Then
            ' Check if current number divisible by any prior number
            For j=2 to i/2
                If i mod j = 0 Then
                    ' Can be divided by some number, not prime
                    IsPrime = False
                End If
        End If

        ' If it was prime, display on window
        If IsPrime Then
            Message.innerHTML = "Processing number - " & i
        	Sleep 1
        End If


    ' Clear timer, close window at end of main logic
End Sub

Sub Sleep (Timesec)
    ' Delay for desired number of seconds
    With CreateObject("WScript.Shell") 
        .Run "Timeout /T " & Timesec & " /nobreak" ,0 ,true
    End With
End Sub



<div id="time">
<span id="CurrentTime"></span>
<p />
<div id="status">
<span id="Message"></span>


Open in new window

Vicki05Author Commented:
Thanks Bill,

I will give it a shot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.