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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logon scripts 3

Status
Not open for further replies.

qfkeon

Programmer
May 29, 2001
58
US
Is it possible to use an IF statement based on group membership to allocate drive mappings? I have multiple groups and currently the mapping is done from the workstations. I would like to have the mapping take place at logon since I have users with laptops who chronically lose mappings.
 
Why not just assign each group its own logon script? It works on my lan.
 
No need to assign each group a logon script, use vbscript to test group membership, a search on the net should bring up heaps of examples...if you have no luck repost and I will post an example.
 
Heres one I put together for a win2k box...:)

' Create WSH objects and populate with data from the Domain/AD
set wshNetwork = WScript.CreateObject("WScript.Network")
set wshShell = WScript.CreateObject("WScript.Shell")

' Wait for up to 30 seconds for the user-specific data to be located and loaded from Domain/AD
HurryUp = Timer + 30
Do
Wscript.Sleep 100 ' Check every 100mS
Loop until wshNetwork.username <> &quot;&quot; or HurryUp < Timer
If wshNetwork.username=&quot;&quot; then ProblemGettingDomainData

' Set some variables
User = wshNetwork.username
Domain = wshNetwork.userdomain
computer = wshNetwork.computername

' Determine the users Domain/AD Group membership
adspath=&quot;WinNT://&quot; & domain & &quot;/&quot; & user

' Create an object and populate it with user account properties from the Domain/AD
set adsobj = getobject(adspath)


' Map Drives based on Group Membership
' Users can belong to many groups. The group name for every group that the user belongs to is
' passed through a &quot;select case&quot; test. If the group name under test matches any &quot;case&quot; statement,
' then the line(s) under the &quot;case&quot; statement is actioned.

' The checkNetworkMapping(&quot;x:&quot;) is a function used to check if a drive is already mapped to the
' requested drive letter. It returns False if the letter is available.

' The mapNetwork subroutine will map a drive letter to a UNC path. If the path is invalid or
' unavailable, the routine will popup a warning message for 3 seconds then carry on.


for each prop in adsobj.groups ' Cycle through the user's group membership list

select case prop.name ' Pass the name of the group through the following filter

case &quot;groupname&quot; ' User is a member of this group so...
'if checkNetworkMapping(&quot;S:&quot;) = false then mapNetwork &quot;S:&quot;, &quot;\\servername\sharename&quot;

case &quot;printergroupname&quot; ' User is a member so map printer...
mapPrinter &quot;\\printservername\printsharename&quot;
defPrinter &quot;\\printservername\printsharename&quot;

end select ' Finish the filter test for this group name

next ' Loop around until every entry in the group membership list has been tested

' Sub Routines and Functions called by the master script

function checkNetworkMapping(Driveletter)
' See if the drive letter is already mapped
dim drive
checkNetworkMapping = false
for each Drive in wshNetwork.enumNetworkDrives
if LCase(Drive) = LCase(DriveLetter) then
CheckNetworkMapping = True ' Drive already mapped
Exit For
end if
next
end function

sub mapNetwork(driveletter, netshare)
' Map a drive
on error resume next ' If mapping fails then carry on
err.clear
wshNetwork.mapNetworkDrive driveletter, netshare, false
if err <> 0 then
' Drive mapping failed, display a popup message window for 2 seconds
ignore = WshShell.Popup(&quot;Error Mapping Drive &quot; + driveletter , 2, &quot;Company Name - New Zealand&quot;, 48)
end if
end sub

Sub mapPrinter(prnshare)
On Error Resume Next
err.clear
WshNetwork.AddWindowsPrinterConnection prnshare
if err <> 0 then
' printer share failed, display a popup message window for 2 seconds
ignore = WshShell.Popup(&quot;Printer &quot; + prnshare + &quot; already connected.&quot;, 2, &quot;Company Name - New Zealand&quot;, 48)
end if
End Sub

Sub defPrinter(pshare)
' On Error Resume Next
' err.clear
' WshNetwork.SetDefaultPrinter pshare
' if err <> 0 then
' ' printer share failed, display a popup message window for 2 seconds
' ignore = WshShell.Popup(&quot;Default printer already mapped &quot; + pshare , 2, &quot;Company Name - New Zealand&quot;, 48)
' end if
End Sub

sub ProblemGettingDomainData
' Couldn't get the Domain/AD data within 30 seconds
wscript.Echo &quot;Failed to access Domain/AD account data&quot;
Wscript.Quit ' Quit
end sub
 
Thsnk you for the example. It was fun to read through. I haven't had a chance to work in VB for about a year. I will try to implement something similar.
 
Take a look at this:

thread82-211317

Its something I did for someone wanting to start a logon script in NT4. Should hopefully work in 2000.

Let me know if it does...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top