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

problem with logon script? Can you see whats wrong? 1

Status
Not open for further replies.

1nterpol

IS-IT--Management
Apr 2, 2007
78
IE
im trying to map some drives, using some error control.i know the script is running as i get the message but nothing is mapping..there's a few extra variables there that aren't being used, i had to cut out other code to try narrow down the problem

Option Explicit
Dim ObjNetwork, objShell, groupListD, ADSPath, userPath, listGroup
Dim strComputer, netPrinter, UNCPath, oWMI, colItems, objItem
WScript.Echo "Welcome to the so and so's Domain"
sub MapDrive(byval driveLetter, byval uncPath)
on error resume next
set objNetwork = createobject("Wscript.Network")
objNetwork.MapNetworkDrive driveLetter, uncPath

if err.number = -2147024811 then '
err.clear
driveletter = getNextDrive
if driveLetter <> "" then
MapDrive driveLetter, uncPath
end if

elseif err.number <> 0 then '


end if
end sub


function getNextDrive
set objFSO = createobject("Scripting.FileSystemObject")

for i = 68 to 88 '** Start at ASCI number 68 (D)
drive = chr(i) & ":"
if not objFSO.DriveExists(drive) then
getNextDrive = drive
exit function
end if
next


end function
Function EnvString(variable)
variable = "%" & variable & "%"
EnvString = objShell.ExpandEnvironmentStrings(variable)
End Function
Function IsMember(groupName)
If IsEmpty(groupListD) then
Set groupListD = CreateObject("Scripting.Dictionary")
groupListD.CompareMode = 1
ADSPath = EnvString("userdomain") & "/" & EnvString("username")
Set userPath = GetObject("WinNT://" & ADSPath & ",user")
For Each listGroup in userPath.Groups
groupListD.Add listGroup.Name, "-"
Next
End if
IsMember = CBool(groupListD.Exists(groupName))
End Function
set objNetwork = WSCript.CreateObject("WScript.Network")
set objShell = WScript.CreateObject( "WScript.Shell")
If isMember("dlTempStaff") Then
MapDrive "H:", "\\WIN-3LRLLX93J1B\TempStaffShare"
Else
End If
If isMember("dlMarketing") Then
MapDrive "H:", "\\WIN-3LRLLX93J1B\MarketingShare"

Else
End If
If isMember("dlSales") Then
MapDrive "H:", "\\\\WIN-3LRLLX93J1B\SalesShare"

Else
End If
If isMember("dlManagers") Then
MapDrive "W:", "\\WIN-3LRLLX93J1B\ManagersShare"
MapDrive "X:", "\\WIN-3LRLLX93J1B\TempStaff"
MapDrive "\\WIN-3LRLLX93J1B\MarketingShare"
MapDrive "Z:", "\\WIN-3LRLLX93J1B\SalesShare"
Else

End If


 
Hi Interpol,

Here's a quick & dirty simple script to map the network drive to UNC path. You can base yourself that.

Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath
strDriveLetter = "J:"
strRemotePath = "\\alan\home"

' Purpose of script to create a network object. (objNetwork)
' Then to apply the MapNetworkDrive method. Result J: drive
Set objNetwork = CreateObject("WScript.Network")

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
WScript.Quit

' End of Example VBScript.

Pre-requisites.

1. On Line 10 change the server name from '\\alan' to your server name.
2. Make sure that your server has a share called '\home'.

Instructions to MapNetworkDrive

1. Copy and paste the script below into notepad.
2. Check strPath, your server is unlikely to be called "\\alan, so amend to the name of your server. :)
3. Save the file with .vbs extension e.g. MapNetworkDrive.vbs.
4. Double click your script and check in your Windows Explorer for a new drive called : home on 'alan' (J:)


Let me know if that helps you.


Thanks,
FOXUP!!
 
hey thanks, what about if i want to map a drive depending on what group they are in?
 
im going to try edit this, look okay to you?


On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName
Case "Finance Users"
objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\finance"

Case "Human Resource Users"
objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\hr"

Case "Manufacturing Users"
objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\manufacturing"

Case "Shipping and Receiving Users"
objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\shipping"
End Select
Next
 
Hey,

This should help you:


'start script

On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

'find user name

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

'find user group's

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

' if user member of a group then map network drive

Select Case strGroupName
Case "GROUP NAME 1"
objNetwork.MapNetworkDrive "DRIVE LETTER:", "NETWORK PATH"

Case "GROUP NAME 2"
objNetwork.MapNetworkDrive "DRIVE LETTER:", "NETWORK PATH"

Case "GROUP NAME 3"
objNetwork.MapNetworkDrive "DRIVE LETTER:", "NETWORK PATH"
'
End Select
Next

'end script


Let me know how it works out.


Thanks,
FOXUP!
 
sorry for not getting back to you I was very busy, thats a great help thanks very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top