To cut a long story short I am attempting to add some functionality to a custom updater running as a windows service. I have run into some issues where the application I am attempting to update can potentially be running and I need to perform some custom actions if it is.
The problem I have is that the EnumDesktopWindows api call is only returning processes that are running in the local system context.
Now this mostly makes sense to me as to why this was done and so forth (I guess - although would appreciate further explanation).
However how does one then accomplish this functionality through a service?
This is the basics of the code I am using:
public static IntPtr[] EnumDesktopWindows()
{
WinAPI._desktopWindowHandles = new List<IntPtr>();
WinAPI.EnumDelegate enumfunc = new WinAPI.EnumDelegate(EnumWindowsCallBack);
IntPtr hDesktop = IntPtr.Zero; // current desktop
bool success = WinAPI.EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero);
if (success)
{
IntPtr[] handles = new IntPtr[_desktopWindowHandles.Count];
_desktopWindowHandles.CopyTo(handles);
return handles;
}
else
{
int errorCode = Marshal.GetLastWin32Error();
string errorMessage = String.Format("EnumDesktopWindows failed with code {0}.", errorCode);
throw new Exception(errorMessage);
}
}
Could it be that I have this all wrong and the problem is in the line?:
IntPtr hDesktop = IntPtr.Zero;