Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

VBS Arguments?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Maelstorm

Maelstorm

    AT Field Pattern Blue

  • Member
  • PipPip
  • 265 posts
  • Joined 22-July 04
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?
MAELSTORM


How to remove advertisement from MSFN

#2
IcemanND

IcemanND

    MSFN Junkie

  • Super Moderator
  • 3,266 posts
  • Joined 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag
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


#3
Maelstorm

Maelstorm

    AT Field Pattern Blue

  • Member
  • PipPip
  • 265 posts
  • Joined 22-July 04
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.
MAELSTORM




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users