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

I am trying to do some remote scripting using Win32::OLE. The following code should return a description of all the drives on the system. This works perfectly in command prompt. We would like to run it in cgi-bin so it works remotely.
use Win32::OLE 'in'; my $strComputer = "192.168.0.10"; my $objWMI = Win32::OLE->GetObject("winmgmts:\\\\$strComputer\\root\\c +imv2"); # or die "Failed to create object"; my $objDisks = $objWMI->InstancesOf("Win32_LogicalDisk"); for my $objDisk (in $objDisks){ print "DeviceID: ", $objDisk-DeviceID, "\n"; print "FileSystem: ", $objDisk->FileSystem ,"\n"; print "FreeSpace: ", $objDisk->FreeSpace,"\n"; print "Name: ", $objDisk->Name,"\n"; print "Size: ", $objDisk->Size,"\n"; print "\n"; }
When we run it remotely through Firefox it gives: Can't call method "InstancesOf" on an undefined value at (file name) line 5. I have spent all morning and much of the afternoon reading about OLE (Object Linking and Embedding), the COM (Component Object Model), WMI (Windows Management Instrumenation) and remote scripting in general for Windows 2000.

Replies are listed 'Best First'.
Re: Win32::OLE thru CGI
by Bloodnok (Vicar) on Jan 08, 2009 at 19:54 UTC
    Self-evidently, $objWMI is undefined - as the error tells you. You may glean more info if you change
    my $objWMI = Win32::OLE->GetObject("winmgmts:\\\\$strComputer\\root\\c +imv2"); # or die "Failed to create object";
    to read
    my $objWMI = Win32::OLE->GetObject("winmgmts:\\\\$strComputer\\root\\c +imv2"); die "GetObject(winmgmts:\\\\$strComputer\\root\\cimv2) failed - " . Wi +n32::OLE->LastError() if Win32::OLE->LastError();
    i.e. when OLE fails, get it OLE to tell you why it hasn't worked.

    .oO(Given the context, using CPI::Carp may also prove useful)

    Update:

    Modified error report to give a string.

    A user level that continues to overstate my experience :-))
Re: Win32::OLE thru CGI
by frieduck (Hermit) on Jan 08, 2009 at 19:55 UTC
    Hmmm.... Your CGI is probably running as a non-privileged user. Have you tried granting permissions in wmimgmt.msc to that user? This might provide some help.
Re: Win32::OLE thru CGI
by NetWallah (Canon) on Jan 08, 2009 at 19:59 UTC
    It is most likely that your CGI script is running under an account that does not have privileges to access WMI on the target computer.

    Also - it is probably a good idea to n-comment the "or die" when you create the WMI object.

    More clues would be in your event logs and/or Apache/IIS logs.

         ..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.