Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Win32::OLE VB to perl translation problem

by anadem (Scribe)
on Sep 19, 2012 at 20:42 UTC ( #994536=perlquestion: print w/replies, xml ) Need Help??
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 (Pope) 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994536]
Approved by chacham
and snow settles gently...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-03-29 02:26 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (343 votes). Check out past polls.