当winrar用Process类启动时,我如何使窗口不可见?

本文关键字:窗口 何使 winrar Process 启动 | 更新日期: 2023-09-27 18:09:43

我想让winrar进程窗口不可见。

这行代码似乎没有任何效果:

        //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
        {
        }
    }

当winrar用Process类启动时,我如何使窗口不可见?

当你使用ProcessWindowStyle。隐藏你还必须设置ProcessStartInfo。UseShellExecute为false

<标题>原因:

如果UseShellExecute属性为true或UserName和Password属性不为空,则CreateNoWindow属性值被忽略,并创建一个新窗口。

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