Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WSH problems - can't get Run to work 1

Status
Not open for further replies.

dbMark

Programmer
Apr 10, 2003
1,515
0
0
US
I've recently been tasked to creat some all-VBScript jobs, including FTP. Previously they were done with CMD -> SCP & VBS. Here's my attempt to run an old program that does not wotk on my computer. Surely I'm doing it wrong, but can't figure it out.

Code:
Dim oWSH, myPath, cNewFile, xx
Set oWSH = CreateObject("Wscript.Shell")
myPath = "C:\myFolder\Testing"
cNewFile = myPath & "\myZipFile.zip"
xx = oWSH.Run("S:\Common\PKZIP " & cNewFile & " " & myPath & "\*.csv",1,True)
I get an error: "Invalid procedure call or argument, Code 800A0005"

What am I missing or doing wrong?

I'm also having problems with get my FTP program to run as well in WSH. I suspect I'm not logging via script since I ran it from a CMD file and the CMD window reported Not Connected. Here's the VBS code snippet, if you can see why VBScript error says "The system cannot find the file specified - Code 80070002".
Code:
xx = oWSH.Run("C:\""Program Files""\IpSwitch\""ws_ftp professional""\ftpscrpt -p ""Shared Sites!TestSite""" & myPath & "\myTestScript.scp",1,True)
 
Well, I just figured out that the doubled double quotes don't work in individual spaced-folders as is done in DOS windows.

Snippet good for DOS, wrong for VBScript:
"C:\""Program Files""\IpSwitch\""ws_ftp professional""\ftpscrpt"
Snippet correct for VBScript:
"""C:\Program Files\IpSwitch\ws_ftp professional\ftpscrpt"""

Now that leaves the PKZIP run command which does NOT have spaces in any folder names...
 
To clarify my statement that I figured out the doubled quotes issue, I need to add that I also had to remove the myPath variable and replace it with the full literal address, don't know why...

Caused script not found error:
" ... " & myPath & "\myTestScript.scp"

Worked:
" ... C:\myFolder\Testing\myTestScript.scp"

I'm mystified why I couldn't use a variable here.
 
Another clue, I will have to use a new ZIP program, that one was an older one and zips only DOS 8.3 files. The Run command now returns 0 which must signify no errors.

So now the remaining issue is why I wasn't able to use a variable containing drive and path in the oWSH.Run string.
 
From the example posted, this is not the case but...

make sure all paths that have a space are surrounded by double double (""). Try creating the command string first. Double check it before executing

Code:
cmd = """S:\Common\PKZIP.exe"" """ & cNewFile & """ """ & myPath & "\*.csv"""

msgbox cmd

oWSH.run cmd, 1, true

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Turns out that with all the quotes being bumped around, I didn't leave a required space between the parameters. I fixed that now and I think all VBS issues are fixed, all I have to do is figure out why the FTP won't connect, going to test with another installation.

I notice you didn't use parentheses as I did. Are they optional in VBScript? (I usually work more with database languanges.)
 
I notice you didn't use parentheses as I did. Are they optional in VBScript?
Actually, it is a bit more complicated...

When you call the method as a function a result is returned and the use of parentheses is required:
Code:
xx = oWSH.Run(<parameters>)

When you call the method as a subroutine, no value is returned and it is required that you not use parentheses:
Code:
oWSH.run <parameters>
 
Just as a follow up, I fixed another problem. I had used VBScript to create the .scp file at run time but I set the oFileSystemObject.CreateTextFile flag for Unicode to True since all the examples I saw used True. Oops, big problem, the WS_FTP program could only read ANSI scripts. That solution came from left field so, guys and gals, if you can't figure out the problem, sure that it should work even when it doesn't, sometimes it's simple but something else you would never have imagined.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top