I have a Windows service, written in C# (.NET 4.5). This service has a user
scoped setting that is used to hold a timer variable. For debugging the service, I need to update this variable, so I need to know where the user.config
file for the service is located. Hence I added the following code in the service's OnStart()
method:
Logger.InfoFormat("user.config at \"{0}\"", ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath);
What is dumped into my logfile is the following path:
C:\Windows\system32\config\systemprofile\AppData\Local\company\service.exe_Url_randomcharacters\1.0.0.0\user.config
But when I try to open that file, it doesn't exist. After doing a Windows search, I found the actual file at:
C:\Windows\SysWOW64\config\systemprofile\AppData\Local\company\service.exe_Url_randomcharacters\1.0.0.0\user.config
Why is this? I'm assuming some 32-bit/64-bit compatibility magic, but what would be the correct code (if any) to get the actual path?
Additional info, if it helps: the service is running on a Windows Server 2008 R2 64-bit machine and it was installed via installutil
. I'm not sure whether the 32-bit or 64-bit version of installutil
was used though - would this make a difference?