它一直说 ActiveX 组件无法创建对象:“Shell.LocalMachine”

发布于 2024-11-30 09:20:56 字数 505 浏览 0 评论 0原文

当我运行代码时,出现错误,指出

ActiveX 组件无法创建对象:“Shell.LocalMachine”

Class MachineName
    Private internal_ComputerName

    Public Function SetMachineName
        Set objComputer = CreateObject("Shell.LocalMachine")
        internal_ComputerName = objComputer.MachineName
    End Function

    Public Property Get GetMachineName
        GetMachineName = internal_ComputerName
    End Property
End Class

Dim objMachine
Set objMachine = New MachineName
objMachine.SetMachineName

When I run the code, I get an error saying

ActiveX component can't create object: 'Shell.LocalMachine'

Class MachineName
    Private internal_ComputerName

    Public Function SetMachineName
        Set objComputer = CreateObject("Shell.LocalMachine")
        internal_ComputerName = objComputer.MachineName
    End Function

    Public Property Get GetMachineName
        GetMachineName = internal_ComputerName
    End Property
End Class

Dim objMachine
Set objMachine = New MachineName
objMachine.SetMachineName

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

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

发布评论

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

评论(2

当爱已成负担 2024-12-07 09:20:56

谢谢你。当我尝试运行简单的 vbscript 代码时,在 Windows 7 64 位计算机上使用此 Shell.Localmachine 时,我遇到了同样的问题。我必须默认为 WScript.Network

'just a test script
'set objComputer = CreateObject("Shell.LocalMachine")

'wscript.echo "computer name" & objcomputer.machinename

Set objWshNet = CreateObject("WScript.Network")
wscript.echo "computer name : " & objwshnet.computername

thanks for this. I am having the same problems when using this Shell.Localmachine on my windows 7 64 bit machine when i try to run a simple vbscript code. I had to default to WScript.Network instead:

'just a test script
'set objComputer = CreateObject("Shell.LocalMachine")

'wscript.echo "computer name" & objcomputer.machinename

Set objWshNet = CreateObject("WScript.Network")
wscript.echo "computer name : " & objwshnet.computername
素手挽清风 2024-12-07 09:20:56

Morbo 说:“必须承认我以前没有遇到过该对象。我通常会创建一个“WScript.Network”对象并获取 ComputerName 属性。如果您正在诊断“Shell.LocalMachine”,我可以在我的网站上告诉您这一点。 XP 的副本由 system32\shgina.dll 提供”

Morbo said "Must admit I hadn't come across that object before. I'd normally create a "WScript.Network" object and get the ComputerName property. If you're diagnosing "Shell.LocalMachine" I can tell you that on my copy of XP it is provided by system32\shgina.dll"

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