COM error in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kimi
Forum Newbie
Posts: 2
Joined: Thu Aug 31, 2006 5:48 am

COM error in PHP

Post by kimi »

Hi ALL,

I am trying a PHP script which will automatic startup for virtual machines under Microsoft Virtual Server 2005 r2 but it failed due to COM object saying Source unknown But the same thing when i tried through VB script it works fine.
VB script:

Set objVS = CreateObject("VirtualServer.Application")
Set objVM = objVS.FindVirtualMachine("VM Name")
objVM.Startup();

It Worked fine
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ _ _ _ _ _
PHP Script:

$objVS = new COM(" VirtualServer.Application");
$objVM = $objVS->FindVirtualMachine("Scorpio");
$objVM->Startup();
it throuhgs Error at FindVirtualMachine function saying

ERROR: Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown


Plese Help me it's urgengt !!

Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Where and how are those both scripts invoked?
What conditions/privileges/... must apply for FindVirtualMachine to find the named machine?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The COM extension may not be able to find the GUID associated with the string you have giving it. I can see there's a space in the posted code snippet (which should really be in

Code: Select all

tags, by the way). That may confuse COM.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

feyd wrote:I can see there's a space in the posted code snippet (which should really be in

Code: Select all

tags, by the way). That may confuse COM.[/quote]Right, but that would raise another exception (message)[quote]Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object ` xyz.abc': invalid syntax'[/quote]
edit: at least on winxp it does...
kimi
Forum Newbie
Posts: 2
Joined: Thu Aug 31, 2006 5:48 am

Post by kimi »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

   I  tried many times but still it's troughing the same error, i tried some other example but it seems actual problem is in php, it will not accessing COM properly i tried like this

[u]vb script:-[/u]

[syntax="vbnet"]'Script Begins

On Error Resume Next

'Connect to Virtual Server
Set virtualServer = CreateObject("VirtualServer.Application")

'Get collection of virtual machines
set vmCollection = virtualServer.VirtualMachines

'Iterate over the virtual machines and display data
For Each vm in vmCollection
    Wscript.Echo "=============================="
    Wscript.Echo "Name: " & vm.Name
    Wscript.Echo
    Wscript.Echo "Notes: " & vm.Notes
    
    Wscript.Echo "=============================="

Next

'Script Ends
Works Fine

PHP Script[/syntax]

Code: Select all

<?php
f1();
function f1()
{
//Connect to Virtual Server
 $virtualServer = new COM("VirtualServer.Application");

//Get collection of virtual machines
 $vmCollection = $virtualServer->VirtualMachines;
//Iterate over the virtual machines and display data
 foreach( $vmCollection as $vm)
{
    print("\n==============================");
    print( "\nName: " $vm->Name);
    print("\n==============================");
}
}
Throughs Run time ERROR:

Code: Select all

Fatal error: Uncaught exception 'com_exception' with message 'Source: Unknown
Description: Unknown' in C:\Program Files\lxlabs\ext\php\test.php:9
Stack trace:
#0 C:\Program Files\lxlabs\ext\php\test.php(9): f1()
#1 C:\Program Files\lxlabs\ext\php\test.php(2): f1()
#2 {main}
  thrown in C:\Program Files\lxlabs\ext\php\test.php on line 9

When i cought Exception it will tough Object #2

please help me it's urgent


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply