Click to See Complete Forum and Search --> : Running a Dos command string from .NET


itayc1
May 3rd, 2006, 02:10 PM
Hello All,

I am trying to run the following command from VB.NET with no success.

qwinsta.exe username > c:\username.txt

When I run this command from cmd window it works just fine and creates an output file (username.txt) in drive c:\

Any idea how to run such command from .NET ?

Thanks,

Itay

ChaosTheEternal
May 3rd, 2006, 03:02 PM
How are you trying to call it? If you're calling the exe directly and trying to pipe that, I don't think it'll work, as I don't think Windows understands ">" as wanting to pipe to a file.

I know this will work (Windows 2000/XP):
Process.Start("cmd.exe", "/C echo CodeGuru > C:\codeguru.txt")
Where:
cmd.exe is the process you want to run.
/C is a parameter to cmd.exe saying you want to run a command.
"echo CodeGuru > C:\codeguru.txt" is the string that will be run due to the usage of the /C parameter.

itayc1
May 3rd, 2006, 04:22 PM
Thanks a lot ChaosTheEternal.

Works great !!