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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass params to run vbscript

Status
Not open for further replies.

OrionCookies

Programmer
May 5, 2005
43
0
0
US
Hi.
I'm tring to pass params to run vbscript.
for example
cscript.exe /nologo L:\Scripts\PassParam.vbs DelFld
or cscript.exe /nologo L:\Scripts\PassParam.vbs CrtFld

I am getting runtime error:wrong number of arguments.
Need help
thanks in advance...


'*****************here is my code

dim filespec, DirSpec, sstring
sstring = string

DirSpec = "c:\temp\test"
filespec = "c:\temp\test.tst"


'============================

function main(sstring)

if (sString="DelFld") then

DeleteFiles(filespec)

elseif (sString="CrtFld") then
CreationDate(DirSpec)

end if
end function


FUNCTION CreationDate(DirSpec)
Dim fso, f
SET fso = CreateObject("ScriptINg.FileSystemObject")
fso.DeleteFolder(DirSpec)
END Function

FUNCTION DeleteFiles(filespec)
DIM fso
SET fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(filespec)
END Function
 
This line is not valis syntax:

sstring = string

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks EBGreen,
if I commet out variable sstring = string
i am getting this error.....

Microsoft VBScript compilation error: Expected ')'
 
[tt]dim filespec, DirSpec, sstring
[blue]if wscript.arguments.length<>0 then[/blue]
sstring = wscript.arguments(0)
[blue]else
wscript.quit
end if[/blue]

DirSpec = "c:\temp\test"
filespec = "c:\temp\test.tst"
[blue]
main sstring[/blue]
[/tt]
 
Furthermore, I'd use this calling sequence:
cscript.exe L:\Scripts\PassParam.vbs //nologo DelFld

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[1] Double slash nologo is the more desirable format and it falls inline with the vbs commandline design perspective. // is trying to differentiate parameters destined to the script host from the parameters destined to the script.

[2] With //nologo, its position can be anywhere in the line delimited by whitespace. With /nologo, you _must_ make it immediately follow the script host (.exe).

[3] I recall in some other thread, some member(s?) insisted on single slash over double, so I guess if you think it is more clever and know its position in the line, you can do it.
 
As to the single slash logo, ms itself is partly to blame as well. In a couple of kb articles, they use exactly that. But, you know, big organization...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top