0
votes

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
2
is "Shell.LocalMachine" installed? search your registry with regedit - user69820
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 - Morbo
See also here for a lot more info. - Morbo
which version of windows are you running? - user69820
judging by this thread it's on XP only - user69820

2 Answers

1
votes

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
0
votes

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"