I am trying to run WMIC as Admin via my program, using the following code works, but only if WMIC.exe is allready run as an administrator, otherwise it will just return an empty HTML. I can't seem to find a related issue on stackoverflow or elsewhere... Does anyone see the issue here?
My method for converting the securestring:
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");