C# 如何从自定义操作获取setup.exe的路径?

C# 如何从自定义操作获取setup.exe的路径?,c#,windows,installation,C#,Windows,Installation,我的setup.exe在e:\setup.exe中,我尝试了以下代码: System.AppDomain.CurrentDomain.BaseDirectory; 返回c:\Windows\syswow64\ Application.ExecutablePath; 返回c:\Windows\syswow64\MsiExec.exe Application.StartupPath 返回c:\Windows\syswow64\ Application.ExecutablePath; 我需要返

我的setup.exe在e:\setup.exe中,我尝试了以下代码:

System.AppDomain.CurrentDomain.BaseDirectory;
返回c:\Windows\syswow64\

Application.ExecutablePath;
返回c:\Windows\syswow64\MsiExec.exe

Application.StartupPath
返回c:\Windows\syswow64\

Application.ExecutablePath;

我需要返回e:\

以获取当前工作目录的使用情况

Directory.GetCurrentDirectory();
位于
System.IO下

using System.IO;
string exeDir = Directory.GetCurrentDirectory();
您也可以通过反射获得exe完整路径

string exeLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
你也可以这样做

string exeDir = AppDomain.CurrentDomain.BaseDirectory;
string exeLocation = Assembly.GetEntryAssembly().Location;
还有一种方法:

string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

可以使用
Directory.GetCurrentDirectory()
获取当前正在运行的进程目录,也可以使用
DriveInfo[]allDrives=DriveInfo.GetDrives()
获取所有驱动器如果这是您正在寻找的问题是,在代码运行时,它作为
.msi
文件的一个组件运行,正如大多数指示所告诉您的,该文件实际上是由
MsiExec.exe
程序执行的。如果有办法访问此信息,您将查找特定于MSI的内容以访问MSI属性,而不是查看当前可执行/工作目录的通用.NET代码。谢谢您的回答,您的一些建议返回安装后应用程序所在的路径,但其中一个建议返回setup.exe的路径,这就是为什么我发布了多个答案,因为问题中没有很好地解释:)您可以在CustomActionData属性中设置目标路径,也可以获取上下文参数