使用 Windows 窗体应用程序打开外部可执行文件

本文关键字:外部 可执行文件 应用程序 Windows 窗体 使用 | 更新日期: 2023-09-27 18:35:30

尝试让我的游戏启动器使用以下代码打开外部可执行文件时,我不断收到 NotImplementException 错误:

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.IO.Compression;
using System.Diagnostics;
using System.Net;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        Process.Start("C:/Users/Me/AppData/Local/osu!");
        }
    private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
    {
    }
    private void folderBrowserDialog1_HelpRequest(object sender, EventArgs     e)
    {
    }
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    }
    private void Form1_Load(object sender, EventArgs e)
    {

    }
    private void button2_Click(object sender, EventArgs e)
    {
        Environment.Exit(0);
    }
}
internal class CustomWindow
{
    private string v;
    public CustomWindow(string v)
    {
        this.v = v;
    }
    internal void Show()
    {
        throw new NotImplementedException();
    }
}

internal class Window1 : Form
{
}
internal class Process
{
    public object StartInfo { get; internal set; }
    internal static void Start(string v)
    {
        throw new NotImplementedException();
    }
}
    }

注意:我今天刚开始学习 C#,所以请尽量耐心等待我。

使用 Windows 窗体应用程序打开外部可执行文件

当您要启动外部应用程序时,请考虑以下事项,

  1. 给出特定exe的绝对路径,包括带有扩展名的文件名
  2. 添加参数/选项以提及特定 exe 的启动路径
  3. 如果要导入 dll(托管代码),则通过"添加引用"选项添加它们
  4. 如果要使用非托管代码,请使用 dllImport 选项。

谢谢

internal static void Start(string v)
{
    throw new NotImplementedException();
}

你有故意抛出 NotImplementException 的代码。C# 已经具有此功能,无需为其创建类。删除你的并使用这个:https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.110).aspx

只需删除您的进程类,除非您打算对它执行一些特殊操作。