views:

58

answers:

2

I have a child process I spawn from my main application that needs to be run as another local user on a Windows 7 machine. I would prefer to not set a password on that user account, but it seems that creating a new process with impersonation does not allow for blank passwords or any type of null values. Anyone know if this is possible?

below was my attempt with passing a blank char:

ProcessStartInfo info = new ProcessStartInfo(@"C:\PathToExecutable");
System.Security.SecureString psswd = new System.Security.SecureString();
psswd.AppendChar('\0');
psswd.MakeReadOnly();

info.UseShellExecute = false;
info.UserName = "NewProcessName";
info.Password = psswd;
info.Domain = "LocalMachine";

Process newProc = new Process();
newProc.StartInfo = info;

newProc.Start();

edit: The error message I recieve

Logon failure: user account restriction. Possible reasons are blank passwords not allowed, logon hour restrictions, or a policy restriction has been enforced

+1  A: 

What are you using to impersonate? LogonUser() should allow a blank password.

I don't think calling psswd.AppendChar('\0') is the right way to specify a blank password. Try removing the SecureString from your code to see if you can at least make the impersonation work. Then add the SecureString back in to see if your problem lies there.

* Edit *

Try this:

unsafe {
    char* ary = stackalloc char[0];
    SecureString str = new SecureString(ary, 0);
}

set info.Password to your new SecureString... not sure if you'll have to do that within the unsafe context or not.

James B
If I either choose to not specify any password (omitting `StartInfo.Password`) I receive the same message. If I go into control panel and modify the User Account and add a password (used the character 'A' for testing), I can pass 'A' as a password through the SecureString and that works fine. Just didn't want to have to set a password...
kmfk
Have you tried calling the overloaded Start() that takes a username, pw, and domain, and passing a blank password there? I'd expect the same result, but leaving no stone unturned...
James B
The issue is that StartInfo.Password is a `System.Security.SecureString`, so even the overloaded `Start()` requires `System.Security.SecureString` and not just a string, which can not be blank.Im pretty close to just setting the dummy password and moving on, the account doesn't need to be protected, its sole purpose is for this impersonation, so a '123' password is fine. Im just surprised that you can have a User Account with no password, but can not send a blank password here.
kmfk
I gave your last edit a shot and got the same error. For the time being, Im gonna assume that you NEED to have a password specified.
kmfk
That stinks : ( Sorry I couldn't come up with an answer!
James B
A: 

As this question points out, set LoadUserProfile to true in StartInfo. Try that out, it might help.

Matthew Ferreira
Yeah, looked through the other post - the executable I am running is also my own - does not rely on User Profiles. Thanks though.
kmfk