2010-05-17 146 views
1

我为我的游戏服务器制作了一个启动器。 (魔兽世界) 我想获得用户浏览的游戏的安装路径。 我正在使用此代码浏览并获取installpath,然后从installpath字符串中设置一些其他字符串,然后在我的注册表项中执行strore操作。注册表问题

using System; 
using System.Drawing; 
using System.Reflection; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data; 
using Microsoft.Win32; 
using System.IO; 
using System.Net.NetworkInformation; 
using System.Diagnostics; 
using System.Runtime; 
using System.Runtime.InteropServices; 
using System.Security; 
using System.Security.Cryptography; 
using System.Text; 
using System.Net; 
using System.Linq; 
using System.Net.Sockets; 
using System.Collections.Generic; 
using System.Threading; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     string InstallPath, WoWExe, PatchPath; 
     private void Form1_Load(object sender, EventArgs e) 
     { 

      RegistryKey LocalMachineKey_Existence; 
      MessageBox.Show("Browse your install location.", "Select Wow.exe"); 
      OpenFileDialog BrowseInstallPath = new OpenFileDialog(); 
      BrowseInstallPath.Filter = "wow.exe|*.exe"; 
      if (BrowseInstallPath.ShowDialog() == DialogResult.OK) 
      { 
       InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName); 
       WoWExe = InstallPath + "\\wow.exe"; 
       PatchPath = InstallPath + "\\Data\\"; 

       LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\ExistenceWoW"); 
       LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath); 
       LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath); 
       LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe); 
      } 
     } 
    } 
} 

的问题是: 在某些计算机,它不商店像它应该是。例如,您的wow.exe位于C:\ ASD \ wow.exe中,您将其选择为浏览窗口,然后该程序应将其存储在Existence注册表项中作为C:\ ASD \ Data \,但它以这种方式存储: C:\ ASDData,所以它forgots反斜线:S

看看这张图:

http://img21.imageshack.us/img21/2829/regedita.jpg

我的程序工作在我的电脑上的冷静,和我的朋友的电脑,但一些PC这个“bug”出来:S 我有Windows 7,与.NEt 3.5 请帮助我。

+0

不知道尝试,如果能解决你的问题,但使用'IO.Path.Combine'而不仅仅是添加路径共同建议。 – 2010-05-17 08:37:02

回答

1

您可以调试并查看InstallPath包含的内容吗?

与Path.Combine而不是字符串连接,例如:

WowExe = Path.Combine(InstallPath, "wow.exe"); 
PatchPath = Path.Combine(InstallPath, @"\Data\");