One thing you can do in your application is to check if you are working as the right user, and if not, create a new instance of your application as that other user. The first instance will then exit.
, , , .
CreateProcessWithLogonW, LOGON_WITH_PROFILE. , , , .
EDIT: , , .NET, :
, . WindowsIdentity System.Security.Principal. GetCurrent WindowsIdentity , . Name , .
ProcessStartInfo LoadUserProfile = true, FileName, , Arguments, UserName Password, , Domain UseShellExecute = false. Process.Start(), ProcessStartInfo.
, , # :
using System;
using System.Diagnostics;
using System.Security;
using System.Security.Principal;
class TestApp
{
static void Main( string[] args )
{
string userName = WindowsIdentity.GetCurrent().Name;
if( !userName.Equals( "foo" ) ) {
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "testapp.exe";
startInfo.UserName = "foo";
SecureString password = new SecureString();
password.AppendChar( 'b' );
password.AppendChar( 'a' );
password.AppendChar( 'r' );
startInfo.Password = password;
startInfo.LoadUserProfile = true;
startInfo.UseShellExecute = false;
Process.Start( startInfo );
return;
}
}
}