Solved

Logon Script using VBS Script

Posted on 2009-04-06
8
563 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
  • 5
  • 3
8 Comments
 
LVL 31

Expert Comment

by:DrUltima
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:DrUltima
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
 
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
Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

 
LVL 31

Expert Comment

by:DrUltima
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:
DrUltima 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:DrUltima
ID: 24083833
Looking over it, line 27 should have been:

If IsMember ("NMPG Printer", objUser) Then

Sorry
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The question has been asked on multiple occasions as to how best to do printing in a remote desktop or terminal services environment.   It seems that this particular question has plagued several people and most especially as Terminal Services, as…
This is my 3rd article on SCCM in recent weeks, the 1st (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html) dealing with installat…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now