Solved

Login script

Posted on 2008-06-20
3
272 Views
Last Modified: 2010-04-16
I would like to fix a login script that dose the following:

1- Disconnect the drives: H: , G:, P: , T: , and W:

2- Map the new drive:
    H: = Home directory
    G: shared data
    P: shared programs
    T: special folder that will be mapped on group membership (Example: if user TEST is
        a member of group FINANCE then map the T: folder)
   W: anther shared data folder

In the same script I want to:
3- disconnect room1_printer, room2_printer, and so on
4- Map network printers based on computer location attribute and set a default printer
Some workstations have local printers and in some cases I dont want the local printer to be set as the default printer, instead a network printer will be the default printer.
In other cases the local printer will be set as a default printer.

4- At the end of the script I would like that the user gets a popup msg box greeting the user by his/her first name depending on the time of the day ( lets say; if between 1 am till 11 am say good morning, and if the time is  between 11 am till 7 pm say good afternoon, otherwise say good evening.
The msgbox should also say you are logged in now. Example: good morning John, you are logged in now.  

As you see I have a part of the script (thanks to jared_luker from Experts Exchange) witch helps me to map the printers based on computer location. But I have a problem on how the fix the rest and get it all in one nice and clean login script.


Here are the codes I got from jared_luker:
Dim adsinfo,nw
Set adsinfo = CreateObject("adsysteminfo")
Set objNetwork = CreateObject("WScript.Network")
Set ThisComp = GetObject("LDAP://" & adsinfo.ComputerName)
Set oUser = GetObject("LDAP://" & adsinfo.UserName)
Select Case ThisComp.Location
      Case "Room1"
            objNetwork.AddWindowsPrinterConnection "\\server\room1_printer"
      Case "Room2"
            objNetwork.AddWindowsPrinterConnection "\\server\room2_printer"
      Case "Room3"
            objNetwork.AddWindowsPrinterConnection "\\server\room3_printer"
      Case "Room4"
            objNetwork.AddWindowsPrinterConnection "\\server\room4_printer"
      Case "Room5"
            objNetwork.AddWindowsPrinterConnection "\\server\room5_printer"
End Select
--------------------------------------------------------------------------------------------------------------------
 
Thank you
Regards
0
Comment
Question by:Tog_97
[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
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 21829789
Hi, try this script.

Regards,

Rob.
Set objNetwork = CreateObject("WScript.Network")
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")
 
arrDrives = Array( _
	"ALL~H:~\\server\user$\" & objNetwork.UserName &, _
	"ALL~G:~\\server\shareddata", _
	"ALL~P:~\\server\sharedprograms", _
	"FINANCE~T:~\\server\finance", _
	"ALL~W:~\\server\shareddata2" _
	)
 
For Each strDriveList In arrDrives
	strGroup = Split(strDriveList, "~")(0)
	strDriveLetter = Split(strDriveList, "~")(1)
	strDrivePath = Split(strDriveList, "~")(2)
	objNetwork.RemoveNetworkDrive strDriveLetter, True, True
	WScript.Sleep 1000
	If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroup) = True Then
		objNetwork.MapNetworkDrive strDriveLetter, strDrivePath, True
	End If
Next
 
arrPrintersToDisconnect = Array( _
	"\\server\printer1", _
	"\\server\printer2", _
	"\\server\printer3" _
	)
 
For Each strPrinter In arrPrintersToDisconnect
	objNetwork.RemovePrinterConnection strPrinter, True, True
Next
 
Set objADSysInfo = CreateObject("ADSystemInfo)
Set objComputer = GetObject("LDAP://" & objADSysInfo.ComputerName)
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
Select Case objComputer.Location
	Case "Room1"
		objNetwork.AddWindowsPrinterConnection "\\server\room1_printer"
	Case "Room2" 
		objNetwork.AddWindowsPrinterConnection "\\server\room2_printer"
	Case "Room3" 
		objNetwork.AddWindowsPrinterConnection "\\server\room3_printer"
	Case "Room4" 
		objNetwork.AddWindowsPrinterConnection "\\server\room4_printer"
	Case "Room5" 
		objNetwork.AddWindowsPrinterConnection "\\server\room5_printer"
End Select
 
strDefaultPrinter = "\\server\room3_printer"
On Error Resume Next
objNetwork.SetDefaultPrinter strDefaultPrinter
Err.Clear
On Error GoTo 0
 
If Hour(Now) >= 1 And Hour(Now) < 11 Then
	MsgBox "Good morning " & objUser.GivenName & ". You are now logged in."
ElseIf Hour(Now) >= 11 And Hour(Now) < 7 Then
	MsgBox "Good afternoon " & objUser.GivenName & ". You are now logged in."
Else
	MsgBox "Good evening " & objUser.GivenName & ". You are now logged in."
End If
 
Function IsMemberOfGroup(strUserDomain, objUser, strGroup) 'the user is a member of a specified group
	IsMemberOfGroup = False
	Dim objGroup
	If strGroup <> "ALL" Then
		On Error Resume Next
		Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
		If Err.Number Then
			IsMemberOfGroup = "Error"
		Else
			IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
			'MsgBox objUser.ADsPath
		End If
	Else
		IsMemberOfGroup = True
	End If
End Function

Open in new window

0
 

Author Comment

by:Tog_97
ID: 21830740
Hi Rob,
Thanks for the quick answer.
Just a few quastions:
forgive me but, I don´t understand the following:
----------------------------------------------------
strDefaultPrinter = "\\server\room3_printer"
On Error Resume Next
objNetwork.SetDefaultPrinter strDefaultPrinter
Err.Clear
On Error GoTo 0
----------------------------------
I was thinking like this the script will check for the location attribute of the computer and if the location is(lets say) room 3 the printer in room 3 will be installed and then it will set that printer as a default.
i just wonder how the script will set the printer  in room 4 as a default printer if the location is room
Another thing is:
If the script will install 2 or 3 printers. lets say if the location of the computer is room 1 the install the printer room 1 and the printer in room 2 and room 3 and set the printer in room 1 as a default printer.
One more thing:
Where dose the script checks if the user is a member of lets say FINANCE group , and if he/she is a member of this group the drive T: will be mapped?

Is it me who doesnt get the point here :).
As I said before I really not good at this, and thanks the guys like you i am trying to learn.

Thank in advaice
Regards,



0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21835860
Sorry mate, I was in a bit of a hurry, and didn't explain it....

To answer your first question, this bit:
strDefaultPrinter = "\\server\room3_printer"
On Error Resume Next
objNetwork.SetDefaultPrinter strDefaultPrinter
Err.Clear
On Error GoTo 0

will try to set \\server\room3_printer as the default printer, whether it is mapped or not, but now that I think about it, it won't really suit, because as you say, you might be in room 2.

If you want to it set a default printer based on the location, then this section:

Select Case objComputer.Location
      Case "Room1"
            objNetwork.AddWindowsPrinterConnection "\\server\room1_printer"
      Case "Room2"
            objNetwork.AddWindowsPrinterConnection "\\server\room2_printer"
      Case "Room3"
            objNetwork.AddWindowsPrinterConnection "\\server\room3_printer"
      Case "Room4"
            objNetwork.AddWindowsPrinterConnection "\\server\room4_printer"
      Case "Room5"
            objNetwork.AddWindowsPrinterConnection "\\server\room5_printer"
End Select


should just become this:

Select Case objComputer.Location
      Case "Room1"
            objNetwork.AddWindowsPrinterConnection "\\server\room1_printer"
            objNetwork.AddWindowsPrinterConnection "\\server\room1_printer2"
            objNetwork.SetDefaultPrinter "\\server\room1_printer"
      Case "Room2"
            objNetwork.AddWindowsPrinterConnection "\\server\room2_printer"
            objNetwork.AddWindowsPrinterConnection "\\server\room1_printer2"
            objNetwork.SetDefaultPrinter "\\server\room2_printer
      Case "Room3"
            objNetwork.AddWindowsPrinterConnection "\\server\room3_printer"
            objNetwork.AddWindowsPrinterConnection "\\server\room1_printer2"
            objNetwork.SetDefaultPrinter "\\server\room3_printer"
      Case "Room4"
            objNetwork.AddWindowsPrinterConnection "\\server\room4_printer"
            objNetwork.SetDefaultPrinter "\\server\room4_printer"
      Case "Room5"
            objNetwork.AddWindowsPrinterConnection "\\server\room5_printer"
            objNetwork.SetDefaultPrinter "\\server\room5_printer"
End Select


and then you can remove the first block....

Also, the part that checks for the group membership is this bit:

      If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroup) = True Then
            objNetwork.MapNetworkDrive strDriveLetter, strDrivePath, True
      End If

strGroup is taken as the first element of each line from the array
arrDrives = Array( _
      "ALL~H:~\\server\user$\" & objNetwork.UserName &, _
      "ALL~G:~\\server\shareddata", _
      "ALL~P:~\\server\sharedprograms", _
      "FINANCE~T:~\\server\finance", _
      "ALL~W:~\\server\shareddata2" _
      )

where if you define ALL it will map the drive for all users.  If you specify anything else, then it must match a security group name from your domain, and if the user matches, it will map the drive.

I hope that helps.

If you have any more questions, feel free to ask.

Regards,

Rob.
Set objNetwork = CreateObject("WScript.Network")
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")
 
arrDrives = Array( _
	"ALL~H:~\\server\user$\" & objNetwork.UserName &, _
	"ALL~G:~\\server\shareddata", _
	"ALL~P:~\\server\sharedprograms", _
	"FINANCE~T:~\\server\finance", _
	"ALL~W:~\\server\shareddata2" _
	)
 
For Each strDriveList In arrDrives
	strGroup = Split(strDriveList, "~")(0)
	strDriveLetter = Split(strDriveList, "~")(1)
	strDrivePath = Split(strDriveList, "~")(2)
	objNetwork.RemoveNetworkDrive strDriveLetter, True, True
	WScript.Sleep 1000
	If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroup) = True Then
		objNetwork.MapNetworkDrive strDriveLetter, strDrivePath, True
	End If
Next
 
arrPrintersToDisconnect = Array( _
	"\\server\printer1", _
	"\\server\printer2", _
	"\\server\printer3" _
	)
 
For Each strPrinter In arrPrintersToDisconnect
	objNetwork.RemovePrinterConnection strPrinter, True, True
Next
 
Set objADSysInfo = CreateObject("ADSystemInfo)
Set objComputer = GetObject("LDAP://" & objADSysInfo.ComputerName)
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
Select Case objComputer.Location
	Case "Room1"
		objNetwork.AddWindowsPrinterConnection "\\server\room1_printer"
		objNetwork.AddWindowsPrinterConnection "\\server\room1_printer2"
		objNetwork.SetDefaultPrinter "\\server\room1_printer"
	Case "Room2" 
		objNetwork.AddWindowsPrinterConnection "\\server\room2_printer"
		objNetwork.AddWindowsPrinterConnection "\\server\room1_printer2"
		objNetwork.SetDefaultPrinter "\\server\room2_printer
	Case "Room3" 
		objNetwork.AddWindowsPrinterConnection "\\server\room3_printer"
		objNetwork.AddWindowsPrinterConnection "\\server\room1_printer2"
		objNetwork.SetDefaultPrinter "\\server\room3_printer"
	Case "Room4" 
		objNetwork.AddWindowsPrinterConnection "\\server\room4_printer"
		objNetwork.SetDefaultPrinter "\\server\room4_printer"
	Case "Room5" 
		objNetwork.AddWindowsPrinterConnection "\\server\room5_printer"
		objNetwork.SetDefaultPrinter "\\server\room5_printer"
End Select
 
If Hour(Now) >= 1 And Hour(Now) < 11 Then
	MsgBox "Good morning " & objUser.GivenName & ". You are now logged in."
ElseIf Hour(Now) >= 11 And Hour(Now) < 7 Then
	MsgBox "Good afternoon " & objUser.GivenName & ". You are now logged in."
Else
	MsgBox "Good evening " & objUser.GivenName & ". You are now logged in."
End If
 
Function IsMemberOfGroup(strUserDomain, objUser, strGroup) 'the user is a member of a specified group
	IsMemberOfGroup = False
	Dim objGroup
	If strGroup <> "ALL" Then
		On Error Resume Next
		Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
		If Err.Number Then
			IsMemberOfGroup = "Error"
		Else
			IsMemberOfGroup = objGroup.IsMember(objUser.ADsPath)
			'MsgBox objUser.ADsPath
		End If
	Else
		IsMemberOfGroup = True
	End If
End Function

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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