Display message box that disappears

Posted on 2013-05-13
Last Modified: 2013-06-22

      Looking for a solution to do the following in a Remote Desktop Farm.
#1 Start a script that displays a message box about another vbscript that will be running concurrently. ie. "The special printer script is running, do not start App X until it is complete"
Also, the message cannot be closed by the user.
#2 Code in that message box script that monitors for the completion of the the other vbscript.
#3 Code that then dispays the other script is complete and exits automatically. ie."The special printer script is complete, you can now start App X"

OR embed that code into the "special printer script" (which is a vbscript)

Possibly an HTA would work, but I want to ask the experts at EE.

Question by:NetManaged
  • 4
  • 4
LVL 65

Expert Comment

ID: 39163771
Hi, this isn't hugely sophisticated, and doesn't exactly meet the requirement of not allowing the first message to close, but it does relaunch the message until the install script has fininished.

In TestVBS1.vbs I have this:
Set objShell = CreateObject("WScript.Shell")
strPromptScript = "wscript.exe C:\Temp\Scripts\TestVBS2.vbs"
strInstallScript = "wscript.exe C:\Temp\Scripts\TestVBS3.vbs"
Set objExec1 = objShell.Exec(strPromptScript)
Set objExec2 = objShell.Exec(strInstallScript)
While objExec2.Status = 0
	WScript.Sleep 100
	If objExec1.Status <> 0 Then Set objExec1 = objShell.Exec(strPromptScript)
MsgBox "Finished"

Open in new window

and in TestVBS2.vbs I have this:
MsgBox "Please wait while the application installs..."

Open in new window

and in TestVBS3.vbs I have this, although just for visual testing.  Yours should be silent if possible.
MsgBox "Click OK to simulate install script finishing"

Open in new window


LVL 65

Expert Comment

ID: 39163773
Otherwise as you mentioned, your first script could call a HTA in which you've specified properties like:

and then Terminate that HTA in the same way above when the install script finishes.


Author Comment

ID: 39172166

Thanks for your response! Let me test this out for a bit and I will get back to you.


Author Comment

ID: 39200017

Argh! Sorry it has taken me so long to get back to you!

Hmmm...after reviewing the examples you provided and my existing script, I realized I need more hand-holding on this one.

Below is the code you helped me develop for renaming users' redirected Remote Desktop printers with long names in an Active Directory domain. The GPO contains the authentication credentials needed to run some of the actions in the script.

I'm running into a timing issue with some of the users and want to add notification (ie. Don't click ANY apps until the printers have been renamed!) to the existing script.

How would I add that to my existing script and still call the administrative username and password contained in the GPO?
Below is the script:
'This script addresses the problem of applications running on a Terminal Server/Remote Desktop Session Host 
'with long redirected session printer names.
'This script runs as an Active Directory Logon Script. 
'When adding the Logon Script in Active Directory, place this script in the standard location when clicking on Browse for the Script Name field. 
'Either \\<internal.local, etc.>\SysVol\<internal.local, etc.>\Policies\{some policy number unique to your domain}\User\Scripts\Logon
'OR \\<Domain Controller>\NetLogon
'NEXT, in the Script Parameters: field, place your elevated credentials in the following format Domain\username password.
'ALL Credit goes to Rob Sampson from Australia for his assistance in developing this script. Greg Shepherd, NetManaged

If WScript.Arguments.Count <> 2 Then WScript.Quit

WScript.Sleep 30000

strDomainAdmin = WScript.Arguments.Item(0)
strDomainPW = WScript.Arguments.Item(1)

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

'Add a separate line below for each printer to detect the significant part of the name then rename to a new name. 
'For Example: objDictionary.Add "OldPrinterName", "NewPrinterName"
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "CFC-NDPtr1", "CFCNDPTR1"
objDictionary.Add "IMC-FDPtr1", "IMCFDPTR1"
objDictionary.Add "IMC-FDPtr2", "IMCFDPTR2"

'This section checks for the default printer of the currently logged on user, 
'checks the Dictionary List above and, if there is a match runs the Sub named SetRENRDRPTR
Set objScriptExec = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT Name FROM Win32_Printer WHERE Default=True", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
	For Each strOldName In objDictionary
		If InStr(objItem.Name,strOldName) <> 0 Then SetRENRDRPTR objItem.Name, objDictionary(strOldName)

