2016-08-01 14 views
-1

Ich habe Windows-Formular-Anwendung, die im Administrator-Modus ohne Bearbeitung der app.manifest-Datei ausgeführt werden muss. Habe den unten stehenden Code, weiß aber nicht, wo ich den Code in der Windows-Formularanwendung platzieren soll.Windows Form App im Adminstrator-Modus

ProcessStartInfo proc = new ProcessStartInfo(); 
    proc.UseShellExecute = true; 
    proc.WorkingDirectory = Environment.CurrentDirectory; 
    proc.FileName = Application.ExecutablePath; 
    proc.Verb = "runas"; 
    Process.Start(proc); 
    Application.Exit(); // Quit itself 
+0

Warum wird Änderungen an dem Code „leichter“ zu machen, als nur die offensichtlichen Änderungen vornehmen? –

Antwort

0

Diesen Code in dir Hauptform Ladevorgang

private void Form1_Load(object sender, EventArgs e) 
     { 

      ProcessStartInfo proc = new ProcessStartInfo(); 
      proc.UseShellExecute = true; 
      proc.WorkingDirectory = Environment.CurrentDirectory; 
      proc.FileName = Application.ExecutablePath; 
      proc.Verb = "runas"; 
      Process.Start(proc); 
      Application.Exit(); // Quit itself 
     } 
+0

Wo muss ich den obigen Code platzieren? – VJL

+0

Sie möchten also die Anwendung selbst als Administrator ausführen keine andere Anwendung ausführen? – Mostafiz

+0

Ja, ich möchte die Anwendung im Administratormodus ausführen. Wie mache ich es mit C# – VJL