Announcement

Collapse
No announcement yet.

Can't map the same drive letter

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

  • Can't map the same drive letter

    Hi,

    I'm trying to run a vbs script to map drives. To date, it's worked fine, but I'm now trying to use the same drive letter twice in the same script, but to different paths dependant upon the user's credentials.

    Part of the script is shown below:

    ' Mappings for Group A
    group = "Group A" 'set group name
    set objGroupRPC = GetObject("WinNT://" & domain & "/" & group)
    If objGroupRPC.IsMember(objUser.ADsPath) Then
    'WScript.echo "Member of Group Resourcing"
    Call MapDrive ("g:", "\\servername\sharename\GroupA
    End If

    ' Mappings for Group B
    group = "Group B" 'set group name
    set objGroupRPC = GetObject("WinNT://" & domain & "/" & group)
    If objGroupRPC.IsMember(objUser.ADsPath) Then
    'WScript.echo "Member of Group"
    Call MapDrive ("g:", "\\servername\sharename\GroupB
    End If

    The only drive that gets mapped is for those in Group B. Group A's drive letter doesn't get mapped.

    I've tried a different drive letter for members of Group A, and it works fine, but I would prefer to use the G drive.

    Anyone got any ideas?

    Cheers
    MJ

  • #2
    Re: Can't map the same drive letter

    the line Call MapDrive ("g:", "\\servername\sharename\GroupA

    is that a function you wrote, please post that code as well.
    MCSE 2000\2003, A+
    00000001-00000011-00000011-00000111

    Comment


    • #3
      Re: Can't map the same drive letter

      I would hazard a guess at your If statements not working correctly, and GroupA is being overwritten by GroupB.

      Do users which exists in Group A (but do not exists in GroupB) get mapped to the GroupB drive ?

      topper
      * Shamelessly mentioning "Don't forget to add reputation!"

      Comment


      • #4
        Re: Can't map the same drive letter

        indeed, post you're script completely...
        also try some debugging. a nice scripteditor is primalscript, which can help you out.

        also use the code buttons for better reading and post it next time in de correct forum
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: Can't map the same drive letter

          Sub MapDrive(strDrive, strShare)

          On Error Resume Next
          WshNetwork.MapNetworkDrive strDrive, strShare
          If Err.Number Then
          Err.Clear
          WshNetwork.RemoveNetworkDrive strDrive
          WshNetwork.MapNetworkDrive strDrive, strShare

          End If

          If Err.Number Then
          UpdateStatus ("**FAILED** " & strDrive & " : " & strShare)
          Err.Clear
          Else
          UpdateStatus (strDrive & " " & strShare)
          End If

          End Sub

          Do users which exists in Group A (but do not exists in GroupB) get mapped to the GroupB drive
          Nope.

          Comment


          • #6
            Re: Can't map the same drive letter

            Again,

            post the complete Script!!!!!!!!

            now we got the following:

            Code:
             Mappings for Group A
            group = "Group A" 'set group name
            set objGroupRPC = GetObject("WinNT://" & domain & "/" & group) 
               If objGroupRPC.IsMember(objUser.ADsPath) Then
                   'WScript.echo "Member of Group Resourcing"
                   Call MapDrive ("g:", "\\servername\sharename\GroupA
               End If 
            
            ' Mappings for Group B
            group = "Group B" 'set group name
            set objGroupRPC = GetObject("WinNT://" & domain & "/" & group) 
               If objGroupRPC.IsMember(objUser.ADsPath) Then
                   'WScript.echo "Member of Group"
                   Call MapDrive ("g:", "\\servername\sharename\GroupB
               End If

            and some other code:
            Code:
            Sub MapDrive(strDrive, strShare)
            
            On Error Resume Next
            WshNetwork.MapNetworkDrive strDrive, strShare
               If Err.Number Then
                    Err.Clear
                    WshNetwork.RemoveNetworkDrive strDrive
                    WshNetwork.MapNetworkDrive strDrive, strShare
                End If
            
                If Err.Number Then
                     UpdateStatus ("**FAILED** " & strDrive & " : " & strShare)
                     Err.Clear
                Else
                     UpdateStatus (strDrive & " " & strShare)
            End If
            End Sub

            one big mistake is:

            Call MapDrive ("g:", "\\servername\sharename\GroupA
            have a first look at this, if you have this correct in you're script then post it...
            Marcel
            Technical Consultant
            Netherlands
            http://www.phetios.com
            http://blog.nessus.nl

            MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
            "No matter how secure, there is always the human factor."

            "Enjoy life today, tomorrow may never come."
            "If you're going through hell, keep going. ~Winston Churchill"

            Comment


            • #7
              Re: Can't map the same drive letter

              ok 2 things first off in Call MapDrive ("g:", "\\servername\sharename\GroupA
              put a ") at the end so Call MapDrive ("g:", "\\servername\sharename\GroupA") and for B as well, i'm not sure if thats nessacary but it will make me feel better.

              this code conserns me

              If Err.Number Then
              Err.Clear
              WshNetwork.RemoveNetworkDrive strDrive
              WshNetwork.MapNetworkDrive strDrive, strShare

              if you get get an error b/c the drive is already mapped you remove the drive and remap it, sounds logical. but what if you get an error removing the drive b/c say it was in use. you would then get another error when you tried mapping again and nothing would happen. so does group A have no mapped drive at all or is it mapped to something wrong that you want to change? what happens if you run this on a machine that has no mapped drives to start with.
              MCSE 2000\2003, A+
              00000001-00000011-00000011-00000111

              Comment


              • #8
                Re: Can't map the same drive letter

                '================================================= =========================
                ' AUTHOR:
                ' DATE:
                ' VER:
                '================================================= =========================

                'Declarations
                Dim WshNetwork 'scripting network object
                Dim strStatus 'stores the ongoing state of play
                Dim strUser 'user login name
                Dim IE 'instance of Internet Explorer
                Dim OrgUnit 'the OU (Dept) of the user
                Dim x 'timer for logon start
                Dim y 'timer for logon finish
                Dim strWKS 'computer name
                Dim SiteWKS 'site portion of the computer name (first 4)

                Const ADS_READONLY_SERVER = 4
                x = Timer()
                On Error Resume Next

                'Get the User ID
                Set WshNetwork = WScript.CreateObject("WScript.Network")
                'Get the Computer Name
                strWKS = WshNetwork.ComputerName
                'WScript.Echo strWks


                Call UpdateStatus("Mapping Drives & Network Printers.")


                ' Now do drive mappings based on group membership

                domain = "DOMAIN" ' set domain name
                set objUser = GetObject("WinNT://" & domain & "/" & strUser) 'get user object
                set objWks = GetObject("WinNT://" & domain & "/" & strWks) ' get computer object

                ' Mappings for Group C
                group = "Group c" 'set group name
                set objGroupRPC = GetObject("WinNT://" & domain & "/" & group)
                If objGroupRPC.IsMember(objUser.ADsPath) Then
                'WScript.echo "Member of Group C"
                Call MapDrive ("m:", "\\servername\share\groupc")
                End If

                ' Mappings for Group D
                group = "Group D" 'set group name
                set objGroupRPC = GetObject("WinNT://" & domain & "/" & group)
                If objGroupRPC.IsMember(objUser.ADsPath) Then
                'WScript.echo "Member of Group D"
                Call MapDrive ("s:", "\\servername\share\groupd")
                End If

                ' Mappings for Group A
                group = "Group A" 'set group name
                set objGroupRPC = GetObject("WinNT://" & domain & "/" & group)
                If objGroupRPC.IsMember(objUser.ADsPath) Then
                'WScript.echo "Member of Group A"
                Call MapDrive ("g:", "\\servername\sharename\GroupA")
                End If

                ' Mappings for Group B
                group = "Group B" 'set group name
                set objGroupRPC = GetObject("WinNT://" & domain & "/" & group)
                If objGroupRPC.IsMember(objUser.ADsPath) Then
                'WScript.echo "Member of Group B"
                Call MapDrive ("g:", "\\servername\sharename\GroupB")
                End If

                Sub MapDrive(strDrive, strShare)

                On Error Resume Next
                WshNetwork.MapNetworkDrive strDrive, strShare
                If Err.Number Then
                Err.Clear
                WshNetwork.RemoveNetworkDrive strDrive
                WshNetwork.MapNetworkDrive strDrive, strShare

                End If

                If Err.Number Then
                UpdateStatus ("**FAILED** " & strDrive & " : " & strShare)
                Err.Clear
                Else
                UpdateStatus (strDrive & " " & strShare)
                End If

                End Sub

                so does group A have no mapped drive at all or is it mapped to something wrong that you want to change?
                Group A users only map a home drive and should map to \\servername\sharename\GroupA, but they don't get the latter.

                what happens if you run this on a machine that has no mapped drives to start with.
                It the user is a member of group A, it doesn't map drive G to \\servername\sharename\GroupA.

                I've checked via GPRESULT to make sure it is seeing the Group A membership, and that checks out ok.

                Comment

                Working...
                X