+ Post New Thread
Results 1 to 6 of 6
Coding Thread, VBScript in Coding and Web Development; I'm trying to write a script (stop sniggering at the back), which is going swimmingly ..... except...... I was to ...
  1. #1
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Posts
    1,587
    Thank Post
    2
    Thanked 27 Times in 21 Posts
    Rep Power
    30

    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
    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?

  2. #2

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    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.

  3. #3
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Posts
    1,587
    Thank Post
    2
    Thanked 27 Times in 21 Posts
    Rep Power
    30

    Re: VBScript

    I understand why it's not working, what I can't figure is how to get it working

  4. #4

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    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)

  5. #5
    StewartKnight's Avatar
    Join Date
    Jun 2005
    Posts
    1,587
    Thank Post
    2
    Thanked 27 Times in 21 Posts
    Rep Power
    30

    Re: VBScript

    I think I've got it, I changed it to an inputbox to get the filename!

  6. #6

    Join Date
    Feb 2006
    Posts
    1,187
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Re: VBScript

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

SHARE:
+ Post New Thread

Similar Threads

  1. VBScript / SQL Server
    By Gatt in forum Scripts
    Replies: 7
    Last Post: 23rd September 2011, 03:21 PM
  2. VBScript Error
    By sqdge in forum Scripts
    Replies: 20
    Last Post: 13th September 2007, 03:34 PM
  3. another VBScript question!
    By StewartKnight in forum Coding
    Replies: 4
    Last Post: 3rd May 2007, 05:41 PM
  4. vbscript arguements ?
    By mac_shinobi in forum Scripts
    Replies: 1
    Last Post: 20th February 2007, 10:29 PM
  5. Printer vbscript ?
    By mac_shinobi in forum Scripts
    Replies: 1
    Last Post: 14th September 2005, 08:21 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •