Jump to content

Recommended Posts

Posted

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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...