C# 通过代码以管理员身份打开 cmd 并更改字体和背景颜色



正在尝试更改cmd窗口的颜色。 这行不通?

             ProcessStartInfo p1 = new ProcessStartInfo();
             p1.Verb = "runas";
             p1.FileName = "cmd.exe";
             p1.Arguments = "color 80";
             Process.Start(p1);

添加/K

ProcessStartInfo p1 = new ProcessStartInfo();
p1.Verb = "runas";
p1.FileName = "cmd.exe";
p1.Arguments = "/K color 80";
Process.Start(p1);

推理:COLOR是"内部命令"。

执行以下操作:

Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = "/T:17"; //this would be blue colour
proc.StartInfo.Domain = "domainname"; //use if domain user
proc.StartInfo.UserName = "username";
proc.StartInfo.Password = "password";
proc.Start();

对于颜色问题,您可以在此处查看如何设置:

http://ss64.com/nt/color.html

最新更新