我需要在此代码后隐藏隐藏Windows主机脚本:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C slmgr.vbs /dlv";
process.StartInfo = startInfo;
process.Start();
有谁知道我怎么做到这一点?
答案 0 :(得分:1)
如果您正在谈论完全隐藏窗口,那么您将缺少设置CreateNoWindow
属性。
startInfo.CreateNoWindow = true;
使用 cscript.exe 执行VB脚本,而不是启动其他命令提示符。如果你这样做,你将不必担心shell如何执行你的vbs文件,你将不会得到一个额外的命令行窗口。
startInfo.FileName = "cscript.exe";
startInfo.Arguments = "slmgr.vbs /dlv";
如果创建此进程的可执行文件与slmgr.vbs不在同一目录中,则还需要在参数中设置文件的完整路径,或者设置进程运行的工作目录。
// Example path where your scripts could reside.
startInfo.WorkingDirectory = @"C:\PathToMyScripts\VBScripts\";
你可能也希望redirect the output,所以你可以在某处登录。
答案 1 :(得分:0)
谢谢你先生BrutalDev
第二步
改变startInfo.Arguments = "slmgr.vbs /dlv";
到startInfoent.Arguments = "C:\\Windows\\System32\\slmgr.vbs /dlv";