Click here to Skip to main content
15,884,849 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well i have made a simple windows service that monitor several dirs but Appdata\Local and Appdata\Roaming doesn't works!!!

I don't know why, really.

Intresting that if i made an application (not a service) it works...

What I have tried:

watcher.Path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

watcher2.Path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Posted
Updated 8-Mar-16 1:10am
Comments
Richard MacCutchan 8-Mar-16 4:23am    
The AppData directory is specific to each user, so unless your service runs under that user's account, you probably will not see it. Log the results you get for those two paths to see what they are.
Member 12332928 8-Mar-16 4:41am    
I can agree to you with the ApplicationData path but the LocalApplicationData (Appdata/Roaming) it's the same for all users.

Plus i run as administrator, i can see the dir! It's strange, there is something related to that specific dir, eg. i can monitor c:\Windows and Windows\System32 ...

Maybe i must monitor the Appdata instead of Appdata/Local or Roaming...

EDIT:

the Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) return when execute as service:

C:\Windows\system32\config\systemprofile\AppData\Local

Ok so i have to retrieve the current user login, i think the only method is to read the registry or make an app that write into a file the current user (Environment.Username property)
Richard MacCutchan 8-Mar-16 4:59am    
It's not the same for all users, each user has their own individual folders. But the issue is what is being returned from your calls to Environment.GetFolderPath.

1 solution

Ok solved using WMI Class, works :)

https://msdn.microsoft.com/en-us/library/aa394189(v=vs.85).aspx
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900