如何设置所有驱动器的注册表路径 [英] How to Set the Path to registry for all drive

查看:99
本文介绍了如何设置所有驱动器的注册表路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我需要您的帮助.我制作了一个只能在C驱动器上安装才能运行的软件.但是当我在I:驱动器或其他目录中安装时,我的软件无法运行.引起我的软件搜索c:\ windows \ system32 \ comutilities.dll上的comutilities.dll文件.
我设置了此命令%systemroot%\ system32 \ comutilities.dll,但它不起作用.

所以你们能告诉我如何为所有驱动器设置注册表的路径吗?
我的软件是用C#开发的.

问候
Sazeeb

Hi everybody.I need your help.I made a software that can only run if i install it on C Drive.But when i install in I: Drive or other directory my software don''t run.Cause my software search comutilities.dll file on c:\windows\system32\comutilities.dll.
I set this command %systemroot%\system32\comutilities.dll but its not working.

so guys could you plz tell me How to Set the Path to registry for all drive.
My software developed on C#.

Regards
Sazeeb

推荐答案

要获取system32文件夹的路径,可以使用API​​ GetSystemDirectory.
对于.Net,可以使用Environment.SystemDirectory属性.

获得system32路径后,只需将dll名称附加到该路径即可.

但是,为DLL有一个已定义的搜索路径,并且其中包含system32目录.
因此,您的程序必须简单地搜索不带路径的DLL名称,即可找到它.
Windows用于查找DLL的搜索路径 [ ^ ]

顺便说一句,该主题没有意义,并且与您的问题完全无关.
To get the path to the system32 folder you can use the API GetSystemDirectory.
For .Net you can use the Environment.SystemDirectory property.

Once you get the system32 path, simply append the dll name to it.

However there is a defined search path for a DLL and it includes the system32 directory.
So your program must simply search for the DLL name without the path and it would be found.
Search Path Used by Windows to Locate a DLL[^]

By the way, the subject makes no sense and is totally unrelated to your question.


不!不要试图找到解决方法.这只是一个错误.

浏览您的应用程序,确保您从不使用任何硬编码的路径名.这样的名称在任何情况下都不会有用.您也不能依赖工作目录,因为它完全取决于用户如何加载应用程序.用户可以从任何目录进行操作.

所有路径名只能在运行时根据应用程序的主要可执行模块(仅适用于只读文件)或相对于此路径或相对于特殊目录之一进行计算,请参见System.Environment.GetFolderPath(System.Environment.SpecialFolder)http://msdn.microsoft.com/en-us/library/system.environment.aspx [ ^ ].

要找到应用程序的可执行路径,请使用以下命令:
No! Don''t try to find a work-around. It''s merely a bug.

Look through your application and make sure you never use any hard-coded path names. There is not situations when such names could be useful. You cannot also rely on the working directory, as it totally depends on how the user loads your application. The user can do it from any directory.

All path names can only be calculated in run-time based on application''s main executable module (for read-only files only) or relative to this path or relative to one of special directories, see System.Environment.GetFolderPath(System.Environment.SpecialFolder), http://msdn.microsoft.com/en-us/library/system.environment.aspx[^].

To find the application''s executable path use this:
string exePath =
    System.Path.GetDirectoryName(
        System.ReflectionAssembly.GetEntryAssembly().Location);



同样,路径名可以存储在输入数据文件中(例如应用程序设置);但随后应在安装时调整此类文件的内容.

—SA



Also, path names could be stored in input data files (such as application settings); but then the content of such files should be tuned on installation.

—SA


这篇关于如何设置所有驱动器的注册表路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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