Environment.GetFolderPath from a windows service

I'm writing a service that copies specific MS Office documents(.doc, .xls,.mdb) after any event triggers a file system watcher (Change, Deleted, Renamed, Changed) and logs those file operations
to a xml file. In order to copy those files to a hidden folder located in the user's My Documents Folder I was using in my windows form testing environment Environment.GetFolderPath(Environment.SpecialFolder.Personal) and it worked perfectly and in
order to determine the logged user I was using WindowsIdentity.GetCurrent().Name and when I
tryied using them in the Windows Service code none of them worked as expected, Environment.GetFolderPath Environment.SpecialFolder.Personal) returns nothing at all and
WindowsIdentity.GetCurrent().Name returns the account name that the windows service is using.

Is there any way in which I can accomplish the recolection of this information using perhaps another class or some other way of calling the class?

Thanks in advance, Mario

Comments

  • : I'm writing a service that copies specific MS Office documents(.doc, .xls,.mdb) after any event triggers a file system watcher (Change, Deleted, Renamed, Changed) and logs those file operations
    : to a xml file. In order to copy those files to a hidden folder located in the user's My Documents Folder I was using in my windows form testing environment Environment.GetFolderPath(Environment.SpecialFolder.Personal) and it worked perfectly and in
    : order to determine the logged user I was using WindowsIdentity.GetCurrent().Name and when I
    : tryied using them in the Windows Service code none of them worked as expected, Environment.GetFolderPath Environment.SpecialFolder.Personal) returns nothing at all and
    : WindowsIdentity.GetCurrent().Name returns the account name that the windows service is using.
    :
    : Is there any way in which I can accomplish the recolection of this information using perhaps another class or some other way of calling the class?
    :
    : Thanks in advance, Mario
    :
    Well, you said it yourself. The service runs under a different account, that has no My Documents folder.
    In XP, there may be more than one user logged on at the same time, so there is no way to determine the 'logged on user' from the service.
    You may want to use a different location to store the information (look at 'Isolated Storage' for example).
    Another OPTION is to get some information from the registy:
    HKEY_CURRENT_USERVolatile Environment



    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • But is there anyway from which we can get to the my documents folder of currently logged in user. If we suppose that there is only one user at a time that is logged on the system.

    Regards,
    Nauman Farooq
    [link=http://www.technoblogy.net]Technology Blogs[/link]
  • make sure you have a right EnvironmentPermission. Running the Services with Admin account will solved your problem. If not, you might have the File permission :) which allow you to access it "mannaly". Or else, you can use Isolated Storage to run you services with limited permission.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories