Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login Script help Please? 2

Status
Not open for further replies.

thelke

MIS
Apr 9, 2002
84
0
0
I need some help with mapping Shares and Printers based on NT4 Domain Groups.

I have Win2k Clients, and would like to consoldate my login scripts to 1, where I can map shares and printers based on domain groups. I have the mapping of shares down, but cannot get it to base them on groups, and I cannot get the mapping of the printers down at all. I attempted to re-write what I used for mapping shares, and use it for printers, but to no avail.

Any help would be great!

Here is some sample code of what I tried...

dim OlyNet
dim OlyPrinter
dim OlyFSO
dim OlyShell
dim OlyDrives
dim i
dim cmd

on error resume next

set OlyNet = WScript.CreateObject("WScript.Network")
set OlyPrinters = WScript.CreateObject("WScript.Shell")
Set OlyFSO = WScript.CreateObject("Scripting.FileSystemObject")
set OlyShell = CreateObject("WScript.Shell")
set OlyDrives = OlyNet.EnumNetworkDrives

'----- Set Drive Mappings (This clears any existing mappings)

DriveMapping "I:", ""
DriveMapping "J:", ""
DriveMapping "K:", ""
DriveMapping "L:", ""
DriveMapping "M:", ""
DriveMapping "N:", ""
DriveMapping "O:", ""
DriveMapping "P:", ""
DriveMapping "Q:", ""
DriveMapping "R:", ""
DriveMapping "S:", ""
DriveMapping "T:", ""
DriveMapping "U:", ""
DriveMapping "V:", ""
DriveMapping "W:", ""
DriveMapping "X:", ""
DriveMapping "Y:", ""
DriveMapping "Z:", ""

If INGROUP(&quot;<Domain>\Accounting&quot;)Then
DriveMapping &quot;<Drive>&quot;, &quot;<Share>&quot;

End If


If INGROUP(&quot;<Domain>\Domain Sales&quot;)Then
DriveMapping &quot;<Drive>&quot;, &quot;<Share>&quot;

End If

Sub DriveMapping(Drive, Share)
For i = 0 to OlyDrives.Count -1 Step 2
if LCase(Drive) = LCase(OlyDrives.Item(i)) then
if not LCase(Share) = LCase(OlyDrives.Item(i+1)) then
OlyNet.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next

OlyNet.MapNetworkDrive Drive, Share
End Sub

'-----Set Printer Mappings

If INGROUP(&quot;<Domain>\Accounting&quot;)Then
PrinterMapping &quot;<Share>&quot;
End If

If INGROUP(&quot;<Domain>\Sales&quot;)Then
PrinterMapping &quot;<Share>&quot;
End If

Sub PrinterMapping(Share)
For i = 0 to OlyPrinter.Count -1 Step 2
if LCase(Share) = LCase(OlyPrinter.Item(i+1)) then
Exit Sub
End if
Next

OlyPrinter.Run Share
End Sub
 
Where is the code for the InGroup function?

Jon Hawkins
 
umm... I dont have it? hehe. I am still new to VBScript, and have been piecing things together found on the net to work. but I am sick of writing scripts for each group. I would raterh have 1 script, and as things are needed for the group, I add them to the script.

so how would I re-write this so I could have shares and printers based on group membership?
 
Ok, I'm confused. All I'm trying to do is to create a logon script to map drives based on Group Membership. I don't get any errors, but my test user keeps mapping the same drive. I've used the script in this thread and added the Ingroup function. Do you have a sample script that does just this and only this?
 
Ok, programmers, here's what I have. I want to map drives based on group membership. Anyone know what I'm doing wrong? I know next to nothing about vbs scripting!

Dim oGroup
Dim oMemb
Dim aTemp
dim OlyNet
dim OlyPrinter
dim OlyFSO
dim OlyShell
dim OlyDrives
dim i
dim cmd

on error resume next

set OlyNet = WScript.CreateObject(&quot;WScript.Network&quot;)
set OlyPrinters = WScript.CreateObject(&quot;WScript.Shell&quot;)
Set OlyFSO = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
set OlyShell = CreateObject(&quot;WScript.Shell&quot;)
set OlyDrives = OlyNet.EnumNetworkDrives

'----- Set Drive Mappings (This clears any existing mappings)

