Solved

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

Posted on 2008-06-17
3
841 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
ID: 21823372
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
ID: 21827052
Thank you so much! Solved it straight away.
0
 

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Both in life and business – not all partnerships are created equal. Spend 30 short minutes with us to learn:   • Key questions to ask when considering a partnership to accelerate your business into the cloud • Pitfalls and mistakes other partners…

911 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

18 Experts available now in Live!

Get 1:1 Help Now