StewartKnight Posted May 1, 2007 Posted May 1, 2007 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 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?
NetworkGeezer Posted May 1, 2007 Posted May 1, 2007 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.
StewartKnight Posted May 1, 2007 Author Posted May 1, 2007 I understand why it's not working, what I can't figure is how to get it working
NetworkGeezer Posted May 1, 2007 Posted May 1, 2007 Assuming that the file name is the first argument then you could do this strReadFile = WScript.Arguments(1) set objFile = objFSO.OpenTextFile(strReadFile, 1)
StewartKnight Posted May 1, 2007 Author Posted May 1, 2007 I think I've got it, I changed it to an inputbox to get the filename!
NetworkGeezer Posted May 1, 2007 Posted May 1, 2007 Ok and before anyone says it, yes I know the subscript should be 0 and not 1 for wscript.arguments :oops:
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now