Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 从服务调用Registry.CurrentUser.OpenSubKey时不返回任何内容_Vb.net_Registry - Fatal编程技术网

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

Vb.net 从服务调用Registry.CurrentUser.OpenSubKey时不返回任何内容,vb.net,registry,Vb.net,Registry,在作为服务运行的VB.NET应用程序中,当我使用Registry.CurrentUser.OpenSubKey()时,返回的值为“Nothing”。当应用程序在桌面模式下运行时,相同的代码会正确执行。我不太喜欢VB.NET,不幸的是,这不是我的代码 代码: 服务使用时,regKey为Nothing。桌面返回一个有效的注册表项对象,我觉得它验证了URL。我使用CurrentUser的任何想法,因为在Windows Server 2008上操作时,此代码不适用于LocalMachine 提前感谢,

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

代码:

服务使用时,
regKey
Nothing
。桌面返回一个有效的注册表项对象,我觉得它验证了URL。我使用CurrentUser的任何想法,因为在Windows Server 2008上操作时,此代码不适用于LocalMachine

提前感谢,


Craig

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

如果不是,注册表值将不同,因为
CurrentUser
是用户特定信息的别名-对每个用户来说不一样


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

您的服务在哪个帐户下运行?它们是相同的。我甚至尝试过更改服务的登录设置,但这并没有影响返回值。@cbuck12000-此交换()表明这对您不起作用。为什么不能使用LocalService或NetworkService?服务需要作为特定的桌面用户运行是不寻常的。
Dim regURL As String = "Software\MyCompany\" + _
                  System.Reflection.Assembly.GetCallingAssembly.GetName.Name + _
                  "\Settings"

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