MSFN Forum: VBS Arguments? - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

VBS Arguments? Rate Topic: -----

#1 User is offline   Maelstorm 

  • AT Field Pattern Blue
  • PipPip
  • Group: Members
  • Posts: 265
  • Joined: 22-July 04

  Posted 13 February 2005 - 04:18 AM

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?


#2 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,266
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 13 February 2005 - 10:02 AM

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 User is offline   Maelstorm 

  • AT Field Pattern Blue
  • PipPip
  • Group: Members
  • Posts: 265
  • Joined: 22-July 04

Posted 13 February 2005 - 04:12 PM

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy