Announcement

Collapse
No announcement yet.

Script does not work

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

  • Script does not work

    can any one look at this script I found and have been trying to get working on my server. I am not realy script sasy so I cant see any thing wrong with it but it still wont work. I just need someone who knows scripting enough to take a look at it I feel it is almost there but something keeps stuffing up.




    when running it I get the following error



    Line 79
    Char: 5
    Error: the network path was not found

    Code: 80070035
    Source: wshnetwork.mapnetworkdrive











    Code:
      
     'Created by Richard Merz for mapping and renaming shares.
    'This will check to see if a drive is mapped and map if necessary.  No action if already mapped.
    '12April12
      
     ' ADD OR SUBTRACT AS MANY AS YOU WANT
     Option Explicit
    Dim objNetwork, strDrive, objShell, objUNC, objFSO
     Dim strRemotePath2, strDriveLetter2, strNewName2
    Dim strRemotePath3, strDriveLetter3, strNewName3
    Dim strRemotePath4, strDriveLetter4, strNewName4
    Dim strRemotePath5, strDriveLetter5, strNewName5
    Dim strRemotePath6, strDriveLetter6, strNewName6
    Dim strRemotePath7, strDriveLetter7, strNewName7
    Dim strRemotePath8, strDriveLetter8, strNewName8
      
     ' NEEDED FOR IF THEN
     Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = CreateObject("Wscript.Network") 
      
     ' DECLARING DRIVES AND UNC PATHS
     
    strDriveLetter2 = "M:" 
    strRemotePath2 = "\\\\\\\\LCE-SERVER\\\\MYOB user" 
    strNewName2 = "MYOB"
    ' Change the Letter, Path, and Name
     strDriveLetter3 = "O:" 
    strRemotePath3 = "\\\\\\\\Fileserv\\\\data\\\\COMPANIES" 
    strNewName3 = "Companies"
    ' Change the Letter, Path, and Name
     strDriveLetter4 = "J:" 
    strRemotePath4 = "\\\\\\\\Fileserv\\\\data\\\\COMPANIES\\\\LCE Queensland\\\\Awarded Jobs" 
    strNewName4 = "Awarded Jobs"
    ' Change the Letter, Path, and Name
     strDriveLetter5 = "x:" 
    strRemotePath5 = "\\\\\\\\Fileserv\\\\data\\\\ESTIMATING" 
    strNewName5 = "Estimating"
    ' Change the Letter, Path, and Name
     strDriveLetter6 = "R:" 
    strRemotePath6 = "\\\\\\\\Fileserv\\\\data\\\\RESOURCES" 
    strNewName6 = "Resources"
    ' Change the Letter, Path, and Name
     strDriveLetter7 = "S:" 
    strRemotePath7 = "\\\\\\\\Fileserv\\\\data\\\\RESOURCES\\\\Scans" 
    strNewName7 = "Scans"
    ' Change the Letter, Path, and Name
     strDriveLetter8 = "I:" 
    strRemotePath8 = "\\\\\\\\Fileserv\\\\data\\\\IT" 
    strNewName8 = "IT"
    ' Change the Letter, Path, and Name
      
     ' CHECKING TO SEE IF DRIVE IS MAPPED, IF IT IS IT IGNORES IT AND MOVES ON, IF IT IS NOT IT MAPS IT.
      
     
    ' Section to map the M network drive
    If (objFSO.DriveExists("M:") = True) Then
        objNetwork.RemoveNetworkDrive "M:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2 
     ' Section which actually (re)names the M Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter2).Self.Name = strNewName2
      
     ' Section to map the O network drive
    If (objFSO.DriveExists("O:") = True) Then
        objNetwork.RemoveNetworkDrive "O:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3 
     ' Section which actually (re)names the O Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter3).Self.Name = strNewName3
      
     ' Section to map the J network drive
    If (objFSO.DriveExists("J:") = True) Then
        objNetwork.RemoveNetworkDrive "J:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4 
     ' Section which actually (re)names the J Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter4).Self.Name = strNewName4
      
     ' Section to map the x network drive
    If (objFSO.DriveExists("x:") = True) Then
        objNetwork.RemoveNetworkDrive "x:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5 
     ' Section which actually (re)names the x Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter5).Self.Name = strNewName5
      
     ' Section to map the R network drive
    If (objFSO.DriveExists("R:") = True) Then
        objNetwork.RemoveNetworkDrive "R:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter6, strRemotePath6 
     ' Section which actually (re)names the R Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter6).Self.Name = strNewName6
      
     ' Section to map the S network drive
    If (objFSO.DriveExists("S:") = True) Then
        objNetwork.RemoveNetworkDrive "S:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter7, strRemotePath7 
     ' Section which actually (re)names the S Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter7).Self.Name = strNewName7
      
     ' Section to map the I network drive
    If (objFSO.DriveExists("I:") = True) Then
        objNetwork.RemoveNetworkDrive "I:", True, True
    End If
        Set objNetwork = CreateObject("WScript.Network") 
        objNetwork.MapNetworkDrive strDriveLetter8, strRemotePath8 
     ' Section which actually (re)names the I Mapped Drive
    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(strDriveLetter8).Self.Name = strNewName8
      
     WScript.Quit
     ' End of VBScript.
    Last edited by Mandrake; 1st July 2014, 07:08.

  • #2
    Re: Script dose not work

    Line 79 on mine points to this

    Code:
    objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4
    Which leads me to this

    Code:
    strDriveLetter4 = "J:" 
    strRemotePath4 = "\\\\\\\\Fileserv\\\\data\\\\COMPANIES\\\\LCE Queensland\\\\Awarded Jobs"
    Why is strRemotePath4 like that??

    it should simply be "\\fileserv\data\COMPANIES\LCE\Queensland\Awar ded Jobs"

    Comment


    • #3
      Re: Script dose not work

      I had the same idea when I first found this but I was told being that it is a VB script it needed certain number of \\\\

      sadly I did not know a lot about it but I have tried it with a basic

      \\fileserv\data\COMPANIES\LCE\Queensland\Awarded Jobs

      below is changed code based on what you have mentioned.



      Code:
       
       'Created by Richard Merz for mapping and renaming shares.
      'This will check to see if a drive is mapped and map if necessary.  No action if already mapped.
      '12April12
        
       ' ADD OR SUBTRACT AS MANY AS YOU WANT
       Option Explicit
      Dim objNetwork, strDrive, objShell, objUNC, objFSO
       Dim strRemotePath2, strDriveLetter2, strNewName2
      Dim strRemotePath3, strDriveLetter3, strNewName3
      Dim strRemotePath4, strDriveLetter4, strNewName4
      Dim strRemotePath5, strDriveLetter5, strNewName5
      Dim strRemotePath6, strDriveLetter6, strNewName6
      Dim strRemotePath7, strDriveLetter7, strNewName7
      Dim strRemotePath8, strDriveLetter8, strNewName8
        
       ' NEEDED FOR IF THEN
       Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objNetwork = CreateObject("Wscript.Network") 
        
       ' DECLARING DRIVES AND UNC PATHS
       
      strDriveLetter2 = "M:" 
      strRemotePath2 = "\\LCE-SERVER\MYOB user" 
      strNewName2 = "MYOB"
      ' Change the Letter, Path, and Name
       strDriveLetter3 = "O:" 
      strRemotePath3 = "\\Fileserv\data\COMPANIES" 
      strNewName3 = "Companies"
      ' Change the Letter, Path, and Name
       strDriveLetter4 = "J:" 
      strRemotePath4 = "\\Fileserv\data\COMPANIES\LCE Queensland\Awarded Jobs" 
      strNewName4 = "Awarded Jobs"
      ' Change the Letter, Path, and Name
       strDriveLetter5 = "x:" 
      strRemotePath5 = "\\Fileserv\data\ESTIMATING" 
      strNewName5 = "Estimating"
      ' Change the Letter, Path, and Name
       strDriveLetter6 = "R:" 
      strRemotePath6 = "\\Fileserv\data\RESOURCES" 
      strNewName6 = "Resources"
      ' Change the Letter, Path, and Name
       strDriveLetter7 = "S:" 
      strRemotePath7 = "\\Fileserv\data\RESOURCES\Scans" 
      strNewName7 = "Scans"
      ' Change the Letter, Path, and Name
       strDriveLetter8 = "I:" 
      strRemotePath8 = "\\Fileserv\data\IT" 
      strNewName8 = "IT"
      ' Change the Letter, Path, and Name
        
       ' CHECKING TO SEE IF DRIVE IS MAPPED, IF IT IS IT IGNORES IT AND MOVES ON, IF IT IS NOT IT MAPS IT.
        
       
      ' Section to map the M network drive
      If (objFSO.DriveExists("M:") = True) Then
          objNetwork.RemoveNetworkDrive "M:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2 
       ' Section which actually (re)names the M Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter2).Self.Name = strNewName2
        
       ' Section to map the O network drive
      If (objFSO.DriveExists("O:") = True) Then
          objNetwork.RemoveNetworkDrive "O:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3 
       ' Section which actually (re)names the O Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter3).Self.Name = strNewName3
        
       ' Section to map the J network drive
      If (objFSO.DriveExists("J:") = True) Then
          objNetwork.RemoveNetworkDrive "J:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4 
       ' Section which actually (re)names the J Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter4).Self.Name = strNewName4
        
       ' Section to map the x network drive
      If (objFSO.DriveExists("x:") = True) Then
          objNetwork.RemoveNetworkDrive "x:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5 
       ' Section which actually (re)names the x Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter5).Self.Name = strNewName5
        
       ' Section to map the R network drive
      If (objFSO.DriveExists("R:") = True) Then
          objNetwork.RemoveNetworkDrive "R:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter6, strRemotePath6 
       ' Section which actually (re)names the R Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter6).Self.Name = strNewName6
        
       ' Section to map the S network drive
      If (objFSO.DriveExists("S:") = True) Then
          objNetwork.RemoveNetworkDrive "S:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter7, strRemotePath7 
       ' Section which actually (re)names the S Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter7).Self.Name = strNewName7
        
       ' Section to map the I network drive
      If (objFSO.DriveExists("I:") = True) Then
          objNetwork.RemoveNetworkDrive "I:", True, True
      End If
          Set objNetwork = CreateObject("WScript.Network") 
          objNetwork.MapNetworkDrive strDriveLetter8, strRemotePath8 
       ' Section which actually (re)names the I Mapped Drive
      Set objShell = CreateObject("Shell.Application")
      objShell.NameSpace(strDriveLetter8).Self.Name = strNewName8
        
       WScript.Quit
       ' End of VBScript.
      Code runes for a lot longer this time around but still get the following error now

      Line: 79
      Chr: 5
      Error: The networth Path Was not found

      Code: 80070035
      Source: wshnetwork.mapnetworkdrive

      Comment


      • #4
        Re: Script dose not work

        Thank you I think based of you info and noticing another issue plus removing the name of the server and placed in the ip instead I seem to have fixed this script.

        I thank you a lot for your support.

        Final working code

        Code:
         
         'Created by Richard Merz for mapping and renaming shares.
        'This will check to see if a drive is mapped and map if necessary.  No action if already mapped.
        '12April12
          
         ' ADD OR SUBTRACT AS MANY AS YOU WANT
         Option Explicit
        Dim objNetwork, strDrive, objShell, objUNC, objFSO
         Dim strRemotePath2, strDriveLetter2, strNewName2
        Dim strRemotePath3, strDriveLetter3, strNewName3
        Dim strRemotePath4, strDriveLetter4, strNewName4
        Dim strRemotePath5, strDriveLetter5, strNewName5
        Dim strRemotePath6, strDriveLetter6, strNewName6
        Dim strRemotePath7, strDriveLetter7, strNewName7
        Dim strRemotePath8, strDriveLetter8, strNewName8
          
         ' NEEDED FOR IF THEN
         Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objNetwork = CreateObject("Wscript.Network") 
          
         ' DECLARING DRIVES AND UNC PATHS
         
        strDriveLetter2 = "M:" 
        strRemotePath2 = "\\192.168.0.202\data\RESOURCES\Myob Shortcuts" 
        strNewName2 = "MYOB"
        ' Change the Letter, Path, and Name
         strDriveLetter3 = "O:" 
        strRemotePath3 = "\\192.168.0.202\data\COMPANIES" 
        strNewName3 = "Companies"
        ' Change the Letter, Path, and Name
         strDriveLetter4 = "J:" 
        strRemotePath4 = "\\192.168.0.202\data\COMPANIES\LCE Queensland\Awarded Jobs" 
        strNewName4 = "Awarded Jobs"
        ' Change the Letter, Path, and Name
         strDriveLetter5 = "x:" 
        strRemotePath5 = "\\192.168.0.202\data\ESTIMATING" 
        strNewName5 = "Estimating"
        ' Change the Letter, Path, and Name
         strDriveLetter6 = "R:" 
        strRemotePath6 = "\\192.168.0.202\data\RESOURCES" 
        strNewName6 = "Resources"
        ' Change the Letter, Path, and Name
         strDriveLetter7 = "S:" 
        strRemotePath7 = "\\192.168.0.202\data\RESOURCES\Scans" 
        strNewName7 = "Scans"
        ' Change the Letter, Path, and Name
         strDriveLetter8 = "I:" 
        strRemotePath8 = "\\192.168.0.202\data\IT" 
        strNewName8 = "IT"
        ' Change the Letter, Path, and Name
          
         ' CHECKING TO SEE IF DRIVE IS MAPPED, IF IT IS IT IGNORES IT AND MOVES ON, IF IT IS NOT IT MAPS IT.
          
         
        ' Section to map the M network drive
        If (objFSO.DriveExists("M:") = True) Then
            objNetwork.RemoveNetworkDrive "M:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2 
         ' Section which actually (re)names the M Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter2).Self.Name = strNewName2
          
         ' Section to map the O network drive
        If (objFSO.DriveExists("O:") = True) Then
            objNetwork.RemoveNetworkDrive "O:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3 
         ' Section which actually (re)names the O Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter3).Self.Name = strNewName3
          
         ' Section to map the J network drive
        If (objFSO.DriveExists("J:") = True) Then
            objNetwork.RemoveNetworkDrive "J:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4 
         ' Section which actually (re)names the J Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter4).Self.Name = strNewName4
          
         ' Section to map the x network drive
        If (objFSO.DriveExists("x:") = True) Then
            objNetwork.RemoveNetworkDrive "x:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5 
         ' Section which actually (re)names the x Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter5).Self.Name = strNewName5
          
         ' Section to map the R network drive
        If (objFSO.DriveExists("R:") = True) Then
            objNetwork.RemoveNetworkDrive "R:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter6, strRemotePath6 
         ' Section which actually (re)names the R Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter6).Self.Name = strNewName6
          
         ' Section to map the S network drive
        If (objFSO.DriveExists("S:") = True) Then
            objNetwork.RemoveNetworkDrive "S:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter7, strRemotePath7 
         ' Section which actually (re)names the S Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter7).Self.Name = strNewName7
          
         ' Section to map the I network drive
        If (objFSO.DriveExists("I:") = True) Then
            objNetwork.RemoveNetworkDrive "I:", True, True
        End If
            Set objNetwork = CreateObject("WScript.Network") 
            objNetwork.MapNetworkDrive strDriveLetter8, strRemotePath8 
         ' Section which actually (re)names the I Mapped Drive
        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(strDriveLetter8).Self.Name = strNewName8
          
         WScript.Quit
         ' End of VBScript.

        Comment


        • #5
          Re: Script dose not work

          Originally posted by Mandrake View Post
          Thank you I think based of you info and noticing another issue plus removing the name of the server and placed in the ip instead I seem to have fixed this script.

          I thank you a lot for your support.

          Final working code

          Code:
           
           'Created by Richard Merz for mapping and renaming shares.
          'This will check to see if a drive is mapped and map if necessary.  No action if already mapped.
          '12April12
            
           ' ADD OR SUBTRACT AS MANY AS YOU WANT
           Option Explicit
          Dim objNetwork, strDrive, objShell, objUNC, objFSO
           Dim strRemotePath2, strDriveLetter2, strNewName2
          Dim strRemotePath3, strDriveLetter3, strNewName3
          Dim strRemotePath4, strDriveLetter4, strNewName4
          Dim strRemotePath5, strDriveLetter5, strNewName5
          Dim strRemotePath6, strDriveLetter6, strNewName6
          Dim strRemotePath7, strDriveLetter7, strNewName7
          Dim strRemotePath8, strDriveLetter8, strNewName8
            
           ' NEEDED FOR IF THEN
           Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objNetwork = CreateObject("Wscript.Network") 
            
           ' DECLARING DRIVES AND UNC PATHS
           
          strDriveLetter2 = "M:" 
          strRemotePath2 = "\\192.168.0.202\data\RESOURCES\Myob Shortcuts" 
          strNewName2 = "MYOB"
          ' Change the Letter, Path, and Name
           strDriveLetter3 = "O:" 
          strRemotePath3 = "\\192.168.0.202\data\COMPANIES" 
          strNewName3 = "Companies"
          ' Change the Letter, Path, and Name
           strDriveLetter4 = "J:" 
          strRemotePath4 = "\\192.168.0.202\data\COMPANIES\LCE Queensland\Awarded Jobs" 
          strNewName4 = "Awarded Jobs"
          ' Change the Letter, Path, and Name
           strDriveLetter5 = "x:" 
          strRemotePath5 = "\\192.168.0.202\data\ESTIMATING" 
          strNewName5 = "Estimating"
          ' Change the Letter, Path, and Name
           strDriveLetter6 = "R:" 
          strRemotePath6 = "\\192.168.0.202\data\RESOURCES" 
          strNewName6 = "Resources"
          ' Change the Letter, Path, and Name
           strDriveLetter7 = "S:" 
          strRemotePath7 = "\\192.168.0.202\data\RESOURCES\Scans" 
          strNewName7 = "Scans"
          ' Change the Letter, Path, and Name
           strDriveLetter8 = "I:" 
          strRemotePath8 = "\\192.168.0.202\data\IT" 
          strNewName8 = "IT"
          ' Change the Letter, Path, and Name
            
           ' CHECKING TO SEE IF DRIVE IS MAPPED, IF IT IS IT IGNORES IT AND MOVES ON, IF IT IS NOT IT MAPS IT.
            
           
          ' Section to map the M network drive
          If (objFSO.DriveExists("M:") = True) Then
              objNetwork.RemoveNetworkDrive "M:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2 
           ' Section which actually (re)names the M Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter2).Self.Name = strNewName2
            
           ' Section to map the O network drive
          If (objFSO.DriveExists("O:") = True) Then
              objNetwork.RemoveNetworkDrive "O:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3 
           ' Section which actually (re)names the O Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter3).Self.Name = strNewName3
            
           ' Section to map the J network drive
          If (objFSO.DriveExists("J:") = True) Then
              objNetwork.RemoveNetworkDrive "J:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter4, strRemotePath4 
           ' Section which actually (re)names the J Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter4).Self.Name = strNewName4
            
           ' Section to map the x network drive
          If (objFSO.DriveExists("x:") = True) Then
              objNetwork.RemoveNetworkDrive "x:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter5, strRemotePath5 
           ' Section which actually (re)names the x Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter5).Self.Name = strNewName5
            
           ' Section to map the R network drive
          If (objFSO.DriveExists("R:") = True) Then
              objNetwork.RemoveNetworkDrive "R:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter6, strRemotePath6 
           ' Section which actually (re)names the R Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter6).Self.Name = strNewName6
            
           ' Section to map the S network drive
          If (objFSO.DriveExists("S:") = True) Then
              objNetwork.RemoveNetworkDrive "S:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter7, strRemotePath7 
           ' Section which actually (re)names the S Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter7).Self.Name = strNewName7
            
           ' Section to map the I network drive
          If (objFSO.DriveExists("I:") = True) Then
              objNetwork.RemoveNetworkDrive "I:", True, True
          End If
              Set objNetwork = CreateObject("WScript.Network") 
              objNetwork.MapNetworkDrive strDriveLetter8, strRemotePath8 
           ' Section which actually (re)names the I Mapped Drive
          Set objShell = CreateObject("Shell.Application")
          objShell.NameSpace(strDriveLetter8).Self.Name = strNewName8
            
           WScript.Quit
           ' End of VBScript.
          If you're script won't map based in NetBIOS names then you don't have a WINS server in your domain and should be using DNS names, server.domain.whatever.

          What were the other issues you spotted?

          Comment


          • #6
            Re: Script dose not work

            hmm I had such high hopes this was resolved but I implemented this in a group policy only to get the following error

            lin 79
            chr 5
            error : the local Device name has a remembered connection to another network resource.

            Code: 800704b2
            Source: wshnetwork.mapnetworkdrive


            Wins Server yes I don't remember setting one up so that is probably the case.

            I find this interesting that it seems attached to another network resource...

            btw the line differs but the error is the same.

            not sure if this is a security thing or not as I had tested it with my self and my manager we both have full security but not the other guys. I feeling very newbish not doing the simple test with a person with less security clearance.

            Comment


            • #7
              Re: Script dose not work

              OK I have shortened the script. There were too many repeated lines in your script, what increases the risk of typing errors and it makes it hard to spot errors.

              Code:
              Dim WshNetwork, objShell, WshShell, oDrives
              Set WshNetwork = CreateObject("Wscript.Network") 
              Set objShell = CreateObject("Shell.Application")
              Set WshShell = CreateObject("WScript.Shell")
              Set oDrives = WshNetwork.EnumNetworkDrives
              
              
              ' DRIVES AND UNC PATHS
              
                strDriveLetter = "M:" 
                strRemotePath = "\\LCE-SERVER.domain.local\MYOB user" 
                strNewName = "MYOB"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
                strDriveLetter = "O:" 
                strRemotePath = "\\Fileserv.domain.local\data\COMPANIES" 
                strNewName = "Companies"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
                strDriveLetter = "J:" 
                strRemotePath = "\\Fileserv.domain.local\data\COMPANIES\LCE Queensland\Awarded Jobs" 
                strNewName = "Awarded Jobs"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
                strDriveLetter = "x:" 
                strRemotePath = "\\Fileserv.domain.local\data\ESTIMATING" 
                strNewName = "Estimating"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
                strDriveLetter = "R:" 
                strRemotePath = "\\Fileserv.domain.local\data\RESOURCES" 
                strNewName = "Resources"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
                strDriveLetter = "S:" 
                strRemotePath = "\\Fileserv.domain.local\data\RESOURCES\Scans" 
                strNewName = "Scans"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
                strDriveLetter = "I:" 
                strRemotePath = "\\Fileserv.domain.local\data\IT" 
                strNewName = "IT"
              MapDrive strDriveLetter, strRemotePath, strNewName
              
              wscript.quit
              
              
              Sub MapDrive (sDrv, sUNC, sLabel)
              
                 ' unmap drive (1)
                  If oDrives.Count <> 0 Then
                    For i = 0 To oDrives.Count -1 Step 2
                      If StrComp(oDrives.Item(i), Left(sDrv, 1), vbTextCompare) Then
                        strCMD = "cmd.exe /c COLOR 72 & title Disconnecting persistent Mapping & " _
                                 & "(echo.|NET.exe USE " & sDrv & " /d /y )"
                        WshShell.Run(strCMD), 0, True
                        wscript.sleep 1000
                      End If
                    Next
                  End If
              
                 ' unmap drive
                 On Error Resume Next
                 WshNetwork.RemoveNetworkDrive sDrv, true, true
                 If Err.number = 0 then
                   wscript.sleep 1000
                 Else
                   Err.Clear
                 End If 
                 On Error GoTo 0
              
                 ' map drive
                 WshNetwork.MapNetworkDrive sDrv, sUNC, false
                 objShell.NameSpace(sDrv).Self.Name = sLabel
              
              End Sub
              I have created a sub routine called MapDrive(). The sub routine replaces the lines that are under "CHECKING TO SEE IF DRIVE IS MAPPED, IF IT IS IT IGNORES IT AND MOVES ON, IF IT IS NOT IT MAPS IT." in your script.


              The part "unmap drive (1)" is added because maybe it could solve the error you get. (This part can in fact replace the part "unmap drive" and vice versa.)
              It uses this dos command,
              NET.exe USE <drv> /delete /yes
              It forces to unmap a previous mapping also if it is currently disconnected from the share. Because with RemoveNetworkDrive you cannot remove drives that persistently shows a red "X" in Explorer.


              /Rems
              Last edited by Rems; 9th July 2014, 18:57.

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: Script does not work

                Ha Rems thanks for that made it a lot more tidy.

                the fileserv.domain.local did not work so I changed it to fileserv.lce0.local but no joy so changed it to IP and it works fine.

                now I added another few mappings and they worked fine as well.

                this time I tried it out on a user with less access then me and I get the following error

                Line 83
                Chr: 4
                Error: Access Denied

                I think it has to do with access so when it goes to map something it dose not have access to it throws the above error.

                is there a way to bypass on access denied messages? ie Skip to next mapping?


                below is latest code I working with.

                Code:
                Dim WshNetwork, objShell, WshShell, oDrives
                Set WshNetwork = CreateObject("Wscript.Network") 
                Set objShell = CreateObject("Shell.Application")
                Set WshShell = CreateObject("WScript.Shell")
                Set oDrives = WshNetwork.EnumNetworkDrives
                 
                ' DRIVES AND UNC PATHS
                   strDriveLetter = "M:" 
                  strRemotePath = "\\192.168.0.202\data\RESOURCES\myob shortcuts" 
                  strNewName = "MYOB"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "O:" 
                  strRemotePath = "\\192.168.0.202\data\COMPANIES" 
                  strNewName = "Companies"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "J:" 
                  strRemotePath = "\\192.168.0.202\data\COMPANIES\LCE Queensland\Awarded Jobs" 
                  strNewName = "Awarded Jobs"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "x:" 
                  strRemotePath = "\\192.168.0.202\data\ESTIMATING" 
                  strNewName = "Estimating"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "R:" 
                  strRemotePath = "\\192.168.0.202\data\RESOURCES" 
                  strNewName = "Resources"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "S:" 
                  strRemotePath = "\\192.168.0.202\data\RESOURCES\Scans" 
                  strNewName = "Scans"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "I:" 
                  strRemotePath = "\\192.168.0.202\data\IT" 
                  strNewName = "IT"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "n:" 
                  strRemotePath = "\\192.168.0.202\data\management" 
                  strNewName = "Management"
                MapDrive strDriveLetter, strRemotePath, strNewName
                   strDriveLetter = "T:" 
                  strRemotePath = "\\192.168.0.202\data\COMPANIES\LCE Queensland\safety & qa" 
                  strNewName = "Safety"
                MapDrive strDriveLetter, strRemotePath, strNewName
                 wscript.quit
                 
                Sub MapDrive (sDrv, sUNC, sLabel)
                    ' unmap drive (1)
                    If oDrives.Count <> 0 Then
                      For i = 0 To oDrives.Count -1 Step 2
                        If StrComp(oDrives.Item(i), Left(sDrv, 1), vbTextCompare) Then
                          strCMD = "cmd.exe /c COLOR 72 & title Disconnecting persistent Mapping & " _
                                   & "(echo.|NET.exe USE " & sDrv & " /d /y )"
                          WshShell.Run(strCMD), 0, True
                          wscript.sleep 1000
                        End If
                      Next
                    End If
                    ' unmap drive
                   On Error Resume Next
                   WshNetwork.RemoveNetworkDrive sDrv, true, true
                   If Err.number = 0 then
                     wscript.sleep 1000
                   Else
                     Err.Clear
                   End If 
                   On Error GoTo 0
                    ' map drive
                   WshNetwork.MapNetworkDrive sDrv, sUNC, false
                   objShell.NameSpace(sDrv).Self.Name = sLabel
                 End Sub

                Comment


                • #9
                  Re: Script does not work

                  Originally posted by Mandrake View Post

                  this time I tried it out on a user with less access then me and I get the following error

                  Line 83
                  Chr: 4
                  Error: Access Denied


                  below is latest code I working with.

                  Code:
                  ...
                  Ehh... Error in line 83?? the script you are working with just has 70 lines.

                  Does the user, that is getting this error, has perhaps local administrator rights?
                  What is the OS on the client and the OS on the file server?



                  Originally posted by Mandrake View Post
                  I changed it to fileserv.lce0.local but no joy so changed it to IP and it works fine.
                  Are the computer member of a domain. Do they have static IP addresses or do they obtain an addres from a dhcp server? can you show the results of ipconfig from one off the clients.


                  /Rems
                  Last edited by Rems; 14th July 2014, 12:32.

                  This posting is provided "AS IS" with no warranties, and confers no rights.

                  __________________

                  ** Remember to give credit where credit's due **
                  and leave Reputation Points for meaningful posts

                  Comment


                  • #10
                    Re: Script does not work

                    well the pc I tried was a local admin so I decided to try it on another and it is the exact same error

                    line 83
                    chr 4
                    error : access denied


                    I really think it has to do with security as that user dose not have access to some of the zones being mapped.

                    I know u did your sub routine for the disconnected error but is there a way for it to accept the fact a user dose not have access so moves onto next command.

                    because if I take out the zones she dose not have access to the command runs fine.

                    I had seen login scripts that check for security then map that way but I thought we could bypass that with just skipping any that don't have access.





                    Regarding the other.
                    we run a DHCP off our DC 1 which is also the DNS server. I will have to relook at the domain stuff but I think it is because I put in wrong .local addresses

                    will play with that latter but for now my concern is the security element of this script

                    Comment


                    • #11
                      Re: Script does not work

                      Originally posted by Mandrake View Post
                      is there a way for it to accept the fact a user dose not have access so moves onto next command.
                      sure, replace the subroutine with this version,

                      Code:
                      Sub MapDrive (sDrv, sUNC, sLabel)
                         On Error Resume Next
                      
                         ' unmap drive (1)
                          If oDrives.Count <> 0 Then
                            For i = 0 To oDrives.Count -1 Step 2
                              If StrComp(oDrives.Item(i), Left(sDrv, 1), vbTextCompare) Then
                                strCMD = "cmd.exe /c COLOR 72 & title Disconnecting persistent Mapping & " _
                                         & "(echo.|NET.exe USE " & sDrv & " /d /y )"
                                WshShell.Run(strCMD), 0, True
                                wscript.sleep 1000
                              End If
                            Next
                          End If
                      
                         ' unmap drive
                         Err.Clear
                         WshNetwork.RemoveNetworkDrive sDrv, true, true
                         If Err.number = 0 then
                           wscript.sleep 1000
                         Else
                           Err.Clear
                         End If 
                      
                         ' map drive
                         WshNetwork.MapNetworkDrive sDrv, sUNC, false
                         objShell.NameSpace(sDrv).Self.Name = sLabel
                      
                      End Sub
                      /Rems

                      This posting is provided "AS IS" with no warranties, and confers no rights.

                      __________________

                      ** Remember to give credit where credit's due **
                      and leave Reputation Points for meaningful posts

                      Comment


                      • #12
                        Re: Script does not work

                        well I tested the new code you gave me and works good

                        tested it on 3 different ppl and no errors sofar.


                        but I did notice something the renaming element is hit and miss

                        sometimes need to run it twice to rename them.

                        but at least it is mapping them all now.

                        hopfuly that should do the job

                        Comment

                        Working...
                        X