• 0

VB.NET->Capture Output of CMD Utility?


Question

I am writing an Application in VB.NET. One component of the application is to list the server uptime. If there is a better way to do this let me know, but as for now I am using the "uptime.exe" from Microsoft. Here is the snippet of code that I am using:

Dim uptime As String

uptime = Shell("uptime " & srv2.ServerName)

I am fairly new to running commands through a VB.NET App, so I may be incorrect in some of my statements.

From my research there is no control within VB.NET to gather the Uptime on a Remote System. This is why I have opted to use the "uptime.exe" from Microsoft. Unfotunately when I run the app I receive what appears to be a random 4 digit number for my string "uptime". I am assuming this is some type of return code the "uptime.exe" throws back once it is complete. Obviously this isn't what I want. I need to know how to grab the output from the command. After that I will have to deal with formatting.

Any help would be appreciated.

Link to comment
https://www.neowin.net/forum/topic/273302-vbnet-capture-output-of-cmd-utility/
Share on other sites

7 answers to this question

Recommended Posts

  • 0
  KrAzY said:
I am writing an Application in VB.NET.  One component of the application is to list the server uptime.  If there is a better way to do this let me know, but as for now I am using the "uptime.exe" from Microsoft.  Here is the snippet of code that I am using:

Dim uptime As String

uptime = Shell("uptime " & srv2.ServerName)

I am fairly new to running commands through a VB.NET App, so I may be incorrect in some of my statements.

From my research there is no control within VB.NET to gather the Uptime on a Remote System.  This is why I have opted to use the "uptime.exe" from Microsoft.  Unfotunately when I run the app I receive what appears to be a random 4 digit number for my string "uptime".  I am assuming this is some type of return code the "uptime.exe" throws back once it is complete.  Obviously this isn't what I want.  I need to know how to grab the output from the command.  After that I will have to deal with formatting.

Any help would be appreciated.

585317107[/snapback]

You can use WMI to get the uptime of a remote server.

I know this example is script, but it is VB script so it should port easily.

http://www.microsoft.com/technet/scriptcen...04/hey0907.mspx

  • 0
  Cephas said:
You could try piping the output to a file, like so:

cmd /C uptime servername > c:\test.txt

Then just read that file's contents.

585317403[/snapback]

I thought of this idea, but that would require me parsing a text file after the output and I would rather not rely on creating another file and parsing it. I would rather it be internal to the program.

  weenur said:
You can use WMI to get the uptime of a remote server.

I know this example is script, but it is VB script so it should port easily.

http://www.microsoft.com/technet/scriptcen...04/hey0907.mspx

585317411[/snapback]

I knew this was possible, and haven't experimented with it. The only issue that might be an issue is speed. I believe running 'uptime.exe' is alot faster then trying to invoke WMI properties.

  Andareed said:
If you just want the uptime, you can use the win32 api GetTickCount.

585317881[/snapback]

When I was investingating this issue I found GetTickCount, but I don't think I can use it to remotely query servers. I believe that command can only be used on the system in which the program is running on.

WMI is probably the best idea at this point, but as stated earlier it may be alot slower then using 'uptime.exe' or some other method.

I will experiment with WMI and report back, but other suggestions would be appreciated, and please let me know if I am incorrect in my statements above.

Thanks

  • 0
  KrAzY said:
I knew this was possible, and haven't experimented with it.  The only issue that might be an issue is speed.  I believe running 'uptime.exe' is alot faster then trying to invoke WMI properties.

585318664[/snapback]

To be honest, uptime.exe probably utilizes WMI itself ;) In general, APIs are faster than external programs (Y)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • A few things I am wondering about for S3: A.  What's Pike doo gonna look like this time around....yea I've watched the trailers & it looks poofed up, but still.... B. When will the unintelligible, physco-babbling Pelia go away (or at least learn how to speak English properly, without that crappy, slurred accent that sounds like she's on crack, Mary Jane, & LSD at the same time) ?  Hopefully Scotty's arrival will mean her departure is near.... C.  When do we get to see more of the stunningly gorgeous No. 1, preferably in regular/civilian clothes that show off her physical attributes better ? D. Is Spock EVER gonna get laid properly, human style ?  I feel certain that Christine could make any Vulcan-human horizontal bomp a thing to remember for a LONG time  E.  Can we PLEEEEEEZE get rid of the hatchet-head/buzz cut hair styles on Ortega & anyone else that has it....  But otherwise, as Pike says:  HIT IT !  
    • RIP Hotlips..... IMHO, her best scenes were the few where she dared to let her REAL feminine side show through from underneath all that crappy, worn-torn soldier facade that she had to keep up with...she instantly lit up every room or situation where she was featured !
    • Helium Converter 3.3.69.0 by Razvan Serea Helium Converter is a free Windows utility for converting audio files between formats such as MP3, FLAC, AAC, WMA, OGG, and WAV. It supports batch conversion, preserves or updates tag information, and offers features like volume normalization. With a simple interface, it's ideal for users who need to convert large music libraries quickly and efficiently while retaining metadata. Helium Converter key features: Supports file formats: MP3, MP4, FLAC, AAC, M4A, WMA, WAV, OGG, OPUS, APE.... Batch conversion for large music libraries Preserves and edits metadata (ID3, Vorbis Comments, etc.) Volume normalization to equalize loudness Album art extraction and embedding Drag-and-drop interface for quick file selection Adjustable encoding parameters (bitrate, sample rate, channels) Uses internal codecs for consistent performance Supports CUE sheets for split track conversion File renaming based on tags during export Unicode support for international file and tag names Logging of conversion processes for troubleshooting Multi-core CPU support for faster conversions Download: Helium Converter 3.3.69.0 | 25.1 MB (Freeware) Links: Helium Converter Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Since it's been quite a while since the last episode aired, would it be fair (or cruel) to refer to Peggy as a MILF, or even a SMILF ?  HAHAHAHAHAHA
    • Their computers are not gonna stop working in October
  • Recent Achievements

    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
    • Reacting Well
      sultangris earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      172
    2. 2
      ATLien_0
      122
    3. 3
      snowy owl
      121
    4. 4
      Xenon
      117
    5. 5
      +Edouard
      93
  • Tell a friend

    Love Neowin? Tell a friend!