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

时间:2011-08-19 19:28:02

标签: vbscript activex

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

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

2 个答案:

答案 0 :(得分:1)

谢谢你。当我尝试运行一个简单的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

答案 1 :(得分:0)

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

提供
相关问题