简体   繁体   中英

Can GetSetting() be called in a Windows Service?

I have written a window service. and I am able to successfully install/run the service. Now I have added a timer to the service and I want to be able to adjust the interval via the registry. But I can't figure out why GetSetting("MyAppName", "MySection", "IntervalSetting") will NOT return the value in the registry!

Am I missing something? Does GetSetting() not work when called from a windows service?

From MSDN :

"GetSetting requires that a user be logged on since it operates under the HKEY_LOCAL_USER registry key, which is not active until a user logs on interactively."

What account does your service operate under? If it's LocalSystem, you effectively have no user logged on. Even if you impersonate, IIRC, that doesn't load the registry hive.

服务在其下运行的用户是否有权访问注册表?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM