Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 860
  • Last Modified:

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

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
npcs
Asked:
npcs
  • 2
1 Solution
 
grayeCommented:
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
 
npcsAuthor Commented:
Thank you so much! Solved it straight away.
0
 
npcsAuthor Commented:
While your here, is there any way in VB.net or shell to take a jpg screen shot?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now