简体   繁体   English

如何在项目中配置其他exe文件的路径?

[英]How should I configure paths to other exe files in my project?

I am working on a project that requires a .exe file to be executed by the application. 我正在一个需要由应用程序执行的.exe文件的项目中。 The problem here is that I cannot guarantee that the file will always be in the same location on the user's machine, my app has no way of knowing where this .exe file is located. 这里的问题是我不能保证该文件将始终位于用户计算机上的同一位置,我的应用程序无法知道此.exe文件的位置。

So for example, my application needs to execute mongod.exe which is located (by default) in the following location: C:\\Program Files\\MongoDB\\Server\\3.2\\bin\\mongod.exe . 因此,例如,我的应用程序需要执行mongod.exe (默认情况下位于以下位置): C:\\ Program Files \\ MongoDB \\ Server \\ 3.2 \\ bin \\ mongod.exe

The problem here is that this is not always the case, the user might have installed this application to a different place, so I can't assume that the path to the .exe file is always the same on every client. 这里的问题是,情况并非总是如此,用户可能已将此应用程序安装到了其他位置,所以我不能假定.exe文件的路径在每个客户端上都相同。

Currently I am using the Settings.settings file to store a default file path to the file: 当前,我正在使用Settings.settings文件存储该文件的默认文件路径:

Settings.settings文件中的设置

The user can then either edit the app.config file or I could provide a UI to allow the user to change the file path. 然后,用户可以编辑app.config文件,也可以提供一个UI以允许用户更改文件路径。

So my question is, is there a better way? 所以我的问题是,有没有更好的方法?

Searching the path of the Mongodb.exe file in Registry can be useful. 在注册表中搜索Mongodb.exe文件的路径可能很有用。 Try to find the exe path from the Registry entry. 尝试从注册表项中找到exe路径。

RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\MongoDB\\MongoDB Connector"); RegistryKey键= Registry.LocalMachine.OpenSubKey(“ Software \\ MongoDB \\ MongoDB连接器”); if (key != null) { Object o = key.GetValue("InstallPath"); if(key!= null){对象o = key.GetValue(“ InstallPath”); } }

Object o will give the path of MongoDB.exe file. 对象o将给出MongoDB.exe文件的路径。

PS: If your application does not have rights to access the local machine's registry, then this approach won't work PS:如果您的应用程序无权访问本地计算机的注册表,则此方法将不起作用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使我的exe绑定到其他exe? - How can i make my exe to be bounded to some other exe? 如何获取我项目中文件夹的路径(以及该文件夹中文件的路径)? - How to get the path to a folder in my project (and paths to files in that folder)? 我应该在我的 .NET 6 项目中混合 .cshtml 文件和 .razor 文件吗? - Should I be mixing .cshtml files and .razor files in my .NET 6 project? 如何调用随主应用程序一起分发的.NET exe - How should I call a .NET exe that is distributed with my main application 如何将exe文件与dll和其他文件合并? - How can i merge exe file with dlls and other files? 如何将ffmpeg.exe文件添加到项目中,但如何添加两个文件,一个用于32位,另一个用于64位? - How can i add ffmpeg.exe file to my project but two files one for 32bit and one for 64bit? 我应该使用EXE,XPAP或其他技术来调查服务台客户的环境吗? - Should I have an EXE, XPAP, or some other technology to probe my helpdesk's customers' environment? 我应该如何组合两条路径,包括向后相对路径? - How should I combine two paths including backwards relative paths? 如何用c#获取我电脑中exe的所有路径 - How to get all the paths of exe in my computer with c# 我如何在 my.exe 中包含批处理文件,而不是在 the.exe 所在的文件夹中需要它们 - How do i include batch files inside of my .exe Instead of needing them in the folder the .exe is located in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM