0

I created a Basic Windows Service with the help of Windows Service Template, from Microsoft Visual Studio IDE 2010 Ultimate ; I set the Account Type to Local System, and I test this out, and after that, I set it to LocalService and I test it out. On both sides I have the same problem. I'm trying to check my Desktop folder ( C:\users\charqus\desktop ) with the next variable:

private readonly string folderParent = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

I have printed the variable folderParent to the EntryLog application, and this is the result: C:\Windows\system32\config\systemprofile\Desktop

I have accessed that path, and I don't find any Desktop Folder in there. If I'm trying with my service to list all files from Desktop ( from that path ) he doesn't list anything.

Thanks!

charqus
  • 469
  • 1
  • 5
  • 15
  • Services, as you're already aware, run under *service* accounts. Those accounts have their own desktop folders. And there may be more than one user logged into a machine, so *whose* desktop should it access? Maybe tell us instead the overall problem you're trying to solve. It'll probably end up splitting into two programs - a service part and a separate program run by each user logged into the machine – Damien_The_Unbeliever Jun 22 '13 at 07:16
  • Have a look here http://stackoverflow.com/a/5595738/397807. Windows service is not bound to any user account or current logged in account. – tia Jun 22 '13 at 07:20
  • Thanks for answers guys, but what do you suggest me? To stop working with service and to make an C# Invisible Application which works on background? That will solve my problem? Or is there any simpler solution? – charqus Jun 22 '13 at 07:32

1 Answers1

0

The service runs under the Windows local system account and as you've found out accesses the (non-existant) desktop of the system user.

Services are meant for non-user-dependent background processes. If your application is interacting with the user's desktop it should be a normal interactive application - but probably an invisible one that only displays an icon in the system tray. Set the application to autostart on logon by adding it to the startup folder for all users.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217