1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
private System.Diagnostics.Process StartNewProcessWithAdminCredentials(string executablePathAndName, string sUsername, string startArguments)
{
System.Diagnostics.ProcessStartInfo newProcessStartUpInfo;
try
{
if (startArguments != null)
{
newProcessStartUpInfo = new System.Diagnostics.ProcessStartInfo(executablePathAndName, startArguments);
}
else
{
newProcessStartUpInfo = new System.Diagnostics.ProcessStartInfo(executablePathAndName);
}
// Betriebsystem prüfen: XP oder höher (Vista = 6)
if (System.Environment.OSVersion.Version.Major >= 5)
{
newProcessStartUpInfo.Verb = "runas";
newProcessStartUpInfo.UseShellExecute = false;
newProcessStartUpInfo.Password = password;
newProcessStartUpInfo.UserName = sUsername;
return System.Diagnostics.Process.Start(newProcessStartUpInfo);
}
else
{
return System.Diagnostics.Process.Start(newProcessStartUpInfo);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
private void Button1_Click(object sender, EventArgs e)
{
this.StartNewProcessWithAdminCredentials(@"Pfad der zu startenden Anwendung", txtUser.Text, null);
}
private void txtPass_Enter(object sender, EventArgs e)
{
password.Clear();
}
private void txtPass_KeyPress(object sender, KeyPressEventArgs e)
{
password.AppendChar(e.KeyChar);
}
|