我试图通过我的程序运行WMIC作为管理员,使用以下代码工作,但仅当WMIC.exe已经作为管理员运行时,否则它将只返回一个空的HTML。我似乎无法在stackoverflow或其他地方找到相关问题......有没有人在这里看到这个问题?
我转换securestring的方法:
SecureString secureString = new SecureString();
foreach (char ch in str)
{
secureString.AppendChar(ch);
}
secureString.MakeReadOnly();
return secureString;
起始码:
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");