C# 当winrar使用Process类启动时,如何使窗口不可见
我希望winrar进程窗口不可见 此代码行似乎没有任何效果:C# 当winrar使用Process类启动时,如何使窗口不可见,c#,runtime,winrar,C#,Runtime,Winrar,我希望winrar进程窗口不可见 此代码行似乎没有任何效果: //the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 我如何才能使窗口保持隐藏状态 这是我用来启动winrar的代码: public void compress(string inputfilename, string outputfilename, string workingfolder) { string the_ra
//the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
我如何才能使窗口保持隐藏状态
这是我用来启动winrar的代码:
public void compress(string inputfilename, string outputfilename, string workingfolder)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR\shell\open\command");//for winrar path
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " " + outputfilename + " " + " " + inputfilename;//i dare say for parameter
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = workingfolder;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();//starting compress Process
the_Process.Close();
the_Process.Dispose();
}
catch
{
}
}
使用ProcessWindowsStyle.Hidden时,还必须将ProcessStartInfo.UseShellExecute设置为false 原因: 如果UseShellExecute属性为true或用户名和密码属性不为null,则将忽略CreateNowInow属性值并创建一个新窗口
public void compress(string inputfilename, string outputfilename, string workingfolder)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR\shell\open\command");//for winrar path
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " " + outputfilename + " " + " " + inputfilename;//i dare say for parameter
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.UseShellExecute = false;
the_StartInfo.WorkingDirectory = workingfolder;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();//starting compress Process
the_Process.Close();
the_Process.Dispose();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
为什么不使用本机库而不是shell?@Kaboo
WinRar
附带了一个命令行实用程序(Rar.exe
和unar.exe
)来压缩/提取归档文件。您可能想尝试使用它,而不是使用GUI(WinRar.exe
)。