2011-08-19 52 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 
相關問題