•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,423 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,595 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 4308 | Replies: 0
![]() |
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I have a vbs script that is suppossed to look into AD and find any security group that follows the the format [map {drive letter} to {share name} on {server name}] and map a network drive for users that are a member. This is running in a Windows 2003 AD mixed-mode. It is not doing anything. The AD structure is:
Domain > Site > Policy Groups > Map E to share on server.
Here is the script:
'========================================================================== ====
'
'Drive mapping instructions:
'
' 1. The four default drives that need to be mapped for each user are:
'
' G: - Group public shares
' H: - User's home directory
' I: - User's Group's directory
' X: - Application directory
'
' 2. These four drives are mapped by a logon script - mapshare.vbs
'
' 3. The mapshare.vbs script reads the group membership of the
' logged on user. For each group:
'
' a) If a group is a Windows 2000 built-in group (Domain Admins,
' for example), the script does nothing.
'
' b) If a group is a GPO group (GPO groups begin with one of the
' following prefixes: cs-, cw-, ca-, us-, uw-, ua-), the
' script does nothing.
'
' c) If the group name takes the following form:
'
' map {drive letter} to {share name} on {server name}
'
' then the script attempts to map the appropriate resource.
' Note that the program recognizes only four variables for share
' names: %USERNAME%, %username%, %USERNAME%$, and %username%$
' and that combinations of upper and lower case do not work.
'
' d) If the group does not fall into one of the above categories,
' the script assumes that the group name is the name of a share
' on the user's home server and attempts to map the H: drive to
' this share. IF THE USER BELONGS TO MORE THAN ONE SUCH GROUP,
' THE SCRIPT HAS NO WAY OF DETERMINING WHICH GROUP IS CORRECT.
'
' 4. The mapshare.vbs script is itself run by a GPO:
'
' UC-WS-SC-Logon Script (mapshare.vbs)
'
' would be a GPO with the property:
'
' User Configuration | Windows Settings | Scripts (Logon/Logoff) | Logon
'
' set to:
'
' mapshare.vbs
'
'========================================================================== ====
Option Explicit
Dim g_oGroupDict
Dim g_oNet
Dim sAdsPath
Dim oUser
Dim oGroup
Dim sGroupName
Dim sOurDrive(23)
Dim iPosition
Dim sOurShare(23)
Dim sOurServer(23)
Dim iIndex
Dim iCount
iIndex = 0
iCount = 0
sGroupName = ""
On Error Resume Next
Set g_oNet = CreateObject("Wscript.Network")
If IsEmpty(g_oGroupDict) Then
Set g_oGroupDict = CreateObject("Scripting.Dictionary")
g_oGroupDict.CompareMode = vbTextCompare
sAdsPath = g_oNet.UserDomain & "/" & g_oNet.UserName
Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
For Each oGroup In oUser.Groups
If (Left(oGroup.Name, 3) = "map") Then
sOurDrive(iIndex) = Mid(oGroup.Name, 5, 1) + ":"
iPosition = InStr(1, oGroup.Name, " on ", vbTextCompare)
sOurShare(iIndex) = Mid(oGroup.Name, 10, iPosition - 10)
sOurServer(iIndex) = Right(oGroup.Name, Len(oGroup.Name) - (iPosition + 3))
g_oNet.RemoveNetworkDrive sOurDrive, True, True
iIndex = iIndex + 1
ElseIf ((oGroup.Name <> "Administrators") And (oGroup.Name <> "Domain Users") And (Left(oGroup.Name, 2) <> "cs") And (Left(oGroup.Name, 2) <> "cw") And (Left(oGroup.Name, 2) <> "ca") And (Left(oGroup.Name, 2) <> "us") And (Left(oGroup.Name, 2) <> "uw") And (Left(oGroup.Name, 2) <> "ua")) Then
sGroupName = oGroup.Name
End If
Next
For iCount = 0 To (iIndex - 1)
If sOurShare(iCount) = "%USERNAME%$" Or sOurShare(iCount) = "%username%$" Then sOurShare(iCount) = oUser.Name & "$"
If sOurShare(iCount) = "%USERNAME%" Or sOurShare(iCount) = "%username%" Then sOurShare(iCount) = oUser.Name
If sOurShare(iCount) = "Group Share" Or sOurShare(iCount) = "group share" Then sOurShare(iCount) = sGroupName
g_oNet.RemoveNetworkDrive sOurDrive(iCount), True, True
g_oNet.MapNetworkDrive sOurDrive(iCount), "\\" & sOurServer(iCount) & "\" & sOurShare(iCount)
Next
End If
Domain > Site > Policy Groups > Map E to share on server.
Here is the script:
'========================================================================== ====
'
'Drive mapping instructions:
'
' 1. The four default drives that need to be mapped for each user are:
'
' G: - Group public shares
' H: - User's home directory
' I: - User's Group's directory
' X: - Application directory
'
' 2. These four drives are mapped by a logon script - mapshare.vbs
'
' 3. The mapshare.vbs script reads the group membership of the
' logged on user. For each group:
'
' a) If a group is a Windows 2000 built-in group (Domain Admins,
' for example), the script does nothing.
'
' b) If a group is a GPO group (GPO groups begin with one of the
' following prefixes: cs-, cw-, ca-, us-, uw-, ua-), the
' script does nothing.
'
' c) If the group name takes the following form:
'
' map {drive letter} to {share name} on {server name}
'
' then the script attempts to map the appropriate resource.
' Note that the program recognizes only four variables for share
' names: %USERNAME%, %username%, %USERNAME%$, and %username%$
' and that combinations of upper and lower case do not work.
'
' d) If the group does not fall into one of the above categories,
' the script assumes that the group name is the name of a share
' on the user's home server and attempts to map the H: drive to
' this share. IF THE USER BELONGS TO MORE THAN ONE SUCH GROUP,
' THE SCRIPT HAS NO WAY OF DETERMINING WHICH GROUP IS CORRECT.
'
' 4. The mapshare.vbs script is itself run by a GPO:
'
' UC-WS-SC-Logon Script (mapshare.vbs)
'
' would be a GPO with the property:
'
' User Configuration | Windows Settings | Scripts (Logon/Logoff) | Logon
'
' set to:
'
' mapshare.vbs
'
'========================================================================== ====
Option Explicit
Dim g_oGroupDict
Dim g_oNet
Dim sAdsPath
Dim oUser
Dim oGroup
Dim sGroupName
Dim sOurDrive(23)
Dim iPosition
Dim sOurShare(23)
Dim sOurServer(23)
Dim iIndex
Dim iCount
iIndex = 0
iCount = 0
sGroupName = ""
On Error Resume Next
Set g_oNet = CreateObject("Wscript.Network")
If IsEmpty(g_oGroupDict) Then
Set g_oGroupDict = CreateObject("Scripting.Dictionary")
g_oGroupDict.CompareMode = vbTextCompare
sAdsPath = g_oNet.UserDomain & "/" & g_oNet.UserName
Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
For Each oGroup In oUser.Groups
If (Left(oGroup.Name, 3) = "map") Then
sOurDrive(iIndex) = Mid(oGroup.Name, 5, 1) + ":"
iPosition = InStr(1, oGroup.Name, " on ", vbTextCompare)
sOurShare(iIndex) = Mid(oGroup.Name, 10, iPosition - 10)
sOurServer(iIndex) = Right(oGroup.Name, Len(oGroup.Name) - (iPosition + 3))
g_oNet.RemoveNetworkDrive sOurDrive, True, True
iIndex = iIndex + 1
ElseIf ((oGroup.Name <> "Administrators") And (oGroup.Name <> "Domain Users") And (Left(oGroup.Name, 2) <> "cs") And (Left(oGroup.Name, 2) <> "cw") And (Left(oGroup.Name, 2) <> "ca") And (Left(oGroup.Name, 2) <> "us") And (Left(oGroup.Name, 2) <> "uw") And (Left(oGroup.Name, 2) <> "ua")) Then
sGroupName = oGroup.Name
End If
Next
For iCount = 0 To (iIndex - 1)
If sOurShare(iCount) = "%USERNAME%$" Or sOurShare(iCount) = "%username%$" Then sOurShare(iCount) = oUser.Name & "$"
If sOurShare(iCount) = "%USERNAME%" Or sOurShare(iCount) = "%username%" Then sOurShare(iCount) = oUser.Name
If sOurShare(iCount) = "Group Share" Or sOurShare(iCount) = "group share" Then sOurShare(iCount) = sGroupName
g_oNet.RemoveNetworkDrive sOurDrive(iCount), True, True
g_oNet.MapNetworkDrive sOurDrive(iCount), "\\" & sOurServer(iCount) & "\" & sOurShare(iCount)
Next
End If
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- How do I detect available drives in a Delphi program? (Pascal and Delphi)
- Map Drive from Windows XP to Windows Server 2003 (Networking Hardware Configuration)
- Editing Registry with VBS (Visual Basic 4 / 5 / 6)
- Windows Scheduled Tasks weirdness (Windows NT / 2000 / XP / 2003)
- Please help with a script (Visual Basic 4 / 5 / 6)
- Computer extremely slow - can you please help tell me what's wrong? (Viruses, Spyware and other Nasties)
- Please help: Going Doolally (Viruses, Spyware and other Nasties)
- Add a Map Drive Button to the Toolbar (Windows tips 'n' tweaks)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB Macro
- Next Thread: Drawing curves with Picbox.Line


Linear Mode