注册表问题C# [英] Registry Problem C#

查看:92
本文介绍了注册表问题C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为游戏服务器制作了一个启动器. (魔兽世界)
我想获取用户浏览的游戏的安装路径.
我正在使用此代码进行浏览,并获取安装路径,然后从安装路径字符串中设置其他一些字符串,然后只需输入我的注册表项即可.

I made a launcher for my game server. (World of Warcraft)
I want to get the installpath of the game, browsed by the user.
I''m using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.

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中,通过浏览窗口选择它,然后程序应将其作为C:\ ASD \ Data \存储在Existence注册表项中,但是它像这样存储:
C:\ ASDData,所以它忘记了反斜线:S

看这张照片:

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

我的程序可以在我的PC和朋友PC上正常运行,但是在某些PC上会出现此错误":S
我有Windows 7,带有.NEt 3.5
请帮助我.



The problem is:
On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this:
C:\ASDData , so it forgots a backslash :S

Look at this picture:

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

My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S
I have windows 7, with .NEt 3.5
Please help me.

推荐答案

而不是使用字符串附加,应该使用Path.Combine创建目录结构.这样,您不必担心\\的存在.这就是我要为您的PatchPath做的事情.
Rather than using string appending, you should use Path.Combine to create directory structures. This way, you don''t have to worry about the presence of \\. Here''s what I would do for your PatchPath.
PatchPath = Path.Combine(InstallPath, "Data");


我要对其进行测试,它在我的计算机上没有任何变化,也许现在可以在我的电脑上运行了朋友的计算机.还是很奇怪:)
I''m going to test it, it has no change on my computer, maybe it will work now on my friend''s computer. It''s still weird :)


这篇关于注册表问题C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