• 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

    • MacBook Air M3 with 512GB SSD and 16GB RAM is now available for just $899 by Taras Buria Apple is infamous for its eye-watering storage and RAM upgrade prices in Macs, iPads, and iPhones. However, there is no denying that the company makes great hardware, especially for Macs with their powerful and efficient chips. If you want an affordable Mac with more than just 256GB of storage, check out this deal on the 2024 MacBook Air M3 with 512GB SSD and 16GB of RAM, which is now available for only $899 ($600 off the original MSRP). The MacBook Air needs no introduction. This 13-inch laptop with a full-metal body has a solid Liquid Retina display, a powerful eight-core M3 processor with a 10-core graphics, and a battery that lasts all day (Apple claims up to 18 hours of video playback). The chip supports Apple Intelligence features such as image generation, writing tools, ChatGPT integration with Siri, and more. It can also drive two external 5K displays with the lid closed (or one display with the lid open). The laptop also has a backlit keyboard with a fingerprint sensor, a massive haptic trackpad, a 1080p webcam (in the notch), and a powerful quad-speaker audio system with Spatial Audio support. Available ports include MagSafe for magnetic charging, a headphone jack, and two Thunderbolt 4 Type-C ports. All of that is packed into a half-inch-thick lightweight chassis that is easy to carry around. 2024 13-inch MacBook Air M3, 16GB, 512GB - $899 | 31% off on Amazon This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • This game is already dead and we all know it. "delayed indefinitely" my a**...
    • That's why it really depends to what extent they've tweaked it and if you can just easily switch to full Windows if you want. I'm sure lots of people who just game on their devices with some light web browsing etc, would love to have this Xbox version as a option though. It really depends on what you do with your device. Maybe they're only going to offer it to specific gaming devices like handhelds or mini-PCs you can put under your TV?
  • Recent Achievements

    • First Post
      Ian_ earned a badge
      First Post
    • Explorer
      JaviAl went up a rank
      Explorer
    • Reacting Well
      Cole Multipass earned a badge
      Reacting Well
    • Reacting Well
      JLP earned a badge
      Reacting Well
    • Week One Done
      Rhydderch earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      665
    2. 2
      ATLien_0
      267
    3. 3
      Michael Scrip
      217
    4. 4
      +FloatingFatMan
      188
    5. 5
      Steven P.
      145
  • Tell a friend

    Love Neowin? Tell a friend!