Discussion Locked

VB script?

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Problems with log on:
As member of Dossiers it maps rhe drive.
As member of Directie or JZ it maps the drive and gives error: the local device name is already in use.???
Script runs in a policy as startup script in part user configuration.

'Sript can be set up to map network drives
'and printers using the IsMember("Group Name")
'function to determine group membership. Script
'will also map drives and printers using the
'MapDrive() and MapPrinter() functions alone.
'-----------------
'declare global variables here
Option Explicit

Dim oShell, oNet, oFSO, oWshNetwork, oGroupDict

'-----------------
'Objects go here

Set oShell = CreateObject("Wscript.Shell")
Set oNet = CreateObject("Wscript.Network")
set oFSO = CreateObject("Scripting.FileSystemObject")

'----------------------------------------------------
'all mapping and stuff is done from'here
'you should not have to change functions
'unless they do not work for some'reason

'Greeting()

If IsMember("Directie") Then
MapDrive "I:", "\\NFLSVR01", "\DIRECTIE$"
End If

If IsMember("JZ") Then
MapDrive "J:", "\\NFLSVR01", "\JUZA$"
End If

If IsMember("Dossiers") Then
MapDrive "K:", "\\NFLSVR01", "\DOSSIERS$"
End If

'this is the end of the function calls
'----------------------------------------
'display greeting to the user
Function Greeting()
Dim sTime, sDate, sMessage, sAdsPath, GreetingTime, oUser

sTime = Hour(Now)
sDate = Now

If sTime <= 11 Then
GreetingTime = "Morgen"
ElseIf sTime <= 18 Then
GreetingTime = "Middag"
Else
GreetingTime = "Avond"
End If sMessage = VbCrLf & sDate & VbCrLf & VbCrLf
sMessage = sMessage & "Goede " & GreetingTime & " " & oNet.UserName & ","
sMessage = sMessage & VbCrLf
Wscript.Echo(sM

7 replies

by luc geurts

Rest of the script:

Wscript.Echo(sMessage)

End Function

'-----------------
'find out what groups the user belongs too
Function IsMember(sGroup)
Dim sAdsPath, oUser, oGroup

If IsEmpty(oGroupDict) Then
Set oGroupDict = CreateObject("Scripting.Dictionary")
oGroupDict.CompareMode = vbTextCompare

sAdsPath = oNet.UserDomain & "/" & oNet.UserName
Set oUser = GetObject("WinNT://" & sAdsPath & ",user")

For Each oGroup In oUser.Groups
oGroupDict.Add oGroup.Name, "-"
Next

Set oUser = Nothing
End If

IsMember = CBool(oGroupDict.Exists(sGroup))

End Function

'-----------------
'map the drives
Function MapDrive(Drive, FileServer, Share)

If oFSO.DriveExists(FileServer & Share) = True Then
oNet.MapNetworkDrive Drive, FileServer & Share
Wscript.Echo("Mapping drive " & Drive & " to " & FileServer & Share)
Else
Wscript.Echo("Cannot Map " & Drive & " to " & FileServer & Share)
End If

End Function

by nikki96

Quite possibly, you are attempting to map twice. From what I see, the user can belong to more than one group.
Nest those IFs.
Put them in order of importance.

If IsMember("Directie") Then
MapDrive "I:", "\\NFLSVR01", "\DIRECTIE$"
Else If IsMember("JZ") Then
MapDrive "J:", "\\NFLSVR01", "\JUZA$"
Else If IsMember("Dossiers") Then
MapDrive "K:", "\\NFLSVR01", "\DOSSIERS$"
End If

There is no need to map the same drive to more than one letter, so I assume you want only one mapping.

by luc geurts

You were right about 2 times a mapping. I already found the solution myself, by running gpresult and drinking 2 liters coffee. Thanks anyway for helping out and live long and prosper.

This discussion is closed to new replies.