从服务调用时,Registry.CurrentUser.OpenSubKey 不返回任何内容

发布于 2024-09-28 19:14:29 字数 602 浏览 0 评论 0原文

在作为服务运行的 VB.NET 应用程序中,当我使用Registry.CurrentUser.OpenSubKey() 时,我得到的值是“Nothing”。当应用程序在桌面模式下运行时,相同的代码可以正确执行。我不太了解 VB.NET,不幸的是,这不是我的代码。

代码:

Dim regURL As String = "Software\MyCompany\" + _
                  System.Reflection.Assembly.GetCallingAssembly.GetName.Name + _
                  "\Settings"

regKey = My.Computer.Registry.CurrentUser.OpenSubKey(regURL, True)

当服务使用时,regKeyNothing。 Desktop 返回一个有效的注册表项对象,我认为该对象验证了 URL。我正在使用 CurrentUser 的任何想法,因为在 Windows Server 2008 上操作时此代码不适用于 LocalMachine。

提前致谢,

Craig

In a VB.NET application that runs as a service, I am getting a value of "Nothing" returned when I use Registry.CurrentUser.OpenSubKey(). The same code executes correctly when the application runs in desktop mode. I am not much on VB.NET and unfortunately, this is not my code.

Code:

Dim regURL As String = "Software\MyCompany\" + _
                  System.Reflection.Assembly.GetCallingAssembly.GetName.Name + _
                  "\Settings"

regKey = My.Computer.Registry.CurrentUser.OpenSubKey(regURL, True)

The regKey is Nothing when used by a service. Desktop returns a valid registry key object to which I feel verifies the URL. Any ideas I am using CurrentUser because this code does not work with LocalMachine when operating on Windows Server 2008.

Thanks in advance,

Craig

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

匿名的好友 2024-10-05 19:14:29

为了使这是一个有效的测试,您必须确保在安装时将您的服务配置为以与桌面测试相同的帐户运行。它们是一样的吗?

如果不是,注册表值将会不同,因为 CurrentUser 是用户特定信息的别名 - 每个用户都不相同。

如果它们不匹配,您应该能够通过 AdminstrativeTools -> 更改服务设置来重新测试。服务 - 右键单击​​您的服务并选择“属性”,然后通过“登录”选项卡更改服务帐户。

For this to be a valid test you have to ensure that your service is configured at installation time to run as the same account that you used for desktop testing. Are they the same?

If not, the registry values will be different since CurrentUser is an alias for user-specific information - not the same for each user.

If they don't match, you should be able to retest by altering the service settings via AdminstrativeTools -> Services - right click your service and select Properties, then alter the service account thru the Log On tab.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文