Click here to Skip to main content
15,894,039 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello.
I´ve a problem trying to execute some app using Process class. I´ve 2 applications the first-one execute the 2nd, it works just fine, the problem begins when i use the registry key Run to execute the first-one first, then the 2nd doesn´t execute. The real problem occurs when i try to execute the 2nd with a specific user passed to the Process using StartInfo.UserName and StartInfo.Password.

Thanks in advance, I´ll really appreciate any help. sorry my English, it´s not my native language.
Posted
Updated 20-Feb-12 8:12am
v3
Comments
Sergey Alexandrovich Kryukov 20-Feb-12 14:20pm    
What is a "program executed from Registry"? What is suppose to mean?
What is "user passed to the Process"?

Could you show some (short!) code sample?
--SA
glbrt.gds 20-Feb-12 16:23pm    
Sorry, I wasn´t clear, let me be more specific.
My real problem is how to execute a program and let it run on a diferent user than the logged user, I´ve create a Local User account with administrative rights and over this account I want to let my program run. Then i wrote a program that shuld execute the other that I want to run over a diferent account, the account that I´ve told before. This first program(the one that execute the real program) is execute at windows start, to do that I put in windows registry in Run key the direction of the first-one, this first-one is execute at windows start but it throw an error when it tryes to execute the real program over a diferent account than the logged-one, the code seems like that:

try
{
Process proc = new Process();
proc.StartInfo.FileName = "programdir";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.UserName = "localAdministratorUser";
proc.StartInfor.Password = GetPass();
proc.Start();
}
catch(Exception e){e.Message();}

The error message is: Invalid directory name
But the directory name is fine, if I just execute by clicking this first .exe, it execute the 2nd very well over the account that I´m specifying in the code. It´s realy crazy to me.
pietvredeveld 20-Feb-12 17:28pm    
Are you using the full path for the application to start, or a relative path? The difference between starting the first application from the explorer and start from the registry is the working folder. Make sure you pass the absolute path to the StartInfo.


Regards,
Piet
glbrt.gds 21-Feb-12 15:35pm    
Yes, I'm using the full path (c:\windows\file.exe) for example, I've checked it out.Even I've used it explicity It seems really extrange to me, it just doesn't work.... sorry my English please.
ZurdoDev 20-Feb-12 14:29pm    
So, what is the error? What is the problem?

1 solution

Everything launched out of the Run key runs at user login time and runs as the user logging in.

Your app may be running. Open Task Manager to find out.

If your App1 is launching App2 as a different user, this could be a problem. I don't know if that user will be able to see the application. Again, check in Task Manager and you can see who the app is running as.
 
Share this answer
 
Comments
glbrt.gds 20-Feb-12 16:25pm    
The first app is executed but it can´t execute the second, it´s realy frustrating for me. :(
Dave Kreskowiak 20-Feb-12 18:24pm    
This is where you have to instrument your App1 code to make sure it is using the fully qualified path to App2.exe and successfully launches it without ignoring any return values or swallowing any exceptions.

Have your App1 code log everything it's doing and getting back to a .LOG file somewhere.
glbrt.gds 21-Feb-12 15:43pm    
My App1 doesn't log anything, at least I'm not doing it.
If I logged as administrator or any account with administrative privileges it goes fine, all works, then how could be the direction wrong, am I getting crazy?.
Dave Kreskowiak 21-Feb-12 21:03pm    
Grrr...This is where you have to put the logging code into your App1 to see what's going on!
glbrt.gds 22-Feb-12 8:43am    
I'm really sorry because maybe I don't understand you, what you mean with "to put the logging code into App1", I've trace it and the error that app1 is throwing is Invalid directory name, I've even verify into my App1 using Directory class members or FileInfo class and the path to the file, even the file is correct and it is there, I've checked it all from my App1. Other thing that I've done is Impersonated(I don't know if It is correctly written) in my App1 I've logged as administrator and then the message error change to: You have not enough privileges, one of the craziest thing I've ever seen, how couldn't have enough privileges from an administrator account... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900