NetWallah has asked for the wisdom of the Perl Monks concerning the following question:
The error I get is:use strict; use warnings; use Win32::OLE qw(in with valof) ; use constant RUNNING=>5; my @VMList; #Connect to Virtual Server my $VirtualServer = Win32::OLE->new('VirtualServer.Application' ) or die "Oops, cannot Connect to Host Virtual server\n" & Win32 +::OLE->LastError(); print "Name: " . valof $VirtualServer->Name() . "\n"; foreach my $vm (in $VirtualServer->VirtualMachines) { print " Name: " . valof $vm->Name . " State: " . valof $vm->Sta +te . "\n"; }
(First Line number corresponds to the first (print "Name...)) statement.Win32::OLE(0.1403) error 0x80070542: "Either a required impersonation +level was not provided, or the provided impersonation level is invalid" in METHOD/PROPERTYGET "Name" at d:\Scripts\BackupVM.pl line 14 Use of uninitialized value in concatenation (.) or string at d:\Script +s\BackupVM .pl line 14. Name: Win32::OLE(0.1403) error 0x80070542: "Either a required impersonation +level was not provided, or the provided impersonation level is invalid" in METHOD/PROPERTYGET "VirtualMachines" at d:\Scripts\BackupVM.pl +line 16 Can't call method "Name" on an undefined value at d:\Scripts\BackupVM. +pl line 18 .
I know there is no security or user rights problem because
a) The equivalent VB code runs fine
b) I'm running as the godly domain admin
Here is the relevent snippet of (ugh!) VB:
Option Explicit On Error Resume Next Dim op,who,I,virtualServer Dim vmachine(50) Dim objvmColl,objVM Const RUNNING=5 Const ForReading=1,ForWriting=2 'Connect to Virtual Server Set virtualServer = CreateObject("VirtualServer.Application") op=WScript.Arguments(0) Who=WScript.Arguments(1) I=0 if op = "list" then Wscript.Echo "Name: " & virtualServer.Name Set objVMColl = virtualServer.VirtualMachines If objVMColl.Count = 0 Then Wscript.Echo " Virtual machines: [none]" Else Wscript.Echo "Virtual machines: " & objVMColl.Count For Each objVM in objVMColl VirtualMachineInfo(objVM) Wscript.Echo " Name: " & objVM.Name & " State: " & obj +VM.State Next End If end if wscript.echo I & " machines are RUNNING: " Redim preserve vmachine(I) Dim vm, fso, MyFile
"There are only two truly infinite things. The universe and stupidity, and I'm not too sure about the universe"- Albert Einstein
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32 VirtualServer Automation prob: Perl Vs. VB
by NetWallah (Canon) on May 02, 2005 at 06:55 UTC |