2011-08-19 49 views
0

当我运行代码,我得到一个错误说口口声声说ActiveX组件不能创建对象:Shell.LocalMachine'

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 
+1

是否安装了“Shell.LocalMachine”?用regedit搜索你的注册表 – 2011-08-19 20:57:37

+1

必须承认我之前没有遇到过这个对象。我通常会创建一个[“WScript.Network”](http://msdn.microsoft.com/en-us/library/s6wt333f%28v=vs.85%29.aspx)对象并获取ComputerName属性。如果您正在诊断“Shell.LocalMachine”,我可以告诉您,在我的XP副本中,它由system32 \ shgina.dll – Morbo

+1

提供另请参阅[here](http://www.robvanderwoude.com/vbstech_network_names_computer.php)了解更多信息。 – Morbo

回答

0

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

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 
相关问题