[HOWTO] Using WMI in PERL (Scripts for Remote computers)

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

Post Reply
User avatar
dev2dev
Cacti User
Posts: 60
Joined: Thu Nov 18, 2004 5:25 am
Location: Hyderabad, India
Contact:

[HOWTO] Using WMI in PERL (Scripts for Remote computers)

Post by dev2dev »

Hi,
I found many scripts contibuted by Devilsun for windows platform
I have tested all of his scripts which are running perfect in windows 2003
(Scripts for IIS, SQL Server)

[If you have problem querying sql server in local computer itself (using wmi, see links below]
This tips are for thosee members who are facing problem using the script to query remote computer. And only for those members who are able to sucessfully querying LOCALMACHINE

I am not going to explain anyting in detail, (coz every thing is new to me, right from the cacti,php,perl,wmi)

So this is the quick solution for those who want to test it for the remote computer.

I have added all new variables, assigned

Code: Select all

#name space
    my $wmipath  = "root\\cimv2";
#domainname\username   
    my $user     = "mydomain\\adminuser";
#password
   my $pwd      = "dumpass";

#New variable again to hold the instance of swbemlocator
   my $wmiwebloc = Win32::OLE->new('WbemScripting.SWbemLocator') ||
		     die "Cannot access WMI on local machine: ", Win32::OLE->LastError; 

#old way of creating $wmi object
#no need of $class
   my $class = "WinMgmts://$computer";
   my $wmi = Win32::OLE->GetObject($class);

#new way which works for both the local and remote computer
#only host name is compulsary
   my $wmi = $wmiwebloc->ConnectServer($computer,$wmipath,$user,$pwd);
As I said, I am very new, so I am looking for Devilsun and others to optimise code and make it more configurable and customisable

This are the links which helped me solving the problem querying SQL server 2000 (in both, local and remote)

http://support.microsoft.com/default.as ... -us;820847
http://support.microsoft.com/default.as ... -us;827260

connecting to remote computer
http://msdn.microsoft.com/library/defau ... mputer.asp
Attachments
iis.pl.txt
Just replace hard coded credential parameters with yours
(6.29 KiB) Downloaded 1482 times
Why me lord?
DevilSun
Cacti User
Posts: 166
Joined: Fri Jul 16, 2004 1:59 pm
Location: Oregon

Post by DevilSun »

Very nice, and good job getting that to work off the links I sent you...I figured all it would take is just some messing with to get it to work. :D

I'm a little busy at the moment, but gimme a little bit and I'll work with it a little bit, been real busy here at work and enjoy my free time ;) I'm working with a set of new scripts that are a little bit cleaner, and doing some performance tests as well using native windows scripting.
hem
Posts: 1
Joined: Sat Apr 18, 2009 12:45 pm

Post by hem »

Hi

Can i use this to pun a batch file on remote machine .

or can i use this to run a .exe on remote machine

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests