vikash
vikash

Reputation: 11

AppData\Roaming folder in windows service project

I need a help on getting Special folder in windows service program. I used this code in my Windows Form application:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

and got the path, ""C:\Users\\AppData\Roaming"*

But if I run the same code in my Winows Service project I got the path: "C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\"

But I need the earlier path (got in Windows Form). How do I get the same path in Service projet also.

I have user setting file, log, config file in the "C:\Users\\AppData\Roaming" folder. So I have to refer the same path both in my Windows Form application and Windows Service project.

Can somebody tell me, what is the difference here and how do i get the same path in both type of project?

Thanks, sharath

Upvotes: 1

Views: 3625

Answers (1)

Prabu Arumugam
Prabu Arumugam

Reputation: 1989

Your Windows Service should use 'User' Account, instead of 'LocalService' or 'LocalSystem'.

        ServiceProcessInstaller process = new ServiceProcessInstaller();
        process.Account = ServiceAccount.User;

And during installation of the service, you need to specify the username and password of currently logged in user. Username should be in this format: "MachineName\UserName". Example: ".\John"

Upvotes: 3

Related Questions