Domanda

In un'applicazione devo eseguire altri programmi con le credenziali di un altro utente. Attualmente utilizzo System.Diagnostics.Process.Start per eseguire il programma:

public static Process Start(
   string fileName,
   string arguments,
   string userName,
   SecureString password,
   string domain
)

Tuttavia, questa funzione non carica il profilo comune dalla rete, il che è necessario.

Potrei usare " runas / profilo ... " per caricare il profilo ed eseguire il comando, ma ciò richiederebbe una password. Deve esserci un modo più elegante ...

Ma dove?

Altri suggerimenti

La mia soluzione (basata sul suggerimento di leppie):

        Process p = new Process();

        p.StartInfo.FileName = textFilename.Text;
        p.StartInfo.Arguments = textArgument.Text;
        p.StartInfo.UserName = textUsername.Text;
        p.StartInfo.Domain = textDomain.Text;
        p.StartInfo.Password = securePassword.SecureText;

        p.StartInfo.LoadUserProfile = true;
        p.StartInfo.UseShellExecute = false;

        try {
            p.Start();
        } catch (Win32Exception ex) {
            MessageBox.Show("Error:\r\n" + ex.Message);
        }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top