Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


Sign in to follow this  
Followers 0
Maelstorm

VBS Arguments?

3 posts in this topic

I have the following code:

Set WshShell = WScript.CreateObject ("WScript.Shell")

wscript.echo "Argument Count", wscript.arguments.count

For I = 0 to wscript.arguments.count - 1
 Wscript.Echo wscript.arguments.item(I)
Next

set cdrom = wscript.arguments.item(0)
set basedir = wscript.arguments.item(1)

wscript.echo cdrom, basedir

When I run it from the command line I get the following output:

G:\Deployment\CDROM\INSTALL>cscript.exe test.vbs g: g:\deployment\cdrom\install

Microsoft ® Windows Script Host Version 5.6

Copyright © Microsoft Corporation 1996-2001. All rights reserved.

Argument Count 2

g:

g:\deployment\cdrom\install

G:\Deployment\CDROM\INSTALL\

test.vbs(9, 1) Microsoft VBScript runtime error: Object required: '[string: "g:"]'

Why? I thought that the item is a string value, but it doesn't seem to like it. What I'm trying to do is to make a VBScript to install software that requires user input, but also takes arguments as to where the install executable is located. Here's what I have so far for lookout120.exe, which gives the same type of error:

Set WshShell = WScript.CreateObject ("WScript.Shell")
Set Ag = Wscript.Arguments

' Process command line arguments
if Ag.count < 2 Then
 WScript.Echo "Command Line Error.  Need <CDROM> <Base Dir>" & vbcrlf
 WScript.Quit
End if

set cdrom = Ag.item(0)
set basedir = Ag.item(1)

' execute program
WshShell.Run (basedir & "\COMPONENT\LOOKOUT\LookOut120.exe /S")

' wait for startup and then start sending keystrokes
WScript.Sleep 5000
WshShell.SendKeys "{SPACE}"

' Wait for install to finish
WScript.Sleep 10000

' Quit
WScript.Quit

What am I doing wrong?

0

Share this post


Link to post
Share on other sites

remove the set statement from the cdrom and basedir lines.

Set WshShell = WScript.CreateObject ("WScript.Shell")
Set Ag = Wscript.Arguments

' Process command line arguments
if Ag.count < 2 Then
WScript.Echo "Command Line Error.  Need <CDROM> <Base Dir>" & vbcrlf
WScript.Quit
End if

cdrom = Ag.item(0)
basedir = Ag.item(1)

' execute program
WshShell.Run (basedir & "\COMPONENT\LOOKOUT\LookOut120.exe /S")

' wait for startup and then start sending keystrokes
WScript.Sleep 5000
WshShell.SendKeys "{SPACE}"

' Wait for install to finish
WScript.Sleep 10000

' Quit
WScript.Quit

0

Share this post


Link to post
Share on other sites

Ok, I see what it's complaining about now. Normally, I wouldn't fess up to it, but you helped me. I didn't correctly interpret Microsoft's documentation. Set is used to assign an object reference to a variable or property. I was trying to assign a regular value to it. Now at least I know why it wasn't working.

Thanks for the tip.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.