anadem has asked for the wisdom of the Perl Monks concerning the following question:

I humbly beg the wise monks for advice on converting a simple VBS script to perl. In particular, I'm unable to translate the second line here:

set objWMILocator = CreateObject("WbemScripting.SWbemLocator") objWMILocator.Security_.AuthenticationLevel = 6

The full working VBS script is

Option Explicit On Error Resume Next Dim strServ, strUsrN, strPasswd strServ = "10.x.x.x" strUsrN = "Administrator" strPasswd = "******" Const WMIPATH = "root\Citrix\WanScaler" Dim objWMILocator set objWMILocator = CreateObject("WbemScripting.SWbemLocator") If Err.Number then Wscript.Echo( "CreateObject: error 0x" & CStr(Hex(Err.Number)) ) WScript.Quit(1) end if objWMILocator.Security_.AuthenticationLevel = 6 Dim objService Set objService = objWMILocator.ConnectServer(strServ, WMIPATH, strUsrN +, strPasswd) If Err.number Then Wscript.Echo( "Connect Error 0x" & CStr(Err.Number)) WScript.Quit(1) End If Dim colSettings, strQuery strQuery = "Select * from Citrix_WS_SystemConfig" Set colSettings = objService.ExecQuery(strQuery) Dim objClassProperty, objInstance, colProperties, strOutPut For Each objInstance in colSettings Set colProperties = objInstance.Properties_ For Each objClassProperty In colProperties strOutput = objClassProperty.Name & " = " & objClassProperty.V +alue WScript.Echo " " & strOutput Next WScript.echo " " Next WScript.Quit(0)

my beginner attempt in perl

use strict; use Win32::OLE; use Data::Dumper; my $strServ = "10.x.x.x"; my $wmipath = "root\\Citrix\\WanScaler"; my $strUsrN = "Administrator"; my $strPasswd = "******"; my $objWMILocator; unless( Win32::OLE::CreateObject( "WbemScripting.SWbemLocator", $objWM +ILocator )) { print("Cannot create objWMILocator ($!)\n"); exit; } # TBD - FIX THIS # objWMILocator.Security_.AuthenticationLevel = 6 my $objWMIService; $objWMIService = $objWMILocator->ConnectServer($strServ,$wmipath,$strU +srN,$strPasswd) or die "Can't access WMI on remote machine $strServ\n"; my $colItems = $objWMIService->ExecQuery( "Select * From Citrix_WS_Sys +temConfig" ) or die "ExecQuery failed"; foreach my $objItem ( in $colItems ) { #code yet to be written } print "\nfinished\n";

Replies are listed 'Best First'.
Re: Win32::OLE VB to perl translation problem
by Anonymous Monk on Sep 19, 2012 at 20:52 UTC
Re: Win32::OLE VB to perl translation problem
by Corion (Patriarch) on Sep 20, 2012 at 07:23 UTC

    If you are interested in just running some WMI queries, DBD::WMI might be of assistance. The drawback is that DBD::WMI does not concern itself much with permissions and remote machines, so you have to do some work to make it log on to remote machines with the appropriate credentials.