Strange behaviour with ProcessStart

M

mcw.willart

Hi,

I notice some strange behaviour with Process.start; when I start an
mmc-console,
e.g. Process.Start("c:\\tools\\AdminConsole.msc"); everything works
fine, but when I try to start it with the following code (using a
username and password) I get "The specified executable is not a valid
Win32 application".

ProcessStartInfo myProcess = new ProcessStartInfo("AdminConsole.msc");
myProcess.UserName = strUserName;
myProcess.Password = password;
myProcess.Domain = "<domain>";
myProcess.FileName = "AdminConsole.msc";
myProcess.UseShellExecute = false;
Process.Start(myProcess);

Anyone any idea?

Greetings,

Mario
 
J

Jon Skeet [C# MVP]

Hi,

I notice some strange behaviour with Process.start; when I start an
mmc-console,
e.g. Process.Start("c:\\tools\\AdminConsole.msc"); everything works
fine, but when I try to start it with the following code (using a
username and password) I get "The specified executable is not a valid
Win32 application".

myProcess.UseShellExecute = false;

This line is your problem.

Change it to true instead, and it'll be fine.

Jon
 
M

mcw.willart

This line is your problem.

Change it to true instead, and it'll be fine.

Jon

Jon,

I tried your suggestion, but then I get "The Process object must have
the UseShellExecute property set to false in order to start a process
as a user".

Mario
 
W

Willy Denoyette [MVP]

Hi,

I notice some strange behaviour with Process.start; when I start an
mmc-console,
e.g. Process.Start("c:\\tools\\AdminConsole.msc"); everything works
fine, but when I try to start it with the following code (using a
username and password) I get "The specified executable is not a valid
Win32 application".

ProcessStartInfo myProcess = new ProcessStartInfo("AdminConsole.msc");
myProcess.UserName = strUserName;
myProcess.Password = password;
myProcess.Domain = "<domain>";
myProcess.FileName = "AdminConsole.msc";
myProcess.UseShellExecute = false;
Process.Start(myProcess);

Anyone any idea?

Greetings,

Mario


Make it:

myProcess.FileName = "mmc.exe";
myProcess.Arguments = "c:\\tools\\AdminConsole.msc";

Willy.
 
J

Jon Skeet [C# MVP]

I tried your suggestion, but then I get "The Process object must have
the UseShellExecute property set to false in order to start a process
as a user".

In that case you'll need to specify the executable to use, as per
Willy's post.

Jon
 
C

Christof Nordiek

Jon,

I tried your suggestion, but then I get "The Process object must have
the UseShellExecute property set to false in order to start a process
as a user".

You've got to call the exe directly with aproppriate command line
parameters. The shell-execution doesn't work with password and username. I
don't know why, but that's what the docs say.

Christof
 
M

mcw.willart

Make it:

myProcess.FileName = "mmc.exe";
myProcess.Arguments = "c:\\tools\\AdminConsole.msc";

Willy.- Hide quoted text -

- Show quoted text -

Willy,

that did the trick! I had to pass the msc as an argument, I didn't
know that.

Thanks,

Mario
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top