Welcome, Register for free! or Login below:
EduGeek.net RSS Feeds Register FAQ Members Social Groups User Map Calendar Search Today's Posts Mark Forums Read

Go Back   EduGeek.net Forums > Coding and Web Development > Coding
Reply
 
LinkBack Thread Tools Search Thread Language
Sponsored Links
Old 01-05-2007, 10:28 AM   #1
 
StewartKnight's Avatar
 
Join Date: Jun 2005
Posts: 1,433
Thanks: 0
Thanked 7 Times in 7 Posts
Rep Power: 12 StewartKnight will become famous soon enough
Default VBScript

I'm trying to write a script (stop sniggering at the back), which is going swimmingly ..... except......

I was to specify a file from the command prompt at run time.
I want the file that I specify from WScript.Argument to be read using objFSO.OpenTextFile.

When I do it, i get the error:

C:\stewart7.vbs(50, 3) Microsoft VBScript runtime error: Object doesn't support this property or method: 'WScript.Argument'.

The whole of the function that I'm trying to create is this
Quote:
Function CheckFile
Set objReadFile = WScript.Argument
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(objReadFile, 1)
set objCreate = objFSO.CreateTextFile("results.txt", 2)


Do While Not objFile.AtEndOfStream
objStewart = objFile.ReadLine

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colPings = objWMIService.ExecQuery _
("Select * From Win32_PingStatus where Address = '" & objStewart & "'")
If Err = 0 Then
Err.Clear
For Each objPing in colPings
If objPing.StatusCode = 0 Then
objResult = objStewart & " available." & "IP Address: " & objPing.ProtocolAddress
Else
objResult = objStewart & " not available."
End If
Next
Else
Err.Clear
If ExecPing = True Then
GetName
End If
End If

objCreate.WriteLine(objResult & ": " & Now)

Loop

objFile.Close
objCreate.Close

wscript.echo "The output has been saved into the file 'results.txt'."

End Function
If I hard code the path, it works fine, but I can't get it to specify from the command prompt!

Any ideas?
  Reply With Quote
Old 01-05-2007, 10:37 AM   #2
 
NetworkGeezer's Avatar
 
Join Date: Feb 2006
Posts: 1,194
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 0 NetworkGeezer is an unknown quantity at this point
Default Re: VBScript

It's Wscript.Arguments (as in the plural of argument )

In any case Wscript.Arguments is a collection and you are using it in the context of a text string.
  Reply With Quote
Old 01-05-2007, 10:48 AM   #3
 
StewartKnight's Avatar
 
Join Date: Jun 2005
Posts: 1,433
Thanks: 0
Thanked 7 Times in 7 Posts
Rep Power: 12 StewartKnight will become famous soon enough
Default Re: VBScript

I understand why it's not working, what I can't figure is how to get it working
  Reply With Quote
Old 01-05-2007, 10:58 AM   #4
 
NetworkGeezer's Avatar
 
Join Date: Feb 2006
Posts: 1,194
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 0 NetworkGeezer is an unknown quantity at this point
Default Re: VBScript

Assuming that the file name is the first argument then you could do this

Code:
strReadFile = WScript.Arguments(1)
set objFile = objFSO.OpenTextFile(strReadFile, 1)
  Reply With Quote
Old 01-05-2007, 10:59 AM   #5
 
StewartKnight's Avatar
 
Join Date: Jun 2005
Posts: 1,433
Thanks: 0
Thanked 7 Times in 7 Posts
Rep Power: 12 StewartKnight will become famous soon enough
Default Re: VBScript

I think I've got it, I changed it to an inputbox to get the filename!
  Reply With Quote
Old 01-05-2007, 11:04 AM   #6
 
NetworkGeezer's Avatar
 
Join Date: Feb 2006
Posts: 1,194
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 0 NetworkGeezer is an unknown quantity at this point
Default Re: VBScript

Ok and before anyone says it, yes I know the subscript should be 0 and not 1 for wscript.arguments ops:
  Reply With Quote
Reply

Register now for FREE and post messages!


Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Birthday:      
Image Verification
  I agree to forum rules 

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript Error sqdge Scripts 20 13-09-2007 03:34 PM
VBScript / SQL Server Gatt Scripts 5 23-05-2007 02:12 PM
another VBScript question! StewartKnight Coding 4 03-05-2007 05:41 PM
vbscript arguements ? mac_shinobi Scripts 1 20-02-2007 11:29 PM
Printer vbscript ? mac_shinobi Scripts 1 14-09-2005 08:21 AM



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search Thread
Search Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 08:01 PM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
Copyright EduGeek.net