Permission differences between windows service and console application
I'm developing an application with a smart card involved (digital signature). Let's assume that we have the same code in this two contexts:
- Console application, executed by Administrator user
- Windows Service, executed by Administrator user
I suposed that if this two codes were executed by the same user they would have the same privileges. It seems that this is not true. When I try with the Windows Service (Executed with Administrator user) i receive
TargetInvocationException
CryptographicException
Can't initialize DLL provider at System.Security.Cryptography.Utils.CreateProvHandle(.
As far as I read on internet maybe is some king of permissions issue. Console Application works OK.
What is the difference between the Windows Service and Console Application if they are开发者_C百科 executed by the same user?
Is possible to achieve the same results with Windows Service?
Free virtual beers for the person who solves it ;)
Thanks!
Have you tried running your service as Local Service, Network Service, and Local System? No difference with changing these? I know I had to change mine from Local Service to Local System to give it access to my files. Not sure if you're even using any files, but at least it's something to check.
One difference between a console app and a Windows service which caused me headaches is the fact that the Windows service uses C:\Windows\System32 as the current directory. I don't know if this will help in your case, but I guess you could try it: http://igorbrejc.net/development/c/windows-services-and-working-directories
I don't have a solution for you, unfortunately, but Windows Services do behave quite differently from ordinary programs. For example, you won't be able to access network drives from a windows service, unless your service starts AFTER the service that initializes those drives.
You can add dependencies to your service, to make them depend on the services you need, or at the very end. This MAY solve your problem, but I cannot guarantee that.
精彩评论