Strange behaviour with ProcessStart

  • Thread starter Thread starter mcw.willart
  • Start date Start date
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
 
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
 
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
 
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.
 
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
 
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
 
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

Back
Top