【问题标题】:How to start a Process from resources?如何从资源启动流程?
【发布时间】:2016-11-23 15:53:45
【问题描述】:

我想像按 Win+R 一样启动 Skype,而不是输入运行任务“skype.exe”,这应该在我单击 Windows 窗体上的按钮时发生。

我只想通过单击按钮来启动 Skype,但每次都会崩溃。

   private void button5_Click(object sender, EventArgs e)
    {
        Process X = new Process(); 
        X.StartInfo.FileName = "Skype.exe";        
        X.Start();
        //Process.Start(Properties.Resources.lul);  ||lul is a batch file in the resources which should after running start skype but it doesn´t work :/     
    }

【问题讨论】:

  • 如果它在资源中,你将不得不暂时将它保存在某个地方,然后运行它,然后如果需要再次删除它。 Process.Start 需要路径,而您的资源文件不是有效路径。
  • 请说明你得到了什么异常。而且我认为这与资源或 Skype 无关。
  • 我想像按 Win+R 一样启动 Skype,而不是输入运行任务“skype.exe”,当我单击 Windows 窗体上的按钮时应该会发生这种情况。

标签: c# process resources skype


【解决方案1】:

是的,最后我自己搞定了 -.- 我

private void button5_Click(object sender, EventArgs e)
    {
        Process.Start("C:\\Program Files (x86)\\Skype\\Phone\\Skype.exe");
    }

【讨论】:

    【解决方案2】:

    FileName 不仅是 exe 的名称,还是它的路径。 这是standard microsoft example

    public static void Main()
        {
            Process myProcess = new Process();
    
            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                // This code assumes the process you are starting will terminate itself. 
                // Given that is is started without a window so you cannot terminate it 
                // on the desktop, it must terminate itself or you can do it programmatically
                // from this application using the Kill method.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 2017-10-29
      • 1970-01-01
      • 2021-03-30
      • 2021-12-18
      • 2020-07-22
      相关资源
      最近更新 更多