I'm writing a windows service in C# that spawns multiple instances of another application I am writing. There is a chance that the application can be installed anywhere on a machine. What is the best way to let the service know where the application is located?
When the device location setting is enabled, the Microsoft location service will use a combination of global positioning service (GPS), nearby wireless access points, cell towers, and your IP address to determine your device's location.
To find out where an app is installed, the easiest method is to go through a shortcut used to open it. to do so, right-click on a shortcut and select “Open file location”. If the shortcut is in File Explorer, or on the desktop, this will take you straight to the location of the app.
In the search box on the taskbar, type Control Panel and select it from the results. Select Programs > Programs and Features. Press and hold (or right-click) on the program you want to remove and select Uninstall or Uninstall/Change. Then follow the directions on the screen.
One way to determine the game directory of your game is to look for a file called GameInfo. txt . If you find the GameInfo. txt file, then the directory it sits in is the game directory.
If you need to locate the folder your service is installed to you can use the following code
this.GetType().Assembly.Location
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();
}
If you mean that the service starts a different app, then; options:
Personally, I like the config file option; it is simple and easy to maintain, and allows multiple separate (side-by-side) service and app installs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With