Help - Search - Members - Calendar
Full Version: VBScript - Logon Script help
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
Aen
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:

CODE
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
Yzöwl
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.
Aen
QUOTE (Yzöwl @ Aug 21 2008, 11:35 AM) *
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?
Yzöwl
Sorry I missed that, I get used to putting all that stuff together in one place!

That said, you still haven't defined the objRootLDAP variable:
objRootLDAP = <whatever>
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.