DriveMapping &quot;G:&quot;, &quot;&quot;
DriveMapping &quot;H:&quot;, &quot;&quot;
DriveMapping &quot;I:&quot;, &quot;&quot;
DriveMapping &quot;J:&quot;, &quot;&quot;
DriveMapping &quot;K:&quot;, &quot;&quot;
DriveMapping &quot;L:&quot;, &quot;&quot;
DriveMapping &quot;M:&quot;, &quot;&quot;
DriveMapping &quot;N:&quot;, &quot;&quot;
DriveMapping &quot;O:&quot;, &quot;&quot;
DriveMapping &quot;P:&quot;, &quot;&quot;
DriveMapping &quot;Q:&quot;, &quot;&quot;
DriveMapping &quot;R:&quot;, &quot;&quot;
DriveMapping &quot;S:&quot;, &quot;&quot;
DriveMapping &quot;T:&quot;, &quot;&quot;
DriveMapping &quot;U:&quot;, &quot;&quot;
DriveMapping &quot;V:&quot;, &quot;&quot;
DriveMapping &quot;W:&quot;, &quot;&quot;
DriveMapping &quot;X:&quot;, &quot;&quot;
DriveMapping &quot;Y:&quot;, &quot;&quot;
DriveMapping &quot;Z:&quot;, &quot;&quot;

If oGroup(&quot;gilroy_domain\training&quot;)Then
DriveMapping &quot;X:&quot;, &quot;\\policesrvr\ITS1$&quot;
End If


If oGroup(&quot;gilroy_domain\cso&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If

If oGroup(&quot;gilroy_domain\dispatch&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If

If oGroup(&quot;gilroy_domain\crimepr&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
'PrinterMapping &quot;\\policesrvr\printer&quot;
End If

If oGroup(&quot;gilroy_domain\ca&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If

If oGroup(&quot;gilroy_domain\admn&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If

If oGroup(&quot;gilroy_domain\admn&quot;)Then
DriveMapping &quot;P:&quot;, &quot;\\policesrvr\sys$&quot;
End If

If oGroup(&quot;gilroy_domain\corporal&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If


If oGroup(&quot;gilroy_domain\records&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If


If oGroup(&quot;gilroy_domain\gang_pdox&quot;)Then
DriveMapping &quot;P:&quot;, &quot;\\policesrvr\gangdata$&quot;
End If


If oGroup(&quot;gilroy_domain\super&quot;)Then
DriveMapping &quot;H:&quot;, &quot;\\policesrvr\depts$&quot;
End If


If oGroup(&quot;gilroy_domain\mso&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If


If oGroup(&quot;gilroy_domain\officers&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If


If oGroup(&quot;gilroy_domain\everyone&quot;)Then
DriveMapping &quot;G:&quot;, &quot;\\policesrvr\depts$&quot;
End If


Function IsMember(domain, group, user)
IsMember = False
Set oGroup = GetObject(&quot;WinNT://&quot; & domain & &quot;/&quot; & group & &quot;,group&quot;)
If oGroup.IsMember(&quot;WinNT://&quot; & domain & &quot;/&quot; & user) Then
IsMember = True
ExitFunction
End If
For Each oMemb In oGroup.Members
If oMemb.Class = &quot;Group&quot; Then
aTemp = Split(oMemb.ADsPath, &quot;/&quot;)
IsMember = IsMember(aTemp(2), aTemp(3), user)
If IsMember Then Exit For
End If
Next
End Function


Sub DriveMapping(Drive, Share)
For i = 0 to OlyDrives.Count -1 Step 2
if LCase(Drive) = LCase(OlyDrives.Item(i)) then
if not LCase(Share) = LCase(OlyDrives.Item(i+1)) then
OlyNet.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next
OlyNet.MapNetworkDrive Drive, Share
End Sub
 
I cannot make that work. It maps all of the drives in the list, and does not differentiate between groups.
 
Ok, I have a work-around anyway. I created separate OU's for each of my groups. Each OU gets a logon scripts and my users are happy. A little bit more work up front, but easy to maintain. No huge logon script to debug when there's a change! Appreciate the look though. YOu're thread has been very helpful to me.
 
First, an insight why the above did not produce the results you desire. At the beginning of your script, you included On Error Resume Next, which informs the script to continue with the next statement regardless if the current produces an error. When the line If oGroup(&quot;.....&quot;) was executed, an error was thrown because there is no oGroup function defined; however, since you had directed the script to continue, all DriveMapping commands were executed.

A simplified example using the IsMember function posted above,

Code:
Set OlyNet = WScript.CreateObject(&quot;WScript.Network&quot;)

If IsMember(&quot;gilroy_domain&quot;,&quot;mso&quot;,OlyNet.UserName) Then x=y

Jon Hawkins
 
You have already solved this issue, but the problem was the &quot;If oGroup()&quot; statements. oGroup is not defined until you enter the IsMember function. Should have been &quot;If IsMember()&quot; with appropriate parameters.

You can find lots of examples to learn from here...
 
I would suggest avoiding the need to always change your login scripts when you want to add a new drive mapping or a printer mapping are any other thing for that matter.

why not have an ini file which contains something like

[MapDrives]
EnabledLocal=1
EnabledRemote=1
LoggingRemote=none
LoggingLocal=eventlogonly
FSC-NOW-BaseInstall=\\groups\stuff& Persistent;Disconnect
SalesGroup=groups stuff&Persistent;NoDisconnect
MCH_FSC_ECRM=F:\\mchrd05a\area1\%UserName%& Persistent;Disconnect
hjjs=H:\\mchsales\datagroup\sales&Persistent;NoDisconnect

that way you never touch your perfectly working script but just add a line to the ini file.
you can have ini files for sites, groups, users with user ini files being the highest priority etc

rich
 
Ok guys, I'm sorry to be a pain, BUT I need one more line. I'm trying to do a DriveMapping to a username variable. I can't figure this out. I'm under the gun. I need this working by noon today (5/14/2003) Can someone debug this script and look at my I: mapping?

im OlyNet
dim OlyPrinter
dim OlyFSO
dim OlyShell
dim OlyDrives
dim i
dim cmd

on error resume next

set OlyNet = WScript.CreateObject(&quot;WScript.Network&quot;)
set OlyPrinters = WScript.CreateObject(&quot;WScript.Shell&quot;)
Set OlyFSO = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
set OlyShell = CreateObject(&quot;WScript.Shell&quot;)
set OlyDrives = OlyNet.EnumNetworkDrives
set username = shell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;)


'----- Set Drive Mappings (This clears any existing mappings)

DriveMapping &quot;F:&quot;, &quot;&quot;
DriveMapping &quot;G:&quot;, &quot;&quot;
DriveMapping &quot;H:&quot;, &quot;&quot;
DriveMapping &quot;I:&quot;, &quot;&quot;
DriveMapping &quot;J:&quot;, &quot;&quot;
DriveMapping &quot;K:&quot;, &quot;&quot;
DriveMapping &quot;L:&quot;, &quot;&quot;
DriveMapping &quot;M:&quot;, &quot;&quot;
DriveMapping &quot;N:&quot;, &quot;&quot;
DriveMapping &quot;O:&quot;, &quot;&quot;
DriveMapping &quot;P:&quot;, &quot;&quot;
DriveMapping &quot;T:&quot;, &quot;&quot;
DriveMapping &quot;U:&quot;, &quot;&quot;
DriveMapping &quot;V:&quot;, &quot;&quot;
DriveMapping &quot;W:&quot;, &quot;&quot;
DriveMapping &quot;X:&quot;, &quot;&quot;
DriveMapping &quot;Y:&quot;, &quot;&quot;
DriveMapping &quot;Z:&quot;, &quot;&quot;

DriveMapping &quot;G:&quot;, &quot;\\firerms\depts$&quot;
DriveMapping &quot;I:&quot;, &quot;\\firerms\&quot; & username & &quot;$&quot;
DriveMapping &quot;O:&quot;, &quot;\\cityhallsrvr\cityinfo$&quot;
DriveMapping &quot;P:&quot;, &quot;\\firerms\apps$&quot;


Sub DriveMapping(Drive, Share)
For i = 0 to OlyDrives.Count -1 Step 2
if LCase(Drive) = LCase(OlyDrives.Item(i)) then
if not LCase(Share) = LCase(OlyDrives.Item(i+1)) then
OlyNet.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next
OlyNet.MapNetworkDrive Drive, Share
End Sub
 
Change

set username = shell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;)

to

username = OlyShell.ExpandEnvironmentStrings(&quot;%USERNAME%&quot;)

FWIW, if any of your clients are not NT/2K/XP, you will want to retrieve the username from the wshNetwork object, instead of the environment variable because username is not a default environment variable on 9x systems.

username = OlyNet.UserName

Jon Hawkins
 
Thanks!

Here's what I ended up with and it works. I don't know if there are any unnecessary lines. I also don't know if this will map groups, but one thing at a time.

dim strUserName
dim OlyNet
dim OlyPrinter
dim OlyFSO
dim OlyShell
dim OlyDrives
dim i
dim cmd
dim WSHNetwork


on error resume next


set WSHNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)
set OlyNet = WScript.CreateObject(&quot;WScript.Network&quot;)
set OlyPrinters = WScript.CreateObject(&quot;WScript.Shell&quot;)
Set OlyFSO = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
set OlyShell = CreateObject(&quot;WScript.Shell&quot;)
set OlyDrives = OlyNet.EnumNetworkDrives

While strUserName = &quot;&quot;
strUserName = WSHNetwork.UserName
Wend


'----- Set Drive Mappings (This clears any existing mappings)

DriveMapping &quot;F:&quot;, &quot;&quot;
DriveMapping &quot;G:&quot;, &quot;&quot;
DriveMapping &quot;H:&quot;, &quot;&quot;
DriveMapping &quot;I:&quot;, &quot;&quot;
DriveMapping &quot;J:&quot;, &quot;&quot;
DriveMapping &quot;K:&quot;, &quot;&quot;
DriveMapping &quot;L:&quot;, &quot;&quot;
DriveMapping &quot;M:&quot;, &quot;&quot;
DriveMapping &quot;N:&quot;, &quot;&quot;
DriveMapping &quot;O:&quot;, &quot;&quot;
DriveMapping &quot;P:&quot;, &quot;&quot;
DriveMapping &quot;T:&quot;, &quot;&quot;
DriveMapping &quot;U:&quot;, &quot;&quot;
DriveMapping &quot;V:&quot;, &quot;&quot;
DriveMapping &quot;W:&quot;, &quot;&quot;
DriveMapping &quot;X:&quot;, &quot;&quot;
DriveMapping &quot;Y:&quot;, &quot;&quot;
DriveMapping &quot;Z:&quot;, &quot;&quot;

WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\firerms\depts$&quot;
WSHNetwork.MapNetworkDrive &quot;I:&quot;, &quot;\\firerms\&quot; + strUserName + &quot;$&quot;
WSHNetwork.MapNetworkDrive &quot;O:&quot;, &quot;\\cityhallsrvr\cityinfo$&quot;
WSHNetwork.MapNetworkDrive &quot;P:&quot;, &quot;\\firerms\apps$&quot;


Sub DriveMapping(Drive, Share)
For i = 0 to OlyDrives.Count -1 Step 2
if LCase(Drive) = LCase(OlyDrives.Item(i)) then
if not LCase(Share) = LCase(OlyDrives.Item(i+1)) then
OlyNet.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next
OlyNet.MapNetworkDrive Drive, Share
End Sub
 
Here's another script...
'

Can anyone see anything wrong with it. It's doing nothing at the moment.


On Error Resume Next
Dim strUserName
Dim GroupObj
Dim UserObj
Dim UserGroups
Dim WSHNetwork
Set WSHNetwork = WScript.CreateObject(&quot;WScript.Network&quot;)

While strUserName = &quot;&quot;
strUserName = WSHNetwork.UserName
Wend

' maps a letter to hidden share based on user name
WSHNetwork.MapNetworkDrive &quot;I:&quot;, &quot;\\police_srvr\&quot; + strUserName + &quot;$&quot;

'*****************************************************************
'************* Map drive for DATA Directory ********************
'*****************************************************************
WSHNetwork.MapNetworkDrive &quot;R:&quot;, &quot;\\sql_apps_srvr\data&quot;

'*****************************************************************
'************* Map drive for Specific Groups! *****************
'*****************************************************************


'Get User Object
Set UserObj = GetObject(&quot;WinNT://local.ci.gilroy.ca.us/&quot; & strUserName)

UserGroups=&quot;&quot;
For Each GroupObj In UserObj.Groups
UserGroups=UserGroups & &quot;[&quot; & GroupObj.Name & &quot;]&quot;
Next

UserGroups = Ucase(UserGroups)

'************* Map J: drive for ECS members OR Shams users *****************
'Check if member of group
Select Case true
case InStr(UserGroups,&quot;[&quot; & &quot;SARGENTS&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;CSO&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;dispatch&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;ADMN&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;
WSHNetwork.MapNetworkDrive &quot;P:&quot;, &quot;\\city_hall_srvr\sys$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;CRIMEPR&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;CA&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;CORPORAL&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;RECORDS&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;GANG_PDOX&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;P:&quot;, &quot;\\police_srvr\gangdata$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;super&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;H:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;sUPER&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

case InStr(UserGroups,&quot;[&quot; & &quot;OFFICERS&quot; & &quot;]&quot;) > 0
WSHNetwork.MapNetworkDrive &quot;G:&quot;, &quot;\\police_srvr\depts$&quot;

End Select

'WSHNetwork.RemoveNetworkDrive &quot;j:&quot; ' will remove mapped drive

'etc etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top