Announcement

Collapse
No announcement yet.

Little Help Please

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Little Help Please

    Hello Guys - I need a little help please.. I've been trying to make this login script to run with our Windows 2003 domain controller but I've been unsuccessful so far. I got this script of Microsoft's website. I want to map drives and printers based upon groups. Is there something I'm missing? Can someone please validate this script. I'm running Windows 2003 SP1, with AD. Thank you so much!


    Code:
    Const ADMINISTRATIONS_GROUP = "cn=Administrations"
    Const ENGINEERING_GROUP     = "cn=Engineering"
    Const EXECUTIVES_GROUP      = "cn=Executives"
    Const MANUFACTURING_GROUP   = "cn=Manufacturing"
    Const MIS_GROUP             = "cn=MIS"
    Const SALES_GROUP           = "cn=Sales"
    Const SUPPORT_GROUP         = "cn=Support"
    
    Set ADSysInfo = CreateObject("ADSystemInfo")
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
    strGroups = LCase(Join(CurrentUser.MemberOf))
    
    If InStr(strGroups, ADMINISTRATIONS_GROUP) Then
    
        wshNetwork.MapNetworkDrive "S:", "\\Eklinserver01\Administrations\"
        wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing\"
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
       
    ElseIf InStr(strGroups, ENGINEERING_GROUP) Then
    
        wshNetwork.MapNetworkDrive "N:", "\\Eklinserver01\Engineering\"
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
        wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8100N"
    
    ElseIf InStr(strGroups, EXECUTIVES_GROUP) Then
    
        wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing\"
        wshNetwork.MapNetworkDrive "N:", "\\Eklinserver01\Engineering\"
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing\"
        wshNetwork.MapNetworkDrive "S:", "\\Eklinserver01\Administration\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
        wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
    
    ElseIf InStr(strGroups, MANUFACTURING_GROUP) Then
    
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
        wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8100N"
    
    ElseIf InStr(strGroups, MIS_GROUP) Then
    
        wshNetwork.MapNetworkDrive ("M:", "\\Eklinserver01\Marketing\")
        wshNetwork.MapNetworkDrive ("N:", "\\Eklinserver01\Engineering\")
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing\"
        wshNetwork.MapNetworkDrive "S:", "\\Eklinserver01\Administration\"
        wshNetwork.MapNetworkDrive "T:", "\\Eklinserver01\IT\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
        wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
    
    ElseIf InStr(strGroups, SALES_GROUP) Then
    
        wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing\"
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
        wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
    
    ElseIf InStr(strGroups, SUPPORT_GROUP) Then
    
        wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP\"
        wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public\"
        wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing\"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
        wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
        wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
    
    End If

  • #2
    Re: Little Help Please

    Well what errors are you getting?

    Firstly, I think you need to define wshNetwork with something like

    Code:
    set wshNetwork = CreateObject("WScript.Network")
    Also, I'm no code expert but don't you need to pass the script the current username, I don't think that picks up the current logged on user. Maybe wrong though!!!
    Last edited by topper; 4th October 2005, 10:40.
    * Shamelessly mentioning "Don't forget to add reputation!"

    Comment


    • #3
      Re: Little Help Please

      I haven't tried your code, but...

      > LCase(Join(CurrentUser.MemberOf))

      That lowercases everything, whereas your groupnames are partially uppercase. That would lead to no match at all.

      Comment


      • #4
        Re: Little Help Please

        Sorry for not giving any details on the error message... actually, there are none.. it just doesn't work.. no messages, no pop-ups.. it just doesn't work...
        Last edited by mhikey; 4th October 2005, 17:41.

        Comment


        • #5
          Re: Little Help Please

          Then you need to start simplyfying your code. Remove but only the essentials.

          Is this where you got the example from:

          http://www.microsoft.com/technet/pro...8d6a63080.mspx

          If so then topper is right you are missing

          Code:
          Set wshNetwork = CreateObject("WScript.Network")
          EDIT: Just tested the script and it works fine with the above line added. Hope this helps
          Last edited by tonyyeb; 4th October 2005, 19:35.
          Server 2000 MCP
          Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

          ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

          Comment


          • #6
            Re: Little Help Please

            Thank you so much for the response guys.. I tried a bit different script but I'm still having problems.. especially when it comes to mapping drives per group. It removes the drive letters, add 2 drives, and adds the printers. But the other drives doesn't get mapped. Any ideas? thanks again!!

            Code:
            Option Explicit
            Dim objNetwork, objUser, CurrentUser
            Dim strGroup
            
            Const administrations_group = "cn=administrations"
            Const engineering_group     = "cn=engineering"
            Const executives_group      = "cn=executives"
            Const manufacturing_group   = "cn=manufacturing"
            Const mis_group             = "cn=mis"
            Const sales_group           = "cn=sales"
            Const support_group         = "cn=support"
            
            Set objNetwork = CreateObject("WScript.Network")
            ' Forces script to skip errors (rem below line to see errors)
            on error resume next
            
            Dim WshNetwork
            Set WshNetwork = WScript.CreateObject("WScript.Network")
            ' Set all drives to be removed here.
            WshNetwork.RemoveNetworkDrive "u:"
            WshNetwork.RemoveNetworkDrive "v:"
            WshNetwork.RemoveNetworkDrive "w:"
            WshNetwork.RemoveNetworkDrive "x:"
            WshNetwork.RemoveNetworkDrive "y:"
            WshNetwork.RemoveNetworkDrive "z:"
            
            Set objUser = CreateObject("ADSystemInfo")
            Set CurrentUser = GetObject("LDAP://" & objUser.UserName) 
            strGroup = LCase(Join(CurrentUser.MemberOf))
            
            ' SETTING ALL NETWORKDRIVES THAT ARE AVAILABLE FOR EVERY USER
             objNetwork.MapNetworkDrive "z:", "\\eklinserver01\PCMRP"
             objNetwork.MapNetworkDrive "y:", "\\eklinserver01\Public"
            
            ' SETTING THE PRINTERS
            Set objNetwork = CreateObject("WScript.Network")
             objNetwork.AddWindowsPrinterConnection "\\eklinserver01\hp8000n" 
             objNetwork.AddWindowsPrinterConnection "\\eklinserver01\hp8100n"
             
             ' EXTRA DRIVES FOR SPECIFIC GROUP
            if InStr(strGroup, administrations_group) then
            	objNetwork.MapNetworkDrive "w:", "\\eklinserver01\Administrations"
            end if
            
            if InStr(strGroup, executives_group) then
            	objNetwork.MapNetworkDrive "w:", "\\eklinserver01\Administrations"
            	objNetwork.MapNetworkDrive "x:", "\\eklinserver01\Marketing"
            	objNetwork.MapNetworkDrive "u:", "\\eklinserver01\Manufacturing"
            end if
            
            if InStr(strGroup, sales_group) then
            	objNetwork.MapNetworkDrive "x:", "\\eklinserver01\Marketing"
            end if
            
            if InStr(strGroup, engineering_group) then
            	objNetwork.MapNetworkDrive "v:", "\\eklinserver01\Engineering"
            end if
            
            if InStr(strGroup, manufacturing_group) or InStr(strGroup, support_group) then 
            	objNetwork.MapNetworkDrive "u:", "\\eklinserver01\Manufacturing"
            end if
            
            WScript.Quit
            'end of script

            Comment


            • #7
              Re: Little Help Please

              Although I haven't test the script in a AD environment I have made a few alterations. If it fails comment out the 'On Error Resume Next' line. THis will help detail where the error is occuring (you'll be suprised the many types of errors that can occur when trying to map a drive using 'RemoveNetworkDrive'.

              Code:
              ''' Ensure that we declare all items
              Option Explicit
              
              ''' Ignore Errors
              On Error Resume Next
              
              Dim objADSysInfo
              Dim objCurrentUser
              Dim strGroups
              Dim wshNewtork
              
              
              ''' Ensure All Constants are in lowercase
              Const ADMINISTRATIONS_GROUP = "cn=administrations"
              Const ENGINEERING_GROUP     = "cn=engineering"
              Const EXECUTIVES_GROUP      = "cn=executives"
              Const MANUFACTURING_GROUP   = "cn=manufacturing"
              Const MIS_GROUP             = "cn=mis"
              Const SALES_GROUP           = "cn=sales"
              Const SUPPORT_GROUP         = "cn=support"
              
              
              ''' Define Objects
              Set objADSysInfo = CreateObject("ADSystemInfo")
              Set objCurrentUser = GetObject("LDAP://" & objADSysInfo.UserName)
              Set wshNetwork = CreateObject("WScript.Network")
              
              ''' Build a string of group user is member of
              If Not IsArray(objCurrentUser.MemberOf) Then
                      strGroups = lcase(objCurrentUser.MemberOf)
              Else
                      strGroups = LCase(Join(objCurrentUser.MemberOf))
              End If
              
              
              ''' Remove Drive Connected to letter we wish to use
              ''' and do it by force. Also deleted it from the user profile
              
              WshNetwork.RemoveNetworkDrive "u:", true, true
              WshNetwork.RemoveNetworkDrive "v:", true, true
              WshNetwork.RemoveNetworkDrive "w:", true, true
              WshNetwork.RemoveNetworkDrive "x:", true, true
              WshNetwork.RemoveNetworkDrive "y:", true, true
              WshNetwork.RemoveNetworkDrive "z:", true, true
              
              
              ''' What Group Is The User A Member Of?
              ''' Make Sure we start at the beginning of the string
              
              If InStr(1, strGroups, ADMINISTRATIONS_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "S:", "\\Eklinserver01\Administrations"
                  wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing"
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                 
              ElseIf InStr(1, strGroups, ENGINEERING_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "N:", "\\Eklinserver01\Engineering"
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                  wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8100N"
              
              ElseIf InStr(1, strGroups, EXECUTIVES_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing"
                  wshNetwork.MapNetworkDrive "N:", "\\Eklinserver01\Engineering"
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing"
                  wshNetwork.MapNetworkDrive "S:", "\\Eklinserver01\Administration"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                  wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
              
              ElseIf InStr(1, strGroups, MANUFACTURING_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                  wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8100N"
              
              ElseIf InStr(1, strGroups, MIS_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing"
                  wshNetwork.MapNetworkDrive "N:", "\\Eklinserver01\Engineering"
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing"
                  wshNetwork.MapNetworkDrive "S:", "\\Eklinserver01\Administration"
                  wshNetwork.MapNetworkDrive "T:", "\\Eklinserver01\IT"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                  wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
              
              ElseIf InStr(1, strGroups, SALES_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "M:", "\\Eklinserver01\Marketing"
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                  wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
              
              ElseIf InStr(1, strGroups, SUPPORT_GROUP) Then
              
                  wshNetwork.MapNetworkDrive "P:", "\\Eklinserver01\PCMRP"
                  wshNetwork.MapNetworkDrive "Q:", "\\Eklinserver01\Public"
                  wshNetwork.MapNetworkDrive "R:", "\\Eklinserver01\Manufacturing"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8000N"
                  wshNetwork.AddWindowsPrinterConnection "\\Eklinserver01\HP8100N"
                  wshNetWork.SetDefaultPrinter "\\Eklinserver01\HP8000N"
              
              End If
              
              
              ''' Once finished ---- Clean Up Your Toys!!!!
              
              Set objADSysInfo = Nothing
              Set objCurrentUser = Nothing
              Set wshNewtork = Nothing

              Comment


              • #8
                Re: Little Help Please

                SIR! Thank you so much!!!! You are awesome!! Everything Works!!!!!

                Comment


                • #9
                  Re: Little Help Please

                  Hi trying to do the exact same mapping described so i edited the script posted......however i keep getting the
                  Error: The specified domain either does not exist or could not be contacted.
                  code: 8007054B

                  the error points to this line.
                  Set objCurrentUser = GetObject("LDAP://" & objADSysInfo.UserName)
                  (Char 1, Line 20)

                  Any ideas??

                  Comment


                  • #10
                    Re: Little Help Please

                    Hi

                    Just try creating a script with just:

                    Code:
                    ''' Ensure that we declare all items
                    Option Explicit
                    
                    ''' Ignore Errors
                    On Error Resume Next
                    
                    Dim objADSysInfo
                    Dim objCurrentUser
                    Dim strGroups
                    Dim wshNewtork
                    
                    
                    ''' Ensure All Constants are in lowercase
                    Const ADMINISTRATIONS_GROUP = "cn=administrations"
                    Const ENGINEERING_GROUP     = "cn=engineering"
                    Const EXECUTIVES_GROUP      = "cn=executives"
                    Const MANUFACTURING_GROUP   = "cn=manufacturing"
                    Const MIS_GROUP             = "cn=mis"
                    Const SALES_GROUP           = "cn=sales"
                    Const SUPPORT_GROUP         = "cn=support"
                    
                    
                    ''' Define Objects
                    Set objADSysInfo = CreateObject("ADSystemInfo")
                    Set objCurrentUser = GetObject("LDAP://" & objADSysInfo.UserName)
                    Set wshNetwork = CreateObject("WScript.Network")
                    This works fine for me.
                    Server 2000 MCP
                    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                    Comment


                    • #11
                      Re: Little Help Please

                      Tested the script with only 2 groups however i still get the same error mentioned.
                      ---------------------------------------------------------------------------
                      code:

                      ''' Ensure that we declare all items
                      Option Explicit

                      ''' Ignore Errors
                      'On Error Resume Next

                      Dim objADSysInfo
                      Dim objCurrentUser
                      Dim strGroups
                      Dim wshNewtork


                      ''' Ensure All Constants are in lowercase
                      Const ADMINISTRATIONS_GROUP = "cn=administrations"
                      Const ENGINEERING_GROUP = "cn=engineering"


                      ''' Define Objects
                      Set objADSysInfo = CreateObject("ADSystemInfo")
                      Set objCurrentUser = GetObject("LDAP://" & objADSysInfo.UserName)
                      Set wshNetwork = CreateObject("WScript.Network")
                      --------------------------------------------------------------------------------------------------
                      I get the error at this line:
                      Set objCurrentUser = GetObject("LDAP://" & objADSysInfo.UserName)

                      Comment


                      • #12
                        Re: Little Help Please

                        What version of Active Directory are you running?
                        Server 2000 MCP
                        Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                        Comment


                        • #13
                          Re: Little Help Please

                          Windows 2003 Server Standard Edition Service Pk 1
                          Exchange 2003 with all the latest Service Packs

                          Active Directory Users and Computers Version: 5.2.3790.1830

                          Comment


                          • #14
                            Re: Little Help Please

                            Are you running the script on a client? Have you tried running it by going to a command prompt and typing:

                            c:\cscript myscript.vbs
                            Server 2000 MCP
                            Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                            Comment


                            • #15
                              Re: Little Help Please

                              In Active Directory on the 2003 server Under the User Profile Tab i have a bat file calling the login script.

                              This is my bat file..........

                              @echo off
                              wscript %0\..\LogonScript.vbs


                              This .bat file is in the C:\Windows\SYSVOL\domain\scripts directory on the same server and the LogonScript.vbs is in the same Directory.

                              I am logging in on a client machine which calls this bat file(i actually see the cmd prompt open on the client machine) then the error message appears.

                              I tried typing: cscript LogonScript.vbs in the command promp after the c:\ on the server and got the response : Microsoft Windows Script Host Version 5.6
                              Input error: can not find script file "C:\LogonScript.vbs"

                              --------------------------------------------------------------------------------------------------
                              If i double click on the LogonScript.vbs on the server i get the message:
                              Variable is undefined: 'wshNetwork'
                              Last edited by morjo; 29th November 2005, 17:10.

                              Comment

                              Working...
                              X