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
If I hard code the path, it works fine, but I can't get it to specify from the command prompt!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
Any ideas?
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.
I understand why it's not working, what I can't figure is how to get it working
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)
I think I've got it, I changed it to an inputbox to get the filename!
Ok and before anyone says it, yes I know the subscript should be 0 and not 1 for wscript.argumentsops:
There are currently 1 users browsing this thread. (0 members and 1 guests)