I'm trying to write an application that runs the Draytek VPN client as another user as I don't want the user to have an admin password and their account is a standard user. However I can't get it working due to errors in both implementations I've tried.
Here is some sample code I've tried:
System.Security.SecureString ss = new System.Security.SecureString();
foreach (var c in "password")
{
ss.AppendChar(c);
}
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.WorkingDirectory = "c:\\";
process.StartInfo.FileName = @"C:\Program Files (x86)\DrayTek\Smart VPN Client\SmartVPNClient.exe";
process.StartInfo.Verb = "runas";
process.StartInfo.UserName = "testUser";
process.StartInfo.Password = ss;
process.StartInfo.UseShellExecute = false;
process.Start();
I get the error: The requested operation requires elevation.
I have also tried Impersonation using the code in the question, Impersonating a Windows user. My implementation of the call is below:
using ( new Impersonator( "testUser", "", "password" ) )
{
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.WorkingDirectory = "c:\\";
process.StartInfo.FileName = @"C:\Program Files (x86)\DrayTek\Smart VPN Client\SmartVPNClient.exe";
process.StartInfo.Verb = "runas";
process.Start();
}
However the error from running the above code is Unknown error (0xfffffffe).
I can provide more error details if required.