Hi,I have developed a Windows Service in VS2010 which is running on Windows7. I am trying to get "MainWindowTitle" but it returns empty.
lObj_Process = Process.GetProcessById(Pi_ProcessID)
lObj_Process.MainWindowTitle
If same service runs on Windows XP, title is found so it is not a Windows Service restriction.
Moreover if I use the same code in windows application rather than service then it returns proper title.
Please note that Service is reading/writing files so there should be no privileges issue.
Question:
Why "MainWindowTitle" property works fine for windows application but returns empty if used in Windows Service.
Regards,
Immi
VulpesPosted Aug 4, 2011, 4:30 PM
Basically, you need the "SeDebugPrivilege" security privilege to read into another process's address space to obtain UI information which should automatically be available under the LocalSystem account.
According to the documentation for the ServiceBase class, a service you create using .NET runs by default under the System account. So, unless you're using a different account which lacks this privilege under Windows 7, I don't know what the problem can be.
To make absolutely sure, you could try enabling this privilege manually using the code in this link (http://rongchaua.net/blog/c-how-to-enable-sedebugprivilege/) and see whether it's any better.
Sam HobbsPosted Aug 4, 2011, 2:36 PM
ImmiPosted Aug 4, 2011, 12:15 AM
Vulpes,
'Allow service to interact with desktop' is already checked for both Windows7 as well as Windows XP. Infact same service is tested for both OS. Any other suggestion plz?
Sam Hobbs
I got the title on WindowsXP thats why thought that it should not be a service restriction. I am not sure about this change for Windows 7. Infact my client is migrating to Windows 7 from WinXP. Same functionality was achieved earlier so i must have to achieve the functionity on Windows 7 as well in any case.
a) Can you provide any authentic link which can clearly tell that it is not possible to get title (or UI properties) in service for Windows7?
b) Is there any other solution for this like API or so?
Regards,
Immi
Sam HobbsPosted Aug 3, 2011, 2:54 PM
VulpesPosted Aug 3, 2011, 7:07 AM
Perhaps you remembered to do this in XP but not in Windows 7?
ImmiPosted Aug 3, 2011, 6:19 AM
Service has no UI and no main window.
Infact Service is trying to get title of other running processes. These processes have UI and obviously titled main windows. Service get the process ID of these processes successfully. Also service can get the process name .i.e.
lObj_Process = Process.GetProcessById(Pi_ProcessID)
lObj_Process.ProcessName
But
lObj_Process.MainWindowTitle returns empty.
It is obvious that running processes are not child process of service at all.
I am repeating that if same service runs on Windows XP, title is found so it is not a Windows Service restriction in my case.
Hope situation is clear now?
Thanks and Regards
Immi
VulpesPosted Aug 3, 2011, 4:54 AM