Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


SOLVED - Quick syntax question

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2985
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> SOLVED - Quick syntax question
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 SOLVED - Quick syntax question - 5/13/2005 3:14:24 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
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 ><
 
 
Post #: 1
 
 Re: SOLVED - Quick syntax question - 5/13/2005 3:38:33 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
Forgot to mention that DriveLetter is getting its value from a function.

(in reply to Caer)
 
 
Post #: 2
 
 Re: SOLVED - Quick syntax question - 5/13/2005 4:45:11 AM   
  Country73


Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
This worked out just fine for me:
Set WshNetwork = WScript.CreateObject("WScript.Network")
DriveLetter = "X:"
sNetPath = "\\server\share"
WshNetwork.MapNetworkDrive DriveLetter, sNetPath

(in reply to Caer)
 
 
Post #: 3
 
 Re: SOLVED - Quick syntax question - 5/13/2005 5:10:31 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
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 ><

(in reply to Caer)
 
 
Post #: 4
 
 Re: SOLVED - Quick syntax question - 5/13/2005 6:15:48 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
What does your variable "sNetPath" contain ?

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

(in reply to Caer)
 
 
Post #: 5
 
 Re: SOLVED - Quick syntax question - 5/13/2005 6:21:39 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
how about posting the whole script?

(in reply to Caer)
 
 
Post #: 6
 
 Re: SOLVED - Quick syntax question - 5/13/2005 6:39:50 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
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 ><

(in reply to Caer)
 
 
Post #: 7
 
 Re: SOLVED - Quick syntax question - 5/13/2005 7:26:57 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
sNetPath = "\\server\share\"
sCommand = "wscript " & sNetPath & "changepassword.vbs"
WshNetwork.MapNetworkDrive DriveLetter, sNetPath

Curious. Is there anything wrong for the statements above ?

(in reply to Caer)
 
 
Post #: 8
 
 Re: SOLVED - Quick syntax question - 5/16/2005 2:12:46 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
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 ><

(in reply to Caer)
 
 
Post #: 9
 
 Re: SOLVED - Quick syntax question - 5/16/2005 6:57:30 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
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 & "#"

(in reply to Caer)
 
 
Post #: 10
 
 Re: SOLVED - Quick syntax question - 5/16/2005 12:40:58 PM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
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...

(in reply to Caer)
 
 
Post #: 11
 
 Re: SOLVED - Quick syntax question - 5/17/2005 2:44:04 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
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

(in reply to Caer)
 
 
Post #: 12
 
 Re: SOLVED - Quick syntax question - 5/17/2005 4:17:21 AM   
  netmarcos

 

Posts: 55
Score: 0
Joined: 12/7/2004
From: USA
Status: offline
Try temp = Left(drives,1) & ": "

(in reply to Caer)
 
 
Post #: 13
 
 Re: SOLVED - Quick syntax question - 5/17/2005 4:42:03 AM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
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

(in reply to Caer)
 
 
Post #: 14
 
 Re: SOLVED - Quick syntax question - 5/17/2005 5:22:14 AM   
  Caer

 

Posts: 29
Score: 0
Joined: 4/26/2005
From: USA
Status: offline
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 ><

(in reply to Caer)
 
 
Post #: 15
 
 Re: SOLVED - Quick syntax question - 5/17/2005 12:36:37 PM   
  marcusrp

 

Posts: 145
Score: 0
Joined: 4/19/2005
From:
Status: offline
good goin man. 90% of the time its the syntax that will bite you

(in reply to Caer)
 
 
Post #: 16
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> SOLVED - Quick syntax question Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts