Solved

Logon Script using VBS Script

Posted on 2009-04-06
8
576 Views
Last Modified: 2013-12-05
Hello all,
I am a newbie to scripting so please be gentle.
All users that connect to these servers will be going through remote desktop connection.
I have the following:
1)  A VBS script that I want to run when the user logs on to the initial part of TS, that an informational box pops up.  This VBS script to do this runs beautifully.
2)  A designated desktop background will load.
I want to accomplish both of these based upon the group the user is in.
For instance,
Say the user is in groupA, then I want them to get informational box A from #1 and desktop background A from number 2.
If the user is in group B then I want them to get informational box B from #1 and desktop background B from number2.
I am including the VBS script from #1 for the informational box A
Could someone help me write this script?
Thank you much in advance,
Kelly W.
'Created: 4/6/2009 10:06:14 AM
'Author: Kelly Wilke -- Misys Tiger Team
'Created by SAPIEN Technologies, Inc. Logon Script Generator
'**********************
 
On Error Resume Next
Dim objFSO,objFILE,objShell,objNetwork
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")
 
strWelcomeMsg="You are entering the Misys Tiger physician practice management" & VbCrLf & "software on file server 1.  " & VbCrLf & VbCrLf & "This is NOT your desktop PC and it is for business use only!!!"
 
 
'build summary message
iDisplayTimeout=15
strMsg=""
strMsg=strMsg & strWelcomeMsg & VbCrLf
strMsg=strMsg & vbcrlf
strMsg=strMsg & vbcrlf
'display summary message
If strMsg<>"" Then objShell.Popup strMsg,iDisplayTimeout,"Logon Summary",vbOKOnly+vbInformation
'End of main script
 
'//////////////////////////////////////////////////
Function PasswordExpires(strDomain,strUser)
On Error Resume Next
Dim objUser
Set objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
PassExp=INT(objUser.MaxPasswordAge/86400)-INT(objUser.PasswordAge/86400)
 
If PassExp<0 Then 
 strPassMsg="Your password never expires."
Else
 strPassMsg="Your password expires in " & PassExp & " day(s)"
end If
 
PasswordExpires=strPassMsg
End Function
 
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
 
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
 
Sub AddPrinterConnection(strPrinterUNC)
On Error Resume Next
 
objNetwork.AddWindowsPrinterConnection 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

0
Comment
Question by:Kelly_W
[X]
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
  • 5
  • 3
8 Comments
 
LVL 31

Expert Comment

by:Justin Owens
ID: 24080276
You have to make sure:

1) Your user is declared
2) Your group is known

You can then use an "if" statement to query the built-in "IsMember"  to perform the required actions.  See short example below....

Dim User
 
User = GetUserName
 
' Map Specific Share on Specific Server to Q
	If IsMember ("SecurityGroupForShare", User) Then MapDrive "Q:", "\\Server\Share"

Open in new window

0
 
LVL 4

Author Comment

by:Kelly_W
ID: 24080362
Hello,
Okay, the users are declared (as far as I can tell) and the groups are known.
Again, I am new to scripting so let's say that fflintstone is the user and the group is NMPG Printer group.
How would I script it to check to see if the user is in NMPG Printer group then we will run the VBS Script (for the informational box) named box4 and have the wallpaper of wallpaper4?
By the way, we are not mapping any drives so I do not need to do that.
Thanks,
Kelly W.
0
 
LVL 31

Expert Comment

by:Justin Owens
ID: 24080410
I was showing that Map Drive as an example of how to check for the user's group. :)  See code below for exact syntax:

Dim User
 
User = GetUserName
 
' Perform actions for NMPG Printer group here:
        If IsMember ("NMPG Printer", User) Then 'add code here

Open in new window

0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 4

Author Comment

by:Kelly_W
ID: 24080474
Hello DrUltima,
Okay so where you have add code here, how do I tell it to run the box4 VBS script?
Also how do I tell it to use the wallpaper4 wallpaper?
Thanks for all your help.
Kelly W.
0
 
LVL 31

Expert Comment

by:Justin Owens
ID: 24080522
Here is where my lack of VBScript knowledge will hinder me. :)  I can submit a sample code, but it will be ugly and large and probably more complicated than would be necessary. :)  Give me a few minutes, and I will have something posted for you.
0
 
LVL 31

Accepted Solution

by:
Justin Owens earned 500 total points
ID: 24080743
OK... Like I said, it is ugly and long.....

'Created: 4/6/2009 10:06:14 AM
'Author: Kelly Wilke -- Misys Tiger Team
'Created by SAPIEN Technologies, Inc. Logon Script Generator
'**********************
 
'DRU - I added the 'DRU - to anything I commented, and I tried to comment anything I changed.  I also cleaned up the Functions and Subs you built to make them a little neater. 
 
On Error Resume Next
 
'DRU - I added the DIMed objUser
Dim objFSO,objFILE,objShell,objNetwork,objUser
set objFSO=CreateObject("Scripting.FileSystemObject")
set objShell=CreateObject("Wscript.Shell")
set objNetwork=CreateObject("Wscript.Network")
objUser = GetUserName
 
'DRU - Here we are defining the Function GetUserName used above:
Function GetUserName ()
	Dim WshShell
 	Set WshShell = CreateObject("WScript.Shell")
	GetUserName = WshShell.ExpandEnvironmentStrings("%UserName%")
	Set WshShell = Nothing
End Function
 
'DRU -  Here is where you I would have to define the "if in groupA then do this" stuff because I don't know a better way to do it:
 
If IsMember ("NMPG Printer", User) Then
	strWelcomeMsg="You are entering the Misys Tiger physician practice management" & VbCrLf & "software on file server 1.  " & VbCrLf & VbCrLf & "This is NOT your desktop PC and it is for business use only!!!"
	  
	'build summary message
	iDisplayTimeout=15
	strMsg=""
	strMsg=strMsg & strWelcomeMsg & VbCrLf
	strMsg=strMsg & vbcrlf
	strMsg=strMsg & vbcrlf
	'display summary message
	If strMsg<>"" Then objShell.Popup strMsg,iDisplayTimeout,"Logon Summary",vbOKOnly+vbInformation
	'End of main script
	 
	'//////////////////////////////////////////////////
 
	Function PasswordExpires(strDomain,strUser)
		On Error Resume Next
		'DRU - Here I commented out your objUser parameters because they were defined earlier now....
		'Dim objUser
		'Set objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
		PassExp=INT(objUser.MaxPasswordAge/86400)-INT(objUser.PasswordAge/86400)
		If PassExp<0 Then 
			strPassMsg="Your password never expires."
			Else
			strPassMsg="Your password expires in " & PassExp & " day(s)"
		end If
		PasswordExpires=strPassMsg
	End Function
	 
	Function IsAMemberOf(strDomain,strUser,strGroup)
		On Error Resume Next
		'DRU - Again, I commednted out your objUser parameters because they were defined earlier now....
		'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
	 
	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
	 
	Sub AddPrinterConnection(strPrinterUNC)
		On Error Resume Next
		objNetwork.AddWindowsPrinterConnection 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
End If
 
'DRU - Repeat code for your other groups... Again, this is a LONG way to do it, and I am sure that a better programmer would be able to shorten it.

Open in new window

0
 
LVL 4

Author Closing Comment

by:Kelly_W
ID: 31567168
This works great.  I will be using this.  Thank you so very much
0
 
LVL 31

Expert Comment

by:Justin Owens
ID: 24083833
Looking over it, line 27 should have been:

If IsMember ("NMPG Printer", objUser) Then

Sorry
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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