Solved

sc query > [filename] not working as a shell command in VB .NET... help?

Posted on 2008-06-17
3
839 Views
Last Modified: 2010-04-21
The command I am trying to run in VB .net is as follows:

Shell("sc query > " & Chr(34) & "C:\Dir Name\ServicesRunning.txt" & Chr(34))

The Directory name has spaces and needs to keep them. I have output that code to a label and it reads exactly as it should:

sc query > "C:\Dir Name\ServicesRunning.txt"

Why Isn't it working? I really don't want to resort to my stop gap solution of running an external batch file to execute the command.
0
Comment
Question by:npcs
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
Comment Utility
The redirection feature is really part of the command shell... so you need to alter your statement to look like  this:

Shell("cmd /c sc query > " & Chr(34) & "C:\Dir Name\ServicesRunning.txt" & Chr(34))
0
 

Author Comment

by:npcs
Comment Utility
Thank you so much! Solved it straight away.
0
 

Author Closing Comment

by:npcs
Comment Utility
While your here, is there any way in VB.net or shell to take a jpg screen shot?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

5 Experts available now in Live!

Get 1:1 Help Now