none
Unable to execute my first VB Script - Errors RRS feed

  • Question

  • While learning VB Script I'm trying to execute a basic one from a tutorial  (as below)

    ===========================

    Set objComputer = CreateObject("Shell.LocalMachine")

    Wscript.Echo "Computer name: " & objComputer.MachineName
    Wscript.Echo "Shutdown allowed: " & objComputer.IsShutdownAllowed
    Wscript.Echo "Friendly UI enabled: " & objComputer.IsFriendlyUIEnabled
    Wscript.Echo "Guest access mode: " & objComputer.IsGuestAccessMode
    Wscript.Echo "Guest account enabled: " & _
        objComputer.IsGuestEnabled(0)
    Wscript.Echo "Multiple users enabled: " & _
        objComputer.IsMultipleUsersEnabled
    Wscript.Echo "Offline files enabled: " & _
        objComputer.IsOfflineFilesEnabled
    Wscript.Echo "Remote connections enabled: " & _
        objComputer.IsRemoteConnectionsEnabled
    Wscript.Echo "Undock enabled: " & objComputer.IsUndockEnabled

    ===========================

    When I try to execute the above scripts saved as 'blip.vbs' on a Windows 7 machine, I receive the below pop up error:

    

    After checking around on the net, I found the below link and followed the recommendation to change the opening line of the script from Set objComputer = CreateObject("Shell.LocalMachine")  to  Set objComputer = CreateObject("WScript.Network")

    http://stackoverflow.com/questions/7126464/it-keeps-saying-activex-component-cant-create-object-shell-localmachine

    So the script now became :

    =============================================

    Set objComputer = CreateObject("WScript.Network")

    Wscript.Echo "Computer name: " & objComputer.MachineName
    Wscript.Echo "Shutdown allowed: " & objComputer.IsShutdownAllowed
    Wscript.Echo "Friendly UI enabled: " & objComputer.IsFriendlyUIEnabled
    Wscript.Echo "Guest access mode: " & objComputer.IsGuestAccessMode
    Wscript.Echo "Guest account enabled: " & _
        objComputer.IsGuestEnabled(0)
    Wscript.Echo "Multiple users enabled: " & _
        objComputer.IsMultipleUsersEnabled
    Wscript.Echo "Offline files enabled: " & _
        objComputer.IsOfflineFilesEnabled
    Wscript.Echo "Remote connections enabled: " & _
        objComputer.IsRemoteConnectionsEnabled
    Wscript.Echo "Undock enabled: " & objComputer.IsUndockEnabled

    =============================================

    But even after this change I am receiving a new error as below :

    

    With this being my first experience with VBScript, can anyone suggest what I'm missing out (or) if I'm doing something wrong?

    Thank You in advance..


    SamSV

    Wednesday, September 21, 2016 9:03 PM

Answers

  • Your first error is that there is no COM object named "Shell.LocalMachine" on your computer.

    You can only use the properties and methods that exist for an object.

    If you use the WshNetwork object (created using the name "WScript.Network"), then you can only use that object's properties and methods. You can read about the WshNetwork object in the documentation:

    https://msdn.microsoft.com/en-us/library/s6wt333f.aspx

    You will note that the WshNetwork object does not have a MachineName property. That's why you get the error.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by SamSV Thursday, September 22, 2016 7:42 PM
    Wednesday, September 21, 2016 9:09 PM
    Moderator

All replies

  • Your first error is that there is no COM object named "Shell.LocalMachine" on your computer.

    You can only use the properties and methods that exist for an object.

    If you use the WshNetwork object (created using the name "WScript.Network"), then you can only use that object's properties and methods. You can read about the WshNetwork object in the documentation:

    https://msdn.microsoft.com/en-us/library/s6wt333f.aspx

    You will note that the WshNetwork object does not have a MachineName property. That's why you get the error.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by SamSV Thursday, September 22, 2016 7:42 PM
    Wednesday, September 21, 2016 9:09 PM
    Moderator
  • I would also add that I think your time is better spent learning PowerShell than VBScript.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, September 21, 2016 9:11 PM
    Moderator
  • Hi Bill.. Thank You very much.. That does clear some air


    SamSV

    Thursday, September 22, 2016 7:42 PM
  • Thank You Bill.. Though that is on my learning plan, I felt learning VBScript first and then Powershell would be more comprehensive.. But if you think I'm wasting time on something not worth, do correct me. 

    SamSV

    Friday, September 23, 2016 2:54 PM
  • Sam - do yourself a favor and just learn PowerShell instead. VBScript was useful in the past but now it's more of a burden.

    Friday, September 23, 2016 3:10 PM
  • Copy that.. Thank You much Mike.. Will do.

    SamSV

    Friday, September 23, 2016 3:39 PM
  • Cheers Sam, you're welcome.


    Friday, September 23, 2016 3:48 PM