The service runs under the System account with the 'allow user to interact with the desktop' checked.
If I have the same code executed from a regular user app it works just fine.
Other P/Invoke calls from the windows service are just fine under the system account like: IsIconic, GetWindowRect, PrintWindow, GetClientRect, CreateCompatibleDC, CreateCompatibleBitmap, SelectObject, etc.
So far only SetWindowLong fails in the code below when under system acccount in the service:
Expand|Select|Wrap|Line Numbers
- [DllImport("user32", SetLastError = true)]
- internal static extern int SetWindowLong(IntPtr hWnd, int index, int dwNewLong);
- //......hWnd is some window on the local desktop
- int res = SetWindowLong(hWnd, GWL_EXSTYLE, winLong | WS_EX_LAYERED);
- if (res != winLong)
- {
- Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());
- throw new ApplicationException("SetWindowLong failed: " + ex.Message, ex);//fails in win service, not regular app
- }
Any ideeas how to get arround?