Advertisement

04.28.2006 at 06:32PM PDT, ID: 21831914
[x]
Attachment Details

AD VBasic Login Script (Long)

Asked by whoam in Visual Basic Programming

Okay, here's the whole script.  I'm trying to map drives and printers based on AD site or membership in groups and OU's.  I think this suffers from bloat.  

I get the printers removed just fine.
The existing network drives enter the state of being disconnected, but do not disappear.  Opening one in this state immediately reconnects it.
I frequently (but not always) get an error 80070057, The parameter is incorrect on line 33
                       oNet.RemoveNetworkDrive oDrives.Item(i)
       This is usually fixed ( for a while) by changing the 0 from the line above to a 1 or 2, saving, then changing it back.


I get the 'common drives', and EVERYONE gets the privalaged drives. but no new printer mapping based on site occurs

Thanks for your help



' the ucase command returns the input in all caps

' +++++++++++++++++++++++++++++++++THIS IS THE BASE PRINTER AND DRIVE MAPPING SCRIPT ++++++++++++++++++++++++++++++++++++++++++++++
' +++purpose is to remove any existing drive and printer mappings, then create new/apprpirate ones based on AD group membership.+++




'start of script
    Option Explicit
    'On Error Resume Next





'++++++++++++++++++++++++++++++because Symantec s***s, we must sleep++++++++++++++++++++++++
    'WScript.Sleep 3000 'miliseconds




'++++++++++++++++++++++++NEXT remove existing mappings+++++++++++++++++++++++++++++++
   Dim oNet, oDrives, nDrive, i

    Set oNet = CreateObject("Wscript.Network")

    Set oDrives = oNet.EnumNetworkDrives

    For i = 0 To oDrives.Count-1 Step 2
        oNet.RemoveNetworkDrive oDrives.Item(i)
    WScript.echo i
    Next
' +++++++++++++++++++++++ "end drive removal"++++++++++++++++++++++++++++++++++++++++






'+++++++++++++++++++++BULK PRINTER REMOVAL BEGIN++++++++++++++++++++++
 WScript.echo  "Begin by removing all mapped printers To unconfuse users"

   Dim WSHNet, wshNetwork
   Dim clprinters, n
   Set WSHNet= WScript.CreateObject("Wscript.Network")
   Set clPrinters = WshNet.EnumPrinterConnections
   On Error Resume Next
   For n = 0 To clPrinters.Count - 1 Step 2
     WSHNet.RemovePrinterConnection clPrinters.Item(n+1), True
   Next
'++++++++++++++++END BULK PRINTER REMOVAL++++++++++++++++++++





'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' ++++++++++++Okay, now that we have had our dose of fiber and are all clean, let's start adding objects+++++++++++++++++
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




'+++++++++++++Some of my drives get mapped no matter who you are++++++++++++++++++++++
                    Dim objNetwork
                    Set objNetwork = CreateObject("WScript.Network")

              WScript.echo "common drives"
              objNetwork.MapNetworkDrive "S:", "\\R105002\shared"
              objNetwork.MapNetworkDrive "I:", "\\R105002\intercept"



'++++++++++++Only domain admins get the N Drive****************************************
           
Dim strGroup
' Dim currentuser
' Dim objectUser
' Dim net
' Dim objprinter
WScript.echo "privalaged drives"
 ' here we creat pegs for the AD groups
 Const DomAd     = "Domain Admins"
 
 

 WScript.echo "Now we see which group the member belongs To"
 Set objectUser = CreateObject("ADSystemInfo")
WScript.echo "next line"
Set currentuser = GetObject("LDAP://" & objectUser.UserName)
WScript.echo "active directoroy group based drive mapping"
WScript.echo  objuser & currentuser
 If UBound(currentuser.MemberOf)>0 Then
 strGroup = LCase(Join(currentuser.MemberOf))
 Else strGroup=currentuser.MemberOf(0)
 WScript.echo strGroup
 End If






' +++++++++++++++++++BEGIN DRIVE MAPPING PER GROUP MEMBERSHIP+++++++++++++++++++

  If InStr(strGroup, DomAd) Then
'      WScript.Echo "You are logged into the IT Group "
    WScript.echo strGroup

          objNetwork.MapNetworkDrive "N:", "\\R105002\install"
          objNetwork.MapNetworkDrive "H:", "\\R105002\home"
          objNetwork.MapNetworkDrive "S:", "\\R052002\home"
          objNetwork.MapNetworkDrive "P:", "\\R227002\home"
          objNetwork.MapNetworkDrive "M:", "\\R221002\home"

  End If      








'+++++++++++++++++++++++++Some Drives are on site server, so they are mapped by AD site+++++++++++++++++++++++++++++++
   
Dim objSYSInfo, objNetW
Set objSysInfo = WScript.CreateObject("ADSystemInfo")
    'a good example of how ADSystemInfo works is
    ' Set objAD = CreateObject("ADSystemInfo")  
    ' Wscript.Echo "Your Computer Name is " & objAD.ComputerName  
    ' WScript.Echo "Your Username is " & objAD.UserName

