Link to home
Create AccountLog in
Avatar of NetManaged
NetManagedFlag for United States of America

asked on

Display message box that disappears

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
Avatar of RobSampson
RobSampson
Flag of Australia image

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.
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.
Avatar of NetManaged

ASKER

Rob,

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

Greg
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

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.
Rob ROCKS!