Sub SetRENRDRPTR(strPrinterName, strNewName)

'Detects the currently logged on user, the user's default printer and runs psexec with elevated credentials 
'to set Ownership of the user's default printer to the currently logged on domain user. 
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "C:\Support\psexec -accepteula -i -u " & strDomainAdmin & " -p " & strDomainPW & " \\" & objNetwork.ComputerName & " C:\Support\SetACL\x64\SetACL.exe -on """ & strPrinterName & """ -ot prn -actn setowner -ownr ""n:" & objNetwork.UserDomain & "\" & objNetwork.UserName &";""", 0, True

'Sets the Manage Printers option of the printer we just changed OWner on, but MUST be run in the currently logged on user's security context. 
'Psexec with elevated credentials does NOT work for this action.
	objShell.Run "C:\Support\SetACL\x64\SetACL.exe -on """ & strPrinterName & """ -ot prn -actn ace -ace ""n:" & objNetwork.UserDomain & "\" & objNetwork.UserName & ";p:man_printer""", 0, True

'NOW we rename the printer from the Dictionary List and preserve the visible redirected printer session mapping number.
	Set colItems = objWMIService.ExecQuery("SELECT Name,Default FROM Win32_Printer WHERE Name='" & strPrinterName & "'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
	For Each objPrinter In colItems
		If InStr(LCase(objPrinter.Name), "redirected") > 0 Then
			strNumber = Left(Mid(objPrinter.Name, InStrRev(objPrinter.Name, " ")), Len(Mid(objPrinter.Name, InStrRev(objPrinter.Name, " "))) - 1)
			strNewName = strNewName & " (" & strNumber & ")"
		End If
		blnDefault = objPrinter.Default

'Now we reset the renamed printer as the default again (Renaming loses the Default Printer setting and we have to reset it).	
	If blnDefault = True Then
		Set colItems = objWMIService.ExecQuery("SELECT Name FROM Win32_Printer WHERE Name='" & strNewName & "'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
		For Each objPrinter In colItems 
	End If
End Sub

Open in new window

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

LVL 65

Accepted Solution

RobSampson earned 500 total points
ID: 39204159
It looks you would need to run the "parent" script that I posted first here, and pass your arguments to that, then in the parent script change

strPromptScript = "wscript.exe C:\Temp\Scripts\TestVBS2.vbs"
strInstallScript = "wscript.exe C:\Temp\Scripts\TestVBS3.vbs"


strPromptScript = "wscript.exe \\internal.local\sysvol\internal.local\Scripts\ShowPromptToUser.vbs"
strInstallScript = "wscript.exe \\internal.local\sysvol\internal.local\Scripts\ReconfigurePrinters.vbs"

and then also change

Set objExec2 = objShell.Exec(strInstallScript)


Set objExec2 = objShell.Exec(strInstallScript & " " & WScript.Arguments(0) & " " & WScript.Arguments(1))

This way, your GPO is passing the parameters on to the parent script, and this script is then passing those to the printer configuration script.

I'm pretty sure this would work, it just means you need three scripts since VBScript is not really capable of asynchronous execution.



Assisted Solution

NetManaged earned 0 total points
ID: 39255100

Sorry it has taken me so long to get back to you on this.

Worked pretty good! I did tweak with some different code to automatically close the dialogue when finished.
After Line 11 in TestVBS1, I added the following:
Line 11:'MsgBox "Finished"
Line 12:Wscript.timeout = 3
Line 13:MsgBox "Finished!",vbExclamation,"Printer Renamed!"

Thank you for your help AND patience!
LVL 65

Expert Comment

ID: 39255109
OK cool.  Sorry it took so long to find a's one of those things that takes me a while to piece together what you need.


Author Closing Comment

ID: 39267798

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

To effectively work with Diskpart on a Server Core, it is necessary to write some small batch script's, because you can't execute diskpart in a remote powershell session. To get startet, place the Diskpart batch script's into a share on your loca…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now