Solved

Display message box that disappears

Posted on 2013-05-13
8
828 Views
Last Modified: 2013-06-22
Hello,

      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.

Thanks,
Greg
0
Comment
Question by:NetManaged
  • 4
  • 4
8 Comments
 
LVL 65

Expert Comment

by:RobSampson
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)
Wend
objExec1.Terminate
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


Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 39163773
Otherwise as you mentioned, your first script could call a HTA in which you've specified properties like:
     BORDER="dialog"
     SCROLL="no"
     SHOWINTASKBAR="no"
     SINGLEINSTANCE="yes"
     SYSMENU="no"

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

Rob.
0
 

Author Comment

by:NetManaged
ID: 39172166
Rob,

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

Greg
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:NetManaged
ID: 39200017
Rob,

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)
	Next
Next
WScript.Quit

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
		objPrinter.RenamePrinter(strNewName)
	Next

'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 
			objPrinter.SetDefaultPrinter()
		Next
	End If
End Sub

Open in new window

0
 
LVL 65

Accepted Solution

by:
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"

to

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)

to

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.

Regards,

Rob.
0
 

Assisted Solution

by:NetManaged
NetManaged earned 0 total points
ID: 39255100
Rob,

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!
0
 
LVL 65

Expert Comment

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

Rob.
0
 

Author Closing Comment

by:NetManaged
ID: 39267798
Rob ROCKS!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
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…
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 configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

776 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