• 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

    • His true motives are clear: to make more money by taking advantage of his position and fame, and to feel big and important as he has always wanted. He's turning the US President position into his own personal brand to sell smoke and ###### products and services. The goal remains: money.
    • Crazy Taxi, Sonic CD, and other classic Sega games are now free on mobile devices by Taras Buria SEGA is discontinuing some of its classic games available on mobile devices in the App Store and Google Play Store. Users noticed that upon launch, some of the classic games that were previously ported to mobile devices via the SEGA Forever program (discontinued in 2023) now display a discontinuation message. However, the good news is that all those games are now available for free, so grab them while you can. SEGA has not made any official announcement yet, minus the in-game message, of course, so exact details remain unknown. There is no information on whether the publisher plans to remove those games from mobile stores. Still, it says that you can continue playing them offline: "Support for this game will be discontinued, but you can continue playing offline! If you’d like to learn more about great SEGA games to play, please click the link below." Should SEGA remove the games from stores, installed games will continue working without issues. With that said, SEGA is no stranger to delisting its games, so chances are that now-unsupported games will meet the same fate. Here are the games that previously cost $2 (or required in-app purchases) and are now available for free, presumably for a limited time. Grab them using the links below: Crazy Taxi Classic - App Store | Google Play Store Golden Axe Classics - App Store | Google Play Store Shining Force Classics - App Store | Google Play Store Sonic CD Classic - App Store | Google Play Store Sonic the Hedgehog 4 Ep.II - App Store | Google Play Store Streets of Rage 2 Classic - App Store | Google Play Store Super Monkey Ball: Sakura Ed. - App Store | Google Play Store Virtual Tennis Challenge - App Store | Google Play Store Source: Android Authority
    • Pick your administration and they all have their share of nonsense. If you look much at all, you can find crap and problems with all of them going back to the beginning. I think there are a lot people in Washington, D.C. right now or have been over the years that have been "domestic terrorists" and should have been in prison. Too many examples to even start naming here. I personally don't know what to think of Trump at this point as far his true motives, but I know he makes himself look bad and one of the best examples is this waffling around regarding TikTok.
    • Sayan’s trying to be creative and find ways to link previous articles together, it’s just word spaghetti…
    • I am waiting for it to hit Fedora in a day or two here.
  • Recent Achievements

    • Week One Done
      Rhydderch earned a badge
      Week One Done
    • Experienced
      dismuter went up a rank
      Experienced
    • One Month Later
      mevinyavin earned a badge
      One Month Later
    • Week One Done
      rozermack875 earned a badge
      Week One Done
    • Week One Done
      oneworldtechnologies earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      694
    2. 2
      ATLien_0
      274
    3. 3
      Michael Scrip
      215
    4. 4
      +FloatingFatMan
      189
    5. 5
      Steven P.
      145
  • Tell a friend

    Love Neowin? Tell a friend!