MGS*_*oto 6 .net c# windows installation windows-services
我正在用C#编写一个Windows服务,它会生成我正在编写的另一个应用程序的多个实例.应用程序有可能安装在计算机上的任何位置.让服务知道应用程序所在位置的最佳方法是什么?
If you need to locate the folder your service is installed to you can use the following code
this.GetType().Assembly.Location
Run Code Online (Sandbox Code Playgroud)
If you need to locate the folder some other application is installed to you should make a request to windows installer
[DllImport("MSI.DLL", CharSet = CharSet.Auto)]
private static extern UInt32 MsiGetComponentPath(
string szProduct,
string szComponent,
StringBuilder lpPathBuf,
ref int pcchBuf);
private static string GetComponentPath(string product, string component)
{
int pathLength = 1024;
StringBuilder path = new StringBuilder(pathLength);
MsiGetComponentPath(product, component, path, ref pathLength);
return path.ToString();
}
Run Code Online (Sandbox Code Playgroud)
如果您的意思是该服务启动了另一个应用程序,那么; 选项:
就个人而言,我喜欢配置文件选项; 它简单易用,并允许多个独立(并排)服务和应用程序安装
| 归档时间: |
|
| 查看次数: |
751 次 |
| 最近记录: |