SOLVED - Quick syntax question

Author Message
Caer

  • Total Posts : 29
  • Scores: 0
  • Reward points : 0
  • Joined: 4/26/2005
  • Location: USA
  • Status: offline
SOLVED - Quick syntax question Friday, May 13, 2005 4:14 AM (permalink)
0
I have a drive mapping problem here.

When this line of code runs:

WshNetwork.MapNetworkDrive DriveLetter, sNetPath

I get this error:

WSHNetwork.MapNetworkDrive: No network provider accepted the given network path.

I have echoed the value of DriveLetter, sNetPath and apparently there is a space between the x: and the \\server\share so it comes out like "x: \\server\share".

Anyone know how i can fix this?

Thanqs,

Caer ><
 
#1
    Caer

    • Total Posts : 29
    • Scores: 0
    • Reward points : 0
    • Joined: 4/26/2005
    • Location: USA
    • Status: offline
    Re: SOLVED - Quick syntax question Friday, May 13, 2005 4:38 AM (permalink)
    0
    Forgot to mention that DriveLetter is getting its value from a function.
     
    #2
      Country73

      • Total Posts : 754
      • Scores: 10
      • Reward points : 0
      • Status: offline
      Re: SOLVED - Quick syntax question Friday, May 13, 2005 5:45 AM (permalink)
      0
      This worked out just fine for me:
      Set WshNetwork = WScript.CreateObject("WScript.Network")
      DriveLetter = "X:"
      sNetPath = "\\server\share"
      WshNetwork.MapNetworkDrive DriveLetter, sNetPath
       
      #3
        Caer

        • Total Posts : 29
        • Scores: 0
        • Reward points : 0
        • Joined: 4/26/2005
        • Location: USA
        • Status: offline
        Re: SOLVED - Quick syntax question Friday, May 13, 2005 6:10 AM (permalink)
        0
        Here is the function (thanks goes to token for that)

        I have tried using () around the mapnetworkdrive arguments, but get this error:
        "Microsoft VBScript compilation error: Cannot use parentheses when calling a Sub"

        _______________________________________________________________________
        DriveLetter = getNextDriveLetter
        WshNetwork.MapNetworkDrive DriveLetter, sNetPath

        Function getNextDriveLetter
        Dim drive, drives, temp
        drives = "C D E F G H I J K L M N O P Q R S T U V W X Y Z"
        For Each drive In objFso.Drives
        drives = Trim(Replace(drives,Left(drive,1),""))
        Next
        temp = Left(drives,1) & ":"
        getNextDriveLetter = temp
        End Function
        _______________________________________________________________

        I know there has to be a way to do this.

        Caer ><
         
        #4
          token

          • Total Posts : 1917
          • Scores: 0
          • Reward points : 0
          • Joined: 1/14/2005
          • Location:
          • Status: offline
          Re: SOLVED - Quick syntax question Friday, May 13, 2005 7:15 AM (permalink)
          0
          What does your variable "sNetPath" contain ?

          I couldn't see any syntax error from your script.

           
          #5
            kirrilian

            • Total Posts : 629
            • Scores: 3
            • Reward points : 0
            • Joined: 3/15/2005
            • Location:
            • Status: offline
            Re: SOLVED - Quick syntax question Friday, May 13, 2005 7:21 AM (permalink)
            0
            how about posting the whole script?
             
            #6
              Caer

              • Total Posts : 29
              • Scores: 0
              • Reward points : 0
              • Joined: 4/26/2005
              • Location: USA
              • Status: offline
              Re: SOLVED - Quick syntax question Friday, May 13, 2005 7:39 AM (permalink)
              0
              Ok here is the whole script:

              Dim WshShell, objFSO, sUser, sPass, sNetPath

              ' ** sUser is the Username
              ' ** sPass is the Users password
              ' ** sCommand is the command that you want run
              ' ** sNetPath is the path to the server\share
              ' ** You can replace these string variables to any user/password/command
              ' ** combo that you need to run on a pc.
              ' ** NOTE: If you change the sPass field be sure to retain the
              ' ** quotes and the ~ at the end of the actual password, it
              ' ** is the carriage return character.
              sUser = "username@domain.net"
              sPass = "UserPassword~"
              sNetPath = "\\server\share\"

              ' ** USAGE: sCommand = "wscript " <path_to_command> "<your_script_here.vbs"
              ' ** or you can write in any command that needs to be run under
              ' ** a specific users account.
              sCommand = "wscript " & sNetPath & "changepassword.vbs"

              ' ** This is where we setup the working environment for the script to run in.
              Set objComputer = CreateObject("Shell.LocalMachine")
              Set WshNetwork = CreateObject("WScript.Network")
              Set WshShell = CreateObject("WScript.Shell")
              Set WshEnv = WshShell.Environment("Process")
              WinPath = WshEnv("SystemRoot")&"\System32\runas.exe"
              Set objFSO = CreateObject("Scripting.FileSystemObject")

              '** Here we will check to see if this script has run on this computer.
              '** If the file exist then we will end the script.

              If objFSO.FileExists("C:\ScriptLog.txt") Then
              WScript.Quit

              Else
              ' ** Here we map a network drive to our server\share.
              DriveLetter = getNextDriveLetter
              WScript.Echo driveletter, sNetPath
              WshNetwork.MapNetworkDrive DriveLetter, sNetPath

              ' ** This is the meat of the program and where the actual command is run.
              rc = WshShell.Run ("runas /noprofile /user:" & sUser & " " & Chr(34) & sCommand & Chr(34))

              ' ** This gives the command window the time to open.
              WScript.Sleep 900

              ' ** This will grab the active command window to send the password to.
              WshShell.AppActivate(WinPath)

              ' ** This will send the password to the waiting window.
              WshShell.SendKeys sPass

              ' ** Here we write a .txt file to the root of c: for verification that the script
              ' ** has been run on this computer.

              Set objFile = objFSO.CreateTextFile("C:\ScriptLog.txt")
              ' ** Here we open the Finished.txt and append the name of the computer
              ' ** that was just changed and the date it happened.

              Set objTextFile = objFSO.OpenTextFile(DriveLetter & "\Finished.txt", 8, True)
              objTextFile.WriteLine(objComputer.MachineName) & " " & Date() & " " & Time() & " " & (WshNetwork.UserName)
              objTextFile.Close

              ' ** Now we will remove the mapped drive

              WshNetwork.RemoveNetworkDrive DriveLetter

              End If

              '** This function finds the next available drive letter
              '** and returns it to the DriveLetter variable

              Function getNextDriveLetter
              Dim drive, drives, temp
              drives = "C D E F G H I J K L M N O P Q R S T U V W X Y Z"
              For Each drive In objFso.Drives
              drives = Trim(Replace(drives,Left(drive,1),""))
              Next
              temp = Left(drives,1) & ":"
              getNextDriveLetter = temp
              End Function

              '** All Done :)

              WScript.quit

              ------------------------------------------------------------

              Before i wasn't using the sNetPath variable, i was just using a "\\server\share" string in quotes and it worked great, but since this script is for a company that i'm contracted by i want to use variables so that if they need to make changes it will be easier for them.

              Thanks,

              Caer ><
               
              #7
                token

                • Total Posts : 1917
                • Scores: 0
                • Reward points : 0
                • Joined: 1/14/2005
                • Location:
                • Status: offline
                Re: SOLVED - Quick syntax question Friday, May 13, 2005 8:26 PM (permalink)
                0
                sNetPath = "\\server\share\"
                sCommand = "wscript " & sNetPath & "changepassword.vbs"
                WshNetwork.MapNetworkDrive DriveLetter, sNetPath

                Curious. Is there anything wrong for the statements above ?

                 
                #8
                  Caer

                  • Total Posts : 29
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 4/26/2005
                  • Location: USA
                  • Status: offline
                  Re: SOLVED - Quick syntax question Monday, May 16, 2005 3:12 AM (permalink)
                  0
                  Yes, if i echo the DriveLetter and sNetPath it returns "x: \\server\share" with a space between the x: and the path. Thus not mapping the drive and failing the script.

                  Caer ><
                   
                  #9
                    token

                    • Total Posts : 1917
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 1/14/2005
                    • Location:
                    • Status: offline
                    Re: SOLVED - Quick syntax question Monday, May 16, 2005 7:57 AM (permalink)
                    0
                    How did you echo them ? If you put a comma (,) in between them, it will echo a space. Try the following and see what you get.

                    wscript.echo "#" & DriveLetter & "#" & sNetPath & "#"

                     
                    #10
                      marcusrp

                      • Total Posts : 150
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 4/19/2005
                      • Location:
                      • Status: offline
                      Re: SOLVED - Quick syntax question Monday, May 16, 2005 1:40 PM (permalink)
                      0
                      what he's sayin is you got two variables separated by a comma...when you echo it its gonna come out with a space in it. you gotta separate'em with an & symbol, that causes them to concatenate without spaces...
                      put the following in a test script and run it.

                      dim var1, var2
                      var1=1
                      var2=2
                      wscript.echo var1, var2
                      wscript.echo var1 & var2

                      don't worry, that one has gotten me a few times too...
                       
                      #11
                        Caer

                        • Total Posts : 29
                        • Scores: 0
                        • Reward points : 0
                        • Joined: 4/26/2005
                        • Location: USA
                        • Status: offline
                        Re: SOLVED - Quick syntax question Tuesday, May 17, 2005 3:44 AM (permalink)
                        0
                        Ok here is a stripped down version of the script with only the parts needed to get my error.

                        'Start Script Snippet

                        Set WshNetwork = CreateObject("WScript.Network")
                        Set objFSO = CreateObject("Scripting.FileSystemObject")
                        sNetPath = "\\Server\Share\"

                        DriveLetter = getNextDriveLetter
                        WScript.Echo Driveletter & sNetPath
                        WshNetwork.MapNetworkDrive DriveLetter & sNetPath


                        Function getNextDriveLetter
                        Dim drive, drives, temp
                        drives = "C D E F G H I J K L M N O P Q R S T U V W X Y Z"
                        For Each drive In objFso.Drives
                        drives = Trim(Replace(drives,Left(drive,1),""))
                        Next
                        temp = Left(drives,1) & ":"
                        getNextDriveLetter = temp
                        End Function


                        'End Script Snippet

                        Here is the output I recieve when i run the script:

                        F:\\Server\Share\
                        C:\Scripts\Final Working Scripts\Untitled5.vbs(7, 4) Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment: 'WshNetwork.MapNetworkDrive'

                        Exit code: 0 , 0000h

                        Thats where i'm at now... any ideas?

                        ><
                        Caer
                         
                        #12
                          netmarcos

                          • Total Posts : 55
                          • Scores: 0
                          • Reward points : 0
                          • Joined: 12/7/2004
                          • Location: USA
                          • Status: offline
                          Re: SOLVED - Quick syntax question Tuesday, May 17, 2005 5:17 AM (permalink)
                          0
                          Try temp = Left(drives,1) & ": "
                           
                          #13
                            marcusrp

                            • Total Posts : 150
                            • Scores: 0
                            • Reward points : 0
                            • Joined: 4/19/2005
                            • Location:
                            • Status: offline
                            Re: SOLVED - Quick syntax question Tuesday, May 17, 2005 5:42 AM (permalink)
                            0
                            go here, and see if you can figure it out -http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthmapnetworkdrive.asp
                             
                            #14
                              Caer

                              • Total Posts : 29
                              • Scores: 0
                              • Reward points : 0
                              • Joined: 4/26/2005
                              • Location: USA
                              • Status: offline
                              Re: SOLVED - Quick syntax question Tuesday, May 17, 2005 6:22 AM (permalink)
                              0
                              OK I GOT IT!

                              Woohoo.

                              Here was the problem.

                              First off in
                              Old version "WshNetwork.MapNetworkDrive DriveLetter, sNetPath"
                              New version "WshNetwork.MapNetworkDrive DriveLetter,sNetPath"
                              I had a space between "Driveletter," and sNetPath. By putting them next to each other with the comma and no space the argument problem was solved.

                              After that i ran into a "No network provider accepted the given network path." problem.
                              That was solved by using
                              sNetPath = "Server.domain.net\share" instead of "\\server\share".

                              Thanks for all your help!

                              Caer ><

                               
                              #15
                                marcusrp

                                • Total Posts : 150
                                • Scores: 0
                                • Reward points : 0
                                • Joined: 4/19/2005
                                • Location:
                                • Status: offline
                                Re: SOLVED - Quick syntax question Tuesday, May 17, 2005 1:36 PM (permalink)
                                0
                                good goin man. 90% of the time its the syntax that will bite you
                                 
                                #16

                                  Online Bookmarks Sharing: Share/Bookmark

                                  Jump to:

                                  Current active users

                                  There are 0 members and 1 guests.

                                  Icon Legend and Permission

                                  • New Messages
                                  • No New Messages
                                  • Hot Topic w/ New Messages
                                  • Hot Topic w/o New Messages
                                  • Locked w/ New Messages
                                  • Locked w/o New Messages
                                  • Read Message
                                  • Post New Thread
                                  • Reply to message
                                  • Post New Poll
                                  • Submit Vote
                                  • Post reward post
                                  • Delete my own posts
                                  • Delete my own threads
                                  • Rate post

                                  2000-2012 ASPPlayground.NET Forum Version 3.9