因此,我創建了一個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