The first thing you should try to do is add this line at the top of your script if you're running into strange errors with Win32::OLE:
Win32::OLE->Options(Warn => 9); That will turn on the big-time warnings. I suspect you're getting this error: "OLE exception from "SWbemLocator": User credentials cannot be used for local connections Win32::OLE(0.1702) error 0x80041064 in METHOD/PROPERTYGET "ConnectServer" at C:\Documents and Settings\tjohnson\Desktop\test.pl line 12" This is because you cannot specify credentials for local connections. I've racked my brain for why this would be necessary and I honestly can't think of why that would be. Microsoft in its infinite wisdom decided that it would be a security risk if we were able to run WMI queries locally with specified usernames and passwords. There are probably workarounds, though. I think you would be able to sort of leapfrog it by spawning a second process under different credentials and then having that process run the query. If that's not the error you're getting, you may have to re-examine your script, because I was able to do it with this script: ################################ use strict; use warnings; use Win32::OLE qw(in); $| = 1; Win32::OLE->Option(Warn => 9); my $locator = Win32::OLE->CreateObject('WbemScripting.SWbemLocator') or warn; my $service = $locator->ConnectServer('computer', "root\\cimv2", "domain\\user", 'password'); my @col = in($service->ExecQuery('Select * From Win32_Process')); foreach my $proc(@col){ print $proc->{Name}."\n"; } ################################# -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, July 20, 2006 4:44 PM To: perl-win32-admin@listserv.ActiveState.com Subject: Running Windows WMI Query as Different User... Hello. Looking for some assistance on setting up my Win32 perl script that does WMI Query, so that is runs as a specified user (not the user who will fire off the script). Wrote a very crude VBScript program a while ago that worked (but need to re-write in perl) and it did the following... Setup variables for the Admin user I intended to use, for their username and password, then fed the WMI query through the following VBScript function (worked fine): Working VBScript Method: Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objSWbemLocator.ConnectServer _ (sComputer, "root\cimv2", strUser, strPassword) (Where "sComputer", "strUser" and "strPassword" were the string variables containing the computer name, username and password) Can't seem to find the same functionality in perl... Tried to append the same type of variables to my (working) call: my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$sComputer\\root\\CIMV2") or warn "WMI connection failed: $!\n"; Changing it to: my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$sComputer\\root\\CIMV2\\$strUser\\$ strPassword") or warn "WMI connection failed: $!\n"; but does not allow. Has anyone done this? Need script to run as specified user. - Joe Pantera, Admin / DBA _______________________________________________ Perl-Win32-Admin mailing list Perl-Win32-Admin@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs