2016-04-06 13 views
0

Ich versuche, WMIC als Admin über mein Programm zu starten, mit dem folgenden Code funktioniert, aber nur wenn WMIC.exe bereits als Administrator ausgeführt wird, sonst wird nur ein zurückgeben leeres HTML. Ich kann nicht scheinen, ein in Verbindung stehendes Problem auf stackoverflow oder anderswo zu finden ... Sieht jemand das Problem hier?Process.start() WMIC.exe Passwort Problem

Meine Methode der Secure zum Umwandeln:

SecureString secureString = new SecureString(); 

foreach (char ch in str) 
{ 
    secureString.AppendChar(ch); 
} 

secureString.MakeReadOnly(); 
return secureString; 

Startcode:

string path = @"C:\Temp\"; 

if (!Directory.Exists(path)) 
{ 
    Directory.CreateDirectory(path); 
} 

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); 

startInfo.UseShellExecute = false; 
startInfo.FileName = "cmd"; 
startInfo.Domain = "EU"; 
startInfo.Verb = "runas"; 

startInfo.UserName = "Username"; 
startInfo.Password = GetSecureString("Password"); 

startInfo.Arguments = @"/k wmic.exe /node: " + "\"" + txt_input_computers.Text + "\" " + "/output:" + path + @"\" + txt_input_computers.Text + ".html " + DDL_WMIC.Text 
      + " list full /format:hform"; 

process.StartInfo = startInfo; 
process.Start(); 

process.WaitForExit(); 
Process.Start(path + @"\" + txt_input_computers.Text + ".html"); 
+0

Ihre Frage ist nicht klar. Wenn es WMI ist, lassen Sie mich Ihnen sagen, dass WMI im Admin-Modus ausgeführt werden muss. Starten Sie Visual Studio im Admin-Modus – Apoorv

+0

Entschuldigung, ich habe meine Frage umformuliert, siehe oben – DaBeast

Antwort

0

das Problem gefunden, das war aufgrund eines Win7 Bug von WMIC. Um dies zu beheben, können Sie kopieren alle * .xsl Dateien von C: \ Windows \ System32 \ wbem \ en-US auf die Anwendung Startpfad (oder anderswo) und Link, um es wie folgt aus:

 startInfo.Arguments = @"/k wmic.exe /node: " + "\"" + "computername" + "\" " + "/output:" + @"C:\Temp\outputfile.html " + "wmiattrib" + " list full /format:\"" + Application.StartupPath + "\\hform\""; 

Mögliche dupe für wmic error (invalid XSL format) in windows7