简体   繁体   English

可以在Windows服务中调用GetSetting()吗?

[英]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! 但是我不知道为什么GetSetting("MyAppName", "MySection", "IntervalSetting")不会在注册表中返回该值!

Am I missing something? 我想念什么吗? Does GetSetting() not work when called from a windows service? 从Windows服务调用时,GetSetting()不起作用吗?

From MSDN : 从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." “ GetSetting要求用户登录,因为它在HKEY_LOCAL_USER注册表项下运行,该注册表项只有在用户交互式登录后才处于活动状态。”

What account does your service operate under? 您的服务使用哪个帐户? If it's LocalSystem, you effectively have no user logged on. 如果是LocalSystem,则实际上您没有用户登录。 Even if you impersonate, IIRC, that doesn't load the registry hive. 即使您冒充IIRC,也不会加载注册表配置单元。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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