Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-06-17
3
845 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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