Set objNetW = WScript.CreateObject("WScript.Network")

Dim objADSUser
'holds our user's name
Set objADSUser = GetObject("LDAP://" & objSYSInfo.username)
' This simply forces LDAP to perform as the dirctory lookup protocol

Dim objADSOU
Set objADSOU = GetObject(objADSUser.parent)
WScript.echo "here we set the site" & objADUser.parent
 ' hmm so the ADSysteminfo.username.parent method returns the OU of the user?

'Dim objWinntUser
'Set objWinntUser = GetObject("WinNT://" & objNetW.UserDomain & "/" & objNetW.UserName & ",user")
'This forces WinNT/NeRIOS to act as the directory

'******* end of objects declarations

Dim strOU, StrGrP
'strOU = "_davidstestou"
'StrGrP = "Domain Admins"
' This is just feeding in known false data to prove the comparison below

'uncomment for testing
'MsgBox objNetW.username & " is directly inside the " & strOU & " OU = " & IsDirectMemberOfOU(strOU)
'MsgBox objNetW.username & " is directly or indirectly inside the " & strOU & " OU = " & IsIndirectMemberOfOU(strOU)
'MsgBox objNetW.username & " is a member of the " & StrGrP & " group = " & IsMemberOfGroup(StrGrP)
'IsDirectMemberOfOU is just a bucket that hold a true or false value, see the 1st function.

MsgBox "note the difference in paths for the different protocols:" & vbCrLf & _
    "User ADSPath(LDAP) = " & objADSUser.adspath
    ' "User ADSPath(Winnt) = " & objWinntUser.adspath & vbCrLf & _
     


'***** End of main script, All functions and subs below *****

'Function IsDirectMemberOfOU(OUName) 'the user is contained directly within the OU
'IsDirectMemberOfOU = False

'If UCase(objADSOU.OU) = UCase(OUName) Then
'     IsDirectMemberOfOU = True
'End If

'End Function

'Function IsIndirectMemberOfOU(OUName) 'the user is somewher under the OU specified
'IsIndirectMemberOfOU = False

'If InStr(UCase(objADSOU.adspath),UCase(OUName)) Then
'     IsIndirectMemberOfOU = True
'End If

'End Function

'Function IsMemberOfGroup(GroupName) 'the user is a member of a specified group
'IsMemberOfGroup = False

'Dim objGroup
'Set objGroup = GetObject("WinNT://" & objNetW.UserDomain & "/" & GroupName & ",group")

'IsMemberOfGroup = objGroup.IsMember(objWinntUser.ADsPath)

'End Function
WScript.exho objADSOU.OU

If UCase(objADSOU.OU) = UCase("OU_MtP") Then objNetW.MapNetworkDrive "z:", "\\R105002\home\" & objADSUser

If UCase(objADSOU.OU) = UCase("OU_Operations") then objNetW.MapNetworkDrive "z:", "\\R105002\home\" & objADSUser

If UCase(objADSOU.OU) = UCase("OU_Pwest") Then objNetW.MapNetworkDrive "z:", "\\R105002\home\" & objADSUser

If UCase(objADSOU.OU) = UCase("OU_serT") Then objNetW.MapNetworkDrive "z:", "\\R052002\home\" & objADSUser

If UCase(objADSOU.OU) = UCase("OU_MBs") Then objNetW.MapNetworkDrive "z:", "\\R221002\home\" & objADSUser



'uncomment after move
'If IsIndirectMemberOfOU("OU_Pwest") Then objNetW.MapNetworkDrive "z:", "\\R227002\home" & objADSUser


Start Free Trial
[+][-]04.28.2006 at 06:36PM PDT, ID: 16567074

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2006 at 06:45PM PDT, ID: 16567094

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2006 at 09:23AM PDT, ID: 16578326

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2006 at 10:35AM PDT, ID: 16578859

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2006 at 11:52AM PDT, ID: 16579551

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2006 at 06:14PM PDT, ID: 16582357

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.02.2006 at 08:46AM PDT, ID: 16587290

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Sign Up Now!
Solution Provided By: ddepastino
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.02.2006 at 09:15AM PDT, ID: 16587660

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.02.2006 at 09:16AM PDT, ID: 16587688

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.05.2006 at 08:34AM PDT, ID: 16615758

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.05.2006 at 11:20AM PDT, ID: 16617205

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.05.2006 at 11:28AM PDT, ID: 16617274

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.05.2006 at 03:37PM PDT, ID: 16618804

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.08.2006 at 11:16AM PDT, ID: 16632839

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.08.2006 at 06:55PM PDT, ID: 16635840

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2006 at 08:35AM PDT, ID: 16691668

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2006 at 09:11AM PDT, ID: 16692005

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2006 at 05:19PM PDT, ID: 16695470

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32