• 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

    • Movavi Video Editor 25.9.0 by Razvan Serea With Movavi Video Editor, you can either enhance your video files with two or three simple steps, or turn them into something completely new. Create your own movies using multiple filters, transitions, and special effects: show multiple videos on one screen with the Picture in picture effect or change the background with the Chroma Key effect, imitate the camera zoom or make your video look like an old-style movie. Adjust video parameters such as brightness, contrast and colors. Stabilize shaky footage, improve video quality and remove defects. Create video presentations, tutorials or educational videos: add titles and record your own narration to create a video with voiceover. Import video from any source: TV-tuner, webcam, camcorder, or VHS. Drop multiple media files onto a timeline and let your imagination do the rest! Features at a glance: Video and audio editing on a timeline Edit, enhance videos Add background music Apply titles and effects Image quality improvement Hollywood-worthy effects High-grade titles and fades Digitize VHS tapes, record video from TV tuners Stabilize any shaky sections Support for a wide range of formats Prepare your videos for uploading to YouTube, Facebook, Vimeo, or any other website New in Movavi Video Editor 2025: Revamped timeline for easier editing The new timeline is now clearer and more streamlined. Get your projects done faster and have more fun with anything – from short vids for socials to longer family movies. Frame-precise cuts in a click Give your videos a sharper look with the new Blade tool. Easily make precise cuts and create eye-catching montages like your favorite bloggers. Pro-quality color correction Get next-level color correction with the same simplicity. Boost colors in a snap and make more viewers fall in love with your videos. AI motion tracking Enhance reality in your videos with additional moving graphics. Just click, and AI will quickly attach any photos, videos, emojis, or memes to objects in your footage. Perfect-match overlay effects Now each overlay effect has 13 blending modes to choose from. Try each of them with the press of a button and pick the one that fits your video perfectly. Best video effects – at your fingertips Create awesome videos in any style with our huge collection of professionally designed effects. Now you can try them all right away, right in the app. Movavi Video Editor 25.9.0 changelog: New Copy effects from one clip to another in a snap. Just right-click the clip → Clip effects → Copy effects. Then right-click again to paste. Try it once, and it might just become your new favorite feature. Improvements Enjoy speedier, smoother previews – now up to 20% faster! Hover over any clip to see the difference. Especially handy when you’ve got a load of clips on the timeline. Speed up editing with new keyboard shortcuts. Ctrl + Z to undo, Ctrl + scroll to zoom the timeline. You’ll find the full list in the Help menu. Fixed issues Some under-the-hood improvements that’ll be useful for faster content creation. Download: Movavi Video Editor Plus 25.9.0 | 5.1 MB (Shareware) View: Movavi Video Editor Plus Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I don't disagree, but I am also not absolving Microsoft. Data protection is the user's responsibility AND OneDrive shouldn't arbitrarily lockout paying users with no way to get support. Again, both statements can be true at the same time. I doubt you mean to imply it is okay for companies to violate their SLAs and screw over their customers. Assuming you don't think that, then we have no disagreement my friend.
    • Also, Microsoft locks Windows 11 user out, shows how easy losing data from forced encryption is The reddit post has nothing to do with Windows 11 or 'Forced' Encryption, at all, reading the thread a guy has uploaded a load of files, deleted the source, tripped the ToS for some reason and been locked out The guy could have been using Windows 7 box with no drive encryption. A more accurate headline would be User with no backup looses data
    • I've been using Microsoft cloud storage since before it was named OneDrive. Though typically only upload the following items. Game Screenshots of like crashes if its a driving game, or occasionally a Video recorded with GameDVR All Purchased Music from former Microsoft App store when they offered music during Windows 8.1, Xbox/Groove Music days, in additon to the 30 Free Albums Christmas 2024 for using a Windows Phone at the time. Of course everything is also backed up on 3 external hard drives as well. and albums that would be hard to replace, also uploaded to GoogleDrive, ((though can't upload all of it to Google drive, as not enough space there to lol)) Been using Microsoft Hotmail & Outlook email ever since first released Hotmail originally signed up April 1998 during high school class Outlook.com email converted to when first launched many years ago
  • 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
      699
    2. 2
      ATLien_0
      272
    3. 3
      Michael Scrip
      214
    4. 4
      +FloatingFatMan
      186
    5. 5
      Steven P.
      144
  • Tell a friend

    Love Neowin? Tell a friend!