I have a program I’m converting to a Windows Service (in C#). This program interacts with an external DLL that has a method that returns an object. The object shows the state of another running program (whether it is running, and whether the program is logged in)
With the previous implementation, everything worked fine. The DLL call to get the object with the state variables in it worked fine. Now that I have moved that method call to the Windows Service, it returns the wrong values. The DLL method call returns the state object, but the values always show that the program is not running or logged in (when it clearly is).
I have no idea why calling this DLL method inside a Windows Service should change the variables returned.
Is there something I can do to make sure the DLL call works as intended?
I have no access to the DLL code, so the change cannot be made there.
Here’s an example:
AppStateDLL.AppStateObject stateObject = new AppStateDLL.AppStateObject();
if (!stateObject.Online || !stateObject.LoggedIn)
{
//things are broken, because the program is always running and logged in
}
(the names are made up, but you get the idea)
If I run this code in a Windows Forms object, the stateObject has the Online and LoggedIn properties set as true, so everythings good. If I run the code from within the Windows Service, I get false returned for both variables.
And my Windows Service is set with LocalSystem access, which I believe should mean it should have no issues with permissions and such.
Thanks
I’m guessing the problem is that the service is running in a different session and thus a different desktop from the app whose status it is trying to report on.
This DLL probably calls EnumWindow to find the app and this would fail to locate it when run from a different desktop.