• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 182
  • Last Modified:

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
  • 6
  • 5
1 Solution
Bill PrewCommented:
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 PrewCommented:
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?

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 PrewCommented:
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.

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 PrewCommented:
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 PrewCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now