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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.


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

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

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.

Question has a verified solution.

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

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

705 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