因此,我创建了一个URL协议以使用命令参数运行应用程序。在c#中为URL协议设置路径#
这里是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics;
namespace iw4Protocol
{
class Program
{
static void Main(string[] args)
{
RegistryKey key = Registry.ClassesRoot.OpenSubKey("gameProtocol");
if (key == null)
{
string iw4FullPath = Directory.GetCurrentDirectory();
gameProtocol protocol = new gameProtocol();
protocol.RegisterProtocol(gameFullPath);
}
else
{
RegistryKey gamepathkey = Registry.ClassesRoot.OpenSubKey("gameProtocol");
string gamepath = gamepathkey.GetValue("gamepath").ToString();
Environment.SetEnvironmentVariable("path",gamepath);
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"test.exe";
startInfo.Arguments = Environment.CommandLine;
Process.Start(startInfo);
}
}
}
}
的问题是,该方案需要一些文件即可启动,但由于路径没有“设置”无法加载它们。
如何设置此路径来启动所有这些所需的文件(如/cd
命令)?
是Environment.SetEnvironmentVariable(”路径”,gamepath);排队那个抛出错误的那个?如果是这样,是不是PATH? – 2014-09-02 15:39:24
http://msdn.microsoft.com/en-us/library/cb20e19t.aspx – Donal 2014-09-02 15:41:34
@DanielCasserly试了一下,并改变了一切。 – Swiftiq 2014-09-02 15:50:21