Environment.MachineName 是否有可能返回零长度字符串

发布于 2024-11-07 15:22:07 字数 208 浏览 0 评论 0原文

我正在客户站点上追踪一个奇怪的错误,并且想知道 Environment.MachineName 是否可能返回零长度字符串。文档说这是从注册表中读取的,但没有指定在哪里。我无法想象一台机器不能有 netbios 名称,但我只是想问一下。

编辑

经过一番调查,似乎这没有返回零长度字符串,但我只是感兴趣是否可行。

I am chasing a strange error at a customer site and was wondering if it is possible that Environment.MachineName could return a zero length string. The docs say this is read from the registry but doesn't specify where. I can't imagine that a machine cannot have a netbios name but just wanted to ask.

EDIT

After some investigation, it appears that this was not returning a zero length string, but I was just interested if it is feasible.

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

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

发布评论

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

评论(1

童话里做英雄 2024-11-14 15:22:07

我不知道它是否可以是空字符串,抱歉,但是关于注册表,您可能需要检查以下内容(和子项):

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName

在我的系统上,它实际上正在查看 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ ComputerName\ActiveComputerName\ComputerName:

在此处输入图像描述

顺便说一句,正如你所看到的,我尝试使用 SysInternals Process Monitor 来解决这个问题,但最初失败了。然后我想,默认情况下会抑制上述键(以及一些相关的键)。以防万一你尝试同样的做法,请注意这一点。

您还可以检查 %COMPUTERNAME% 的值。尽管我没有参考或直接证据,但我认为它的价值来自同一来源。

我知道这不是您问题的真正答案,但它也不适合评论。

I don't know if it can be an empty string, sorry, but concerning the registry you might want to check the following (and subkeys):

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName

On my system it is actually looking at HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName:

enter image description here

BTW, as you can see I tried to figure this out using SysInternals Process Monitor, but initially failed. Then i figured, that the above keys (and some related ones) are suppressed by default. Just in case you try the same be aware of that.

You might also check the value of the %COMPUTERNAME%. Although I have no reference or direct evidence, I would assume that it gets its value from the same source.

I know this is not a real answer to your question, but it wouldn't fit in a comment either.

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