程序/应用加载器 C#



im 制作一个应用程序加载器,它将允许您在其中保存任意数量的应用程序,例如您想在其中包含谷歌浏览器,您按"添加应用程序",您将获得一个 OpenFileDialog 来选择 Chrome 或任何其他您想要的应用程序/程序。 然后,程序将路径和名称保存在.bin文件中,并在您单击按钮时加载它。 它成功加载网站,但不是应用程序,我认为原因是程序将文件路径保存为

C:\Program Files (x86(\Google\Chrome\Application\chrome.exe

而不是

C:/Program Files (x86(/Google/Chrome/Application/chrome.exe

至少我是这么想的。 无论如何,这是"保存"和"加载"的代码:

救:

if (metroTextBox1.Text == "" || metroTextBox2.Text == "")
{
MessageBox.Show("You have to fill in both Name and Path first", "Invalid Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string[] name = { metroTextBox1.Text };
string[] path = { metroTextBox2.Text };
System.IO.File.WriteAllLines(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/appLoader/apps/appname1.bin", name);
System.IO.File.WriteAllLines(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/appLoader/apps/apppath1.bin", path);
}

负荷:

try
{                    
string path = System.IO.File.ReadAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/appLoader/apps/apppath1.bin");
Process.Start(path);
}
catch
{
}

Process.Start()可以同时处理两者,则不必转换任何斜杠或反斜杠。像这样的启动过程应该可以正常工作。

要查找错误,请检查该文件是否存在(File.Exists(path)(,如果可以直接在Windows中运行它,当然(也是最重要的(不要像您那样捕获异常,而是包含抛出的异常,如下所示:

catch (Exception ex)   // <-- !!
{
// investigate (and log) the exception here.
// note that catching all exceptions is not a good idea so narrow 
// it down once you found the exceptions you have to care for.
}

可能该文件根本不存在,或者在没有设置工作路径的情况下无法运行(这对于某些应用程序可能是强制性的(。

相关内容

最新更新