Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts,
I'm using the following code to start a process. It works perfect for a domain user, but it does not work for a local user.

C#
using (SecureString password = new SecureString())
{
    string path = @"c:\temp\test\mytest.exe";

    foreach (char c in "test@mycomputer")
        password.AppendChar(c);
    string uname = "test";
    string domain = Environment.MachineName;
    Process.Start(path, uname, password, domain);
}


The error message is: Invalid Directory.
[EDIT]
This happens if I'm loged in as domain user and try to do the above...but runas /user:test c:\temp\test\mytest.exe works.
[/EDIT]


Any idea?

Thank you in advance.
Bruno
Posted
Updated 5-Nov-14 2:44am
v3
Comments
KaushalJB 5-Nov-14 8:23am    
Does your local user have permission in worker process ?
[no name] 5-Nov-14 8:35am    
Yes it has. I updated the question with a maybe important circumstance.
KaushalJB 5-Nov-14 9:08am    
As per your chat... its for sure the local user needs Full Control to the Drive itself and subpath too.
ZurdoDev 5-Nov-14 8:31am    
Either the directory does not exist where the code is running or the permissions are not enough.
[no name] 5-Nov-14 8:35am    
I updated the question with a maybe important circumstance.

Most probably access rights. Ensure that your local user can read the directory and its content.
 
Share this answer
 
Comments
[no name] 5-Nov-14 17:07pm    
Thanks for answering. No it is not a pb of Access rights.
Try passing an empty string as the domain parameter:
C#
Process.Start(path, uname, password, string.Empty);

The documentation[^] isn't entirely clear, but it does say the the domain is the "Active Directory domain to use when starting the process". Your computer name isn't the name of an Active Directory domain.
 
Share this answer
 
Comments
[no name] 5-Nov-14 8:40am    
Thanks for replying. I allready tried with empty Domain, with "." with ".\" with "machinname" with "machinename\".

And thanks for the link...active dir I Need to check.
I hesitate to post as a solution as this is only a guess. I think the difference between the command prompt "RunAs" and Process.Start is the handling of the user profile. RunAs loads the target user profile by default whereas the Process.Start does not. This probably means that the "Default User" profile will be loaded.

To test the hypothesis try RunAs with the /Noprofile switch or provide a ProcessStartInfo with LoadUserProfile = true for your Process.Start.

Alan.
 
Share this answer
 
Comments
[no name] 5-Nov-14 11:15am    
Hello Alan
Thank you very much for your hint. I tested "runas /noprofile ..." and you guess right, it also does not work!

I will test with ProcessStartInfo and come back with the results.

Anyway I will accept this answer after I completed my tests.

Thanks again. Bruno

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