简体   繁体   English

Process.start()WMIC.exe密码问题

[英]Process.start() WMIC.exe password issue

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. 我正在尝试使用以下代码通过我的程序以管理员身份运行WMIC,但仅当WMIC.exe已经以管理员身份运行时,否则,它将仅返回空HTML。 I can't seem to find a related issue on stackoverflow or elsewhere... Does anyone see the issue here? 我似乎在stackoverflow或其他地方找不到相关的问题……有人在这里看到此问题吗?

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");

Found the problem, this was due to a Win7 bug of WMIC. 找到了问题,这是由于WMIC的Win7错误。 To fix this, you can copy all the *.xsl files of C:\\Windows\\System32\\wbem\\en-US to the application startup path (or elsewhere) and link to it like this: 要解决此问题,您可以将C:\\ Windows \\ System32 \\ wbem \\ zh-CN的所有* .xsl文件复制到应用程序启动路径(或其他位置),并按如下所示链接到该文件:

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

Possible dupe for wmic error (invalid XSL format) in windows7 Windows7中可能出现wmic错误(无效的XSL格式)错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM