2014-09-02 2 views
-1

) 그래서 명령 인수를 사용하여 응용 프로그램을 실행하기위한 URL 프로토콜을 만들었습니다.URL 프로토콜에 대한 경로 설정 (C#

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 명령과 같은) 필요한 파일을 모두 시작할 수 있습니까?

+0

가 Environment.SetEnvironmentVariable입니다 경로 ", 게임 경로); 오류를 던지고있는 행을? 그렇다면 PATH가 아닌가? –

+0

http://msdn.microsoft.com/en-us/library/cb20e19t.aspx – Donal

+0

@DanielCasserly는 그것을 시도하고 변경했습니다. – Swiftiq

답변

1

당신은 PATH 환경 변수를 설정하고 Environment variables에 추가 프로세스에서 사용하고자하지만 그 경우에 false로 UseShellExecute을 설정해야하는 경우 : "(

ProcessStartInfo startInfo = new ProcessStartInfo(); 
// set environment 
startInfo.UseShellExecute = false; 
startInfo.EnvironmentVariables["PATH"] += ";" + gamepath; 
// you might need more Environment vars, you're on your own here... 
// start the exe 
startInfo.FileName = @"test.exe"; 
startInfo.Arguments = Environment.CommandLine; 

// added for debugging 

startInfo.RedirectStandardOutput = true; 
startInfo.RedirectStandardError = true; 


var p = new Process(); 
p.StartInfo = startInfo; 

using(var sw = new StreamWriter(File.Create("c:\\temp\\debug.txt"))) // make sure C:\temp exist 
{ 
    p.OutputDataReceived += (sender, pargs) => sw.WriteLine(pargs.Data); 
    p.ErrorDataReceived += (sender, pargs) => sw.WriteLine(pargs.Data); 

    p.Start(); 
    p.BeginOutputReadLine(); 
    p.BeginErrorReadLine(); 

    p.WaitForExit(); 
} 
+0

이제는 프로그램을 시작했지만 필요한 파일이 아직 남아 있습니다 ... – Swiftiq

+2

상자에 액세스 할 수없고 실제로 필요한 정보를 얻을 수있는 유용한 정보를 제공하지 않는다는 것을 알기를 바랍니다. 질문을 개선하는 방법에 대한 지침을 얻으려면 [ask]를 읽으십시오. – rene

+0

예를 들어, 프로그램이 거기에서 몇 가지 정보를 가져 오기 때문에 내 프로그램에 something.txt가 있어야하지만 URL 프로토콜 핸들러로 파일을로드 할 수는 없습니다. – Swiftiq

관련 문제