.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Windows Service and System.Drawing Namespace
 

Windows Service and System.Drawing Namespace

Hi!
I write an application(windows service) thatuse funtions in GDI+.I need to make a sreen capture of user desktop. This service works fine when I run it in XP machine. But when I try to run this service in Windows Server 2008 it thows "Parameter is not valid" exception in line of code: Image img = Image.FromHbitmap(hBitmap). When I try to run the same application inWindows Server 2008 as window application - it works! This error occurs only if the application run as service inWindows Server 2008 machine! What is the problem?
Thanks


Yarko
No, you cannot logon without a password. Considering it doesn't make a lot of sense to try to make screenshots when nobody is logged in, perhaps it doesn't make a lot of sense to use a service. A plain .exe, started by a .lnk in the Startup folder avoids the problem of both session 0 and the need to use another account.
Hans Passant.
nobugz
You can run a service as a local user; this will give you a real login token. However:
1) With every release of Windows, Microsoft widens the divide between services and desktop interaction.
2) Hans has an excellent point: just run it as a regular exe. Your problem doesn't require a service solution.

-Steve
Stephen Cleary
Your service wouldn't work on Vista either. Services are no longer allowed to interact with the desktop.
Hans Passant.
nobugz
Thanks!
As I understand to solve this problem, I must create a new child process from my service in the user's session with the help of CreateProcessAsUser function.
CreateProcessAsUser function needs handle to a token. How do I get the token for the user from the service?
Yarko
P/Invoke LogonUser().
Hans Passant.
nobugz
Hi, nobugz!
Thanks for reply!

The function LogonUser() needs apassword to give. Is it possible to get a password for an user in .Net? I don't now how to get password...
Yarko
That's not possible in any language. Passwords are stored in a hashed format, not in cleartext.
Hans Passant.
nobugz
That's the problem!
I tryIntPtr hToken = WindowsIdentity.GetCurrent().Token;
But here i get aservice token and I need user token so that i can start application inits context, what is the right way to do it?

Are there some functions(that don't need user password) that allowto obtain token of a logged on user?
Yarko
No, you cannot logon without a password. Considering it doesn't make a lot of sense to try to make screenshots when nobody is logged in, perhaps it doesn't make a lot of sense to use a service. A plain .exe, started by a .lnk in the Startup folder avoids the problem of both session 0 and the need to use another account.
Hans Passant.
nobugz
You can run a service as a local user; this will give you a real login token. However:
1) With every release of Windows, Microsoft widens the divide between services and desktop interaction.
2) Hans has an excellent point: just run it as a regular exe. Your problem doesn't require a service solution.

-Steve
Stephen Cleary

You can use google to search for other answers

Custom Search

More Threads

• API for deleting Certificate Revocation List (CRL) from certificate store
• Hauppauge USB / WIA?
• Remove System.dll
• Parsing a text file
• IEnumerable<T> instead of IList<T> or Collection<T>
• Extending System namespace from other assemblies
• How to add cutom attributes to directory and file
• Counting values in a hash table
• Serial Port Does not Close Properly
• Help do stuff with collection