如何使用c#.net访问gpedit.msc [英] how to access the gpedit.msc using c#.net
本文介绍了如何使用c#.net访问gpedit.msc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#.net以编程方式打开本地组策略编辑器,需要哪个命名空间。
解决方案
您好
请试试这个。
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = gpedit.msc;
Process.Start(startInfo);
我们可以用另一种方式做同样的事情,这个解决方案适用于单个打印机。我们可以使用控制台应用程序在命令提示符下完成整个过程。
示例代码:
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Diagnostics;
使用System.IO;
命名空间GroupPolicyEdit
{
class program
{
static void Main()
{
cmdProcess();
Console.ReadLine();
}
static void cmdProcess()
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName =cmd.exe;
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
流程p =新流程();
p.StartInfo = startInfo;
p.Start();
使用(StreamWriter writer = p.StandardInput)
{
//如果编写者能够写入
if(writer.BaseStream) .CanWrite)
{
//写下传递给方法的命令
string cmd = @printui / Xs / n 打印机名称ClientSideRender已启用;
writer.WriteLine(cmd);
}
/ /关闭StreamWriter
writer.Close();
}
}
catch {}
}
}
}
How to open the local group policy editor through programmatic using C#.net, which namespace is required.
解决方案Hi
Please try this.
ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "gpedit.msc"; Process.Start(startInfo);
We can do the same thing another way, this solutions is applicable to single printer. we can do this entire procedure in command prompt using console application.
sample code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
namespace GroupPolicyEdit
{
class Program
{
static void Main()
{
cmdProcess();
Console.ReadLine();
}
static void cmdProcess()
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
using (StreamWriter writer = p.StandardInput)
{
// If the streamwriter is able to write
if (writer.BaseStream.CanWrite)
{
// Write the command that was passed into the method
string cmd = @"printui /Xs /n ""Printer Name"" ClientSideRender enabled";
writer.WriteLine(cmd);
}
// close the StreamWriter
writer.Close();
}
}
catch { }
}
}
}
这篇关于如何使用c#.net访问gpedit.msc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文