Link to home
Start Free TrialLog in
Avatar of vithal_m
vithal_m

asked on

HTA front end for a Logonscript in VBS

Hello guys,

I have made a VBScript that does some very basic tasks like mapping network drivers and crreating printer connections. I wold like to wrap that script into a HTA and display the progress of the script when a user logs on. I am not really good with HTAs. Any pointers to where I can start would be highly appreciated. Following is the code.
I would like the HTA to display the name of the company on the top and the task currently running with a progress bar and exit when all tasks are done.

Happy to give more information if required.

Thanks,
VM

OPTION EXPLICIT
 
DIM strGroup, strUserPath, strGroupName, strGroupPath, strDomain, strUser, LogonServer, strUNCPrinter
DIM objNetwork, objFso, objShell, objOS, objWMIService, objUser, objGrp, objSysInfo, objSysEnv,  blnShowError
 
CONST ForReading = 1, ForWriting = 2
 
SET objSysInfo = CreateObject("ADSystemInfo")
SET objShell = WScript.CreateObject("WScript.Shell")
SET objFso = CreateObject("Scripting.FileSystemObject")
SET objSysEnv = objShell.Environment("PROCESS")
SET objNetwork = CreateObject("WScript.Network")
strUNCPrinter = "\\Sydprint\Xerox"
 
LogonServer = objShell.ExpandEnvironmentStrings("%LOGONSERVER%")
'Wscript.Echo LogonServer
strDomain = objNetwork.UserDomain
'Wscript.Echo strDomain
strUser = objNetwork.UserName
'Wscript.Echo strUser
 
'************************************************************************************************************************************************************************
'************************************************************************************************************************************************************************
' SERVER CHECK: This part of the script will check if the current machine is a server or not. If it is a server the script execution will end right here.
			'Connect to WMI and obtain instances of Win32_OperatingSystem
FOR EACH objOS IN GetObject( _  
						   "winmgmts:").InstancesOf ("Win32_OperatingSystem")
	IF NOT objOS.ProductType = 1 THEN
		Wscript.Echo objOS.ProductType
		Wscript.Quit
	END IF
NEXT
 
IF Err <> 0 THEN
	Err.Clear
END IF
 
'************************************************************************************************************************************************************************
'************************************************************************************************************************************************************************
'USER MEMBERSHIP CHECK: Checks the membership of the user and depending on it maps the corresponding network drives, printers if any
 
'ON ERROR RESUME NEXT 
 
'################################################### KAPSTREAM #####################################################
 
IF IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"BUG-BTQ-KAPSTREAM-Admin") THEN 
		MapIt "G:","\\CSSYDA012\Kapstream$"
		AddPrinterConnection strUNCPrinter
		Wscript.Quit
END IF
 
'################################################### GREENCAPE #####################################################
 
IF IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"sg-MELC-Green Cape") THEN
		MapIt "G:","\\CSMELC010\Greencape$"
		Wscript.Quit
END IF
 
'################################################### 5 OCEANS# #####################################################
 
IF IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"sg-SYDA-5oam") THEN
		MapIt "L:","\\CSSYDA012\CHALLSYD"
		AddPrinterConnection strUNCPrinter
		Wscript.Quit
END IF
 
'######################################################ARDEA ######################################################
 
IF IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"BUG-BTQ-ARDEA-AllUsers") THEN
		MapIt "Q:","\\CSSYDA012\Ardea$"
		AddPrinterConnection strUNCPrinter
		Wscript.Quit
END IF
 
 
'##################################################### KINETIC #####################################################
 
IF IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"sg-MELC-Kinetic") THEN
		MapIt "G:","\\CSMELC010\Kinetic$"
		Wscript.Quit
END IF
 
'################################################################################################################
 
'************************************************************************************************************************************************************************
'************************************************************************************************************************************************************************
 
'Function that checks the group membership of the user
FUNCTION IsAMemberOf(strDomain,strUser,strGroup)
'ON ERROR RESUME NEXT
SET objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
SET objGrp=GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
 
	IF objGrp.IsMember(objUser.ADsPath) THEN
		IsAMemberOf=TRUE
		ELSE
			IsAMemberOf=FALSE
	END IF 
END FUNCTION
 
 
'************************************************************************************************************************************************************************
'************************************************************************************************************************************************************************
' Function that maps network drives
SUB MapIt(strDrive,strMap)
'ON ERROR RESUME NEXT
	IF objFSO.DriveExists(strDrive) THEN objNetwork.RemoveNetworkDrive(strDrive)
 
		objNetwork.MapNetworkDrive strDrive,strMap
 
			IF Err.Number<>0 AND blnShowError THEN
				strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_
				strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
				VbCrLf & Err.Description
				objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
				Err.Clear
			END IF
 
END SUB
 
'************************************************************************************************************************************************************************
'************************************************************************************************************************************************************************
'Function that Maps the default printer. Only Maps \\SYDPRINT\XEROX to Sydney users
SUB AddPrinterConnection(strPrinterUNC)
ON ERROR RESUME NEXT
 
objNetwork.AddWindowsPrinterConnection strPrinterUNC
objNetwork.SetDefaultPrinter strPrinterUNC
 
IF Err.Number<>0 AND blnShowError THEN
	strMsg="There was a problem mapping " & UCase(strPrinterUNC) & ". " &_
	vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
	VbCrLf & Err.Description
	
	objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
	Err.Clear
END IF
 
END SUB
 
SUB AddPrinterPortConnection(strPort,strPrinterUNC)
ON ERROR RESUME NEXT
 
objNetwork.AddPrinterConnection strPort,strPrinterUNC
 
IF Err.Number<>0 AND blnShowError THEN
	strMsg="There was a problem mapping " & UCase(strPrinterUNC) & " to " &_
	strPort & vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_
	VbCrLf & Err.Description
	
	objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
	Err.Clear
END IF
 
END SUB
'************************************************************************************************************************************************************************
'************************************************************************************************************************************************************************

Open in new window

SOLUTION
Avatar of dkikalis
dkikalis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vithal_m
vithal_m

ASKER

Hello Rob,

The workaround you've suggested seems to be working. I am trying to figure out how to close the IE window once the logonscript has finished what its doing. Also I've done some research on the IE Properties. I am unable to figure out how to disable the Minize, Maximize and Close buttons on the top right of IE window..

Any ideas?

http://www.microsoft.com/technet/scriptcenter/guide/sas_ent_qpyo.mspx?mfr=true

Thank you
VM
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Rob,

Thanks heaps for your response. It was of great help.

Just wondering is there a way to get #### oIE.Document.Body.Title = "Debug Messages" #### this working. At the moment in the script I changed it to Logon Script in Progress but it does not show up in the title. I have attached a screenshot.

Also is there a way to center the text and change the font to something else and display a graphic. I found this article on MS http://www.microsoft.com/technet/scriptcenter/resources/qanda/mar05/hey0316.mspx 
I've used this script and every time it processes the INNERHtml command it will replace the text that was previously displayed.

Thanks in Advance,

VM  





Title.bmp
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Rob,

Thanks for the response. I will give it a try.
Yes I am familiar with HTML.

Thanks,
VM
Brilliant!! I was no where two days ago..but now I have a fully working solution. Great help from both of you guys. I wish I could award more points but 500 is all I can...Thanks to "dkikalis" for his help wtih HTAs and special thanks to Rob for all his help with this and IE front end.

Thanks again guys

VM
No problem.  Thanks for the grade.

Regards,

Rob.
Hi Rob,

This is how the final product looks like

Thanks heaps for your help again.

Final.bmp
Very nice!  Good work.  Did the Fullscreen not work?  Or you didn't bother with it?  I suspect that as it is, if you close the IE window, you'll get an error....

Rob.
Although of course you can always ALT + F4 anyway.....
yeah the full screen worked but I thought the users might not be comfortable with the whole screen being occupied by IE..

As you said the error came up but not when I close IE but i think it was more to do with the timing and the sequence of using Wscript.Quit or oIE.Quit....I did Quit IE first and then sleep for 3 seconds and then quit Wscript....

by the way I was looking at having logging facility in that window. if in case the script encounters some error duing processing....i would like to pause it and give the user an option to dump the log into a text file and may be if they want call the help desk....not a big deal...its a nice to have thing i guess.

Cheers
VM


I am a bit concerned that this post might be open to public viewing as I have attached the actual code that will be used...is there a way that we can remove the code from this post...or hide it from public viewing?

VM
Hi, you can use the "Request Attention" button at the top, and ask that your server names, and whatever else you feel is inappopriate, to be changed to just "server".  An EE page editor will hopefully do that for you.

As for logging, you have the basis for the screen output, so if you do a bit of error checking, you can do, say
On Error Resume Next
objNetwork.MapNetworkDrive "H:", "\\server\share"
If Err.Number <> 0 Then
   Trace "There was an error mapping H drive."
   btn_SaveOutput.visible = True
End If

but this approach requires that you have a fair bit more code...

btn_SaveOutput would be a hidden button on the page that you make, and when there's an error, this will be visible, and a user can click it to run the "save" code.

Regards,

Rob.
Rob, why would I get network path not found for line 94