Jump to content

VBScript - Logon Script help


Recommended Posts

I am trying to make a logon VBScript. The purpose of the script is if a user is part of a AD Security Group, then it will unmap a drive letter, and then map a drive letter. I am having issues getting the part of finding if the user is part of that SG.

Now i will admit, i have no idea what i am doing, and probably not the best way of doing it. Here is what i got so far:

Option Explicit
Dim objShell, objNetwork, ObjGroupDict
Dim drFinance, drFOutlook, drTest
Dim sgFinance, sgFinance2, sgFOutlook, sgFOutlook2, sgTest
Dim shFinance, shFOutlook, shTest
Dim strDomain, strUser, strAdsPath
Set objNetwork = WScript.CreateObject("Wscript.Network")
strDomain = objNetwork.UserDomain
strUser = objNetwork.UserName
strAdsPath = strDomain & "\" & strUser
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

'Drive letters
drFinance = "F:"
drFOutlook = "G:"
drTest = "Z:"

'Security Groups
sgFinance = "CFOOrganization - Finance - M"
sgFinance2 = "CFOOrganization - Finance - R"
sgFOutlook = "CFOOrganization - FinanceOutlook - M"
sgFOutlook2 = "CFOOrganization - FinanceOutlook - R"
sgTest = "testdrivemapping"

'Shares:
shFinance = "\\none\data\CFOOrganization\Finance"
shFOutlook = "\\none\data\CFOOrganization\FinanceOutlook"
shTest = "\\none\data"


if isMember(sgTest) then
objNetwork.RemoveNetworkDrive drTest, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shTest
End If

if isMember(sgFinance) then
objNetwork.RemoveNetworkDrive drFinance, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFinance
End If

if isMember(sgFinance2) then
objNetwork.RemoveNetworkDrive drFinance, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFinance
End If

if isMember(sgFOutlook) then
objNetwork.RemoveNetworkDrive drFOutlook, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFOutlook
End If

if isMember(sgFOutlook2) then
objNetwork.RemoveNetworkDrive drFOutlook, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFOutlook
End If



'=========================================================================
'FUNCTIONS
'=========================================================================

Set objNetwork = Nothing
Set objShell = Nothing

Wscript.Quit

Function IsMember(sGroup)
Dim oDict, oUser, oGroup, strDNSDomain, objRootLDAP

If IsEmpty(oDict) Then
Set oDict = CreateObject("Scripting.Dictionary")
set strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
oDict.CompareMode = vbTextCompare

'Location in AD: none.ad.none.net/None Domain Users/Standard Accounts/Americas
Set oUser = GetObject("LDAP://cn=Americas, cn=Standard Aaccounts, cn=None Domain users," & strDNSDomain)
For Each oGroup In oUser.Groups
oDict.Add oGroup.Name, "-"
Next
Set oUser = Nothing
End If

End Function

right now when i run it i get:

C:\mapdrivetest.vbs(74, 3) Microsoft VBScript runtime error: Object required: 'objRootLDAP'

which is this line:

set strDNSDomain = objRootLDAP.Get("DefaultNamingContext")

I just have no idea what i am doing wrong. I am not sure if i am doing this right at all. Can you point me to the right direction?

--Aen

Link to comment
Share on other sites


You haven't defined 'objRootLDAP', and even if you had you have Option Explicit turned on, which means you must DIM the variable too before using it.

I have it DIM'd a few lines up from that

Dim oDict, oUser, oGroup, strDNSDomain, objRootLDAP

do i need to do something else to it?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...