Query remote PC Service State - Results in GUI

Posted on 2011-10-13
Last Modified: 2012-06-27
I have a batch file that I am using to verify the service state of a specific service on numerous computers.  The output is displayed within a command window.

How can this same idea be put into a standalone executable where I can enter the names of the computers that I wish to query on the status of any service?  I'd like to have the output displayed within the window of a GUI too (instead of relying on the command windows).

Any takers out there?
Question by:tru504187211
    LVL 37

    Accepted Solution

    What methods do you have available to use? Do you have Visual Studio so you can use Windows forms or something?

    You could also embed the code in an Excel document and use either userforms or the spreadsheet for input and output.

    vbScript would be another option since any computer running Windows will support it and you can use commands very similar to the ones you already know from the batch script.

    Author Comment

    I do not have VS...if need be, I'd be open to web files (like PHP, or .NET).

    Does this help??
    LVL 37

    Expert Comment

    Web files don't do well interfacing with the filesystem. I recommend VBScript.

    For starters, try this vbscript. Save the following code into a text file and save it as a .vbs file (like test.vbs)

    Then just double click it. I set it so that hitting cancel deletes the last computer name entered.

    Option Explicit
    Dim result
    Dim prompt
    Dim count, i
    Dim computers()
    Dim shell
    Dim output
    Set shell = WScript.CreateObject("WScript.Shell")
    prompt = ""
    result = ""
    output = ""
    count = 0
    While result <> "Done"
      prompt = ""
      For i = 1 To count
        prompt = prompt & computers(i) & chr(13) & chr(10)
      result = InputBox(prompt, "Enter Computers", "Done")
      If result <> "" And result <> "Done" Then
        ReDim Preserve computers(count + 1)
        count = count + 1
        computers(count) = result
      End If
      If result = "" and count > 0 Then
        ReDim Preserve computers(count - 1)
        count = count - 1
      End If
    For i = 1 To count
      shell.Run "%comspec% /c echo Put any DOS commands here", 0, True
    output = output & "Line 1" & chr(13) & chr(10)
    output = output & "Line 2" & chr(13) & chr(10)
    output = output & "Line 3" & chr(13) & chr(10)
    MsgBox output

    Open in new window

    LVL 37

    Expert Comment

    You can probably convert most of your .bat file code directly into VBScript, but you should post them as new questions in the VBScript zone (I'm not the best at DOS -> VBScript translation).
    LVL 10

    Expert Comment

    This could be done very easily in Powershell as well.  The popup is quite a bit easier in VBScript, but, Powershell is quite a bit more flexible.  It's also a lot wordier (meaning you tend to have to type more to accomplish the same thing).  Powershell is Visual Studio light in script form in my mind.  

    How do you specify the server list?  Is it in the script or manually entered somehow?

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    How to split this in C++ 4 54
    find a node in VST 2 37
    sumDigits  challenge 7 41
    Program to display an alert on Windows Toolbar 2 35
    Introduction This question got me thinking... ( Why shouldn't we use Globals? This is a simple question without a simple answer.  How do you explain these concepts to a programmer w…
    A short article about problems I had with the new location API and permissions in Marshmallow
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now