Jump to content

VBS in Autoit .Exe ?


Roach
 Share

Recommended Posts

Hi,

For work im making a "pc" cleaner.

What it do : clean I.E, Stop all VPC by closing the process, than delete all the directory's associated with them.

Now i want todo the same with Virtual server, so it has to stop and remove the images out of the console so we can remove them.

Ive build a script (rather stole and modified ;) ) that takes info from the virtual server, and for each item it finds removes it.

On Error Resume Next

Set vpcApp = CreateObject("VirtualServer.Application")
Set vmCollection = vpcApp.VirtualMachines

    For each vm in vmCollection


    Set objVM = vpcApp.FindVirtualMachine(vm.Name)
    objVM.Turnoff()
    errReturn = vpcApp.UnregisterVirtualMachine(objVM)

    next

But how do i get something like this in Autoit ? ive copy paste it in but that the .exe just hangs and does nothing.

Sorry if im asking the obvious but i cant find the answer anywhere.

Link to comment
Share on other sites

Hi,

not verified:

You may google for "msdn VirtualServer Com Objects" as well.......

$vpcApp = ObjCreate ("VirtualServer.Application")
$vmCollection = $vpcApp.VirtualMachines

For $vm in $vmCollection
    $objVM = $vpcApp.FindVirtualMachine($vm.Name)
    $objVM.Turnoff()
    $vpcApp.UnregisterVirtualMachine(objVM)
Next

;-))

Stefan

Link to comment
Share on other sites

Hey Stefan, thanks for your reply.

The script is giving me a Syntax Error

:

C:\PSExec\Vsunregister.au3(7,43) : ERROR: syntax error

$vpcApp.UnregisterVirtualMachine(objVM)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\PSExec\Vsunregister.au3 - 1 error(s), 0 warning(s)

i dont get it ? it should work ? i tryed some other syntaxes, tryed different name, do it other but i keep getting this error.

i tryed the DeleteVirtualmachine syntax taken from the MSDN website but that does not work also.

Link to comment
Share on other sites

Hi,

sry for paste and copy error by translating the vbs code.

I still don't know if it is working, but you should use:

$vpcApp.UnregisterVirtualMachine($objVM)

;-))

Stefan

Tried that also, it gives following error in Autoit :

---

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\PSExec\Vsunregister.au3"

C:\PSExec\Vsunregister.au3 (2) : ==> Variable must be of type "Object".:

$vmCollection = $vpcApp.VirtualMachines

$vmCollection = $vpcApp^ ERROR

->13:39:21 AutoIT3.exe ended.rc:1

--

And when trying to excecute on the machine :

--

Line -1:

Error: The requested action with this object has failed.

--

Link to comment
Share on other sites

Hi,

sry i can't help you anymore, because i haven't had any Virtual Server running. So i can't test the script.

the code seemed to be ok, as far as i can interprete msdn description:

http://msdn.microsoft.com/en-us/library/aa368669(VS.85).aspx

;-((

Stefan

Link to comment
Share on other sites

Hi,

sry i can't help you anymore, because i haven't had any Virtual Server running. So i can't test the script.

the code seemed to be ok, as far as i can interprete msdn description:

http://msdn.microsoft.com/en-us/library/aa368669(VS.85).aspx

;-((

Stefan

Hmm ok, thanks for trying atleast ;)

The code in .vbs form works like a charm, its has to be something into the conversion to autoit what is wrong, i just cant put my finger on it cause i dun rlly have a developers eye.. altough it is just a small code :evil:

Anybody else wanna give it a try ??

Link to comment
Share on other sites

Hi,

maybe this is usefull:

http://www.autoitscript.com/forum/index.php?showtopic=104565&st=0&p=739702&hl=virtual%20server&fromsearch=1&#entry739702

;-))

Stefan

Maybe, put in some MsgBoxes for debugging which object fails:

$vpcApp = ObjCreate ("VirtualServer.Application")
MsgBox (0,"", "Func Call VirtualMachines")
$vmcollection = $vpcApp.VirtualMachines ()

For $vm in $vmCollection
    MsgBox (0,"", "FindVirtualMachine")
    $objVM = $vpcApp.FindVirtualMachine($vm.Name)
    MsgBox (0,"", "TurnOff")
    $objVM.Turnoff ()
    MsgBox (0,"", "Unregister")
    $vpcApp.UnregisterVirtualMachine($objVM)
Next
Edited by 99ojo
Link to comment
Share on other sites

Hi,

maybe this is usefull:

http://www.autoitscript.com/forum/index.php?showtopic=104565&st=0&p=739702&hl=virtual%20server&fromsearch=1&#entry739702

;-))

Stefan

Maybe, put in some MsgBoxes for debugging which object fails:

$vpcApp = ObjCreate ("VirtualServer.Application")
MsgBox (0,"", "Func Call VirtualMachines")
$vmcollection = $vpcApp.VirtualMachines ()

For $vm in $vmCollection
    MsgBox (0,"", "FindVirtualMachine")
    $objVM = $vpcApp.FindVirtualMachine($vm.Name)
    MsgBox (0,"", "TurnOff")
    $objVM.Turnoff ()
    MsgBox (0,"", "Unregister")
    $vpcApp.UnregisterVirtualMachine($objVM)
Next

yeah i already checked that link, thing is he only does it for 1 machine wich makes it a little easyer i think.

Good idea about the msgboxes. it showes the "Func Call VirtualMachines" and than it drops out with " The requested action with this object has failed"

Link to comment
Share on other sites

Hi,

i think there is an error creating the object:

$vpcApp = ObjCreate ("VirtualServer.Application")
If @error Then MsgBox (0,"Error", "Creating Object fail...")

1) See helpfile ObjCreate to get more information about function call

2) You may check the suggestions for getting rid of the error

Good luck

;-))

Stefan

i added that peace of code but dont get an error, so the function is correct. i even copyd it from the other page.

the error msg :

C:\Vsunregister.au3 (6) : ==> The requested action with this object has failed.:

$vmcollection = $vpcApp.VirtualMachine

$vmcollection = $vpcApp.VirtualMachine^ ERROR

Edited by Roach
Link to comment
Share on other sites

i think it may be impossible ??? read : http://www.autoitscript.com/forum/index.php?showtopic=76767&st=0&p=556148&hl="Virtual%20Server"&fromsearch=1&#entry556148

Same problem as me and never could get the right code !!!!

Link to comment
Share on other sites

Good morning, got a little impatient yesterday but nothing a good night sleep cant fix ;)

I inputed an extra error handler from the other topic, this is the output :

>Running:(3.3.0.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Vsunregister.au3"    
--> COM Error Encountered in Vsunregister.au3
----> $IEComErrorScriptline = 7
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = Either a required impersonation level was not provided, or the provided impersonation level is invalid.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in Vsunregister.au3
----> $IEComErrorScriptline = 9
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable is not of type 'Object'.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0

cant make any sence of it tough.

Edited by Roach
Link to comment
Share on other sites

ah Yes ! got it working !!!

The Final Code :

#include <IE.au3>

_IEErrorHandlerRegister()

$vpcApp = ObjCreate ("VirtualServer.Application", "localhost" )
MsgBox (0,"", "Func Call VirtualMachines")
$vmcollection = $vpcApp.VirtualMachines

For $vm in $vmCollection
    MsgBox (0,"", "FindVirtualMachine")
    $objVM = $vpcApp.FindVirtualMachine($vm.Name)
    MsgBox (0,"", "TurnOff")
    $objVM.Turnoff ()
    MsgBox (0,"", "Unregister")
    $vpcApp.UnregisterVirtualMachine($objVM)
Next

The problem was "Localhost" at the objcreate !

Link to comment
Share on other sites

Hi,

for christ sake, i was thinking about that as well, because of the other thread i mentioned.

As i haven't had any VirtualServer running, i didn't post.

Otherwise i would have tested it by myself and then post result... ;)

Great. Well done

;-))

Stefan

Link to comment
Share on other sites

Hi,

for christ sake, i was thinking about that as well, because of the other thread i mentioned.

As i haven't had any VirtualServer running, i didn't post.

Otherwise i would have tested it by myself and then post result... ;)

Great. Well done

;-))

Stefan

Haha well it was a good troubleshoot excercise for me :evil: Thanks for your help man rlly appreciate it, you were the light in the dark that gave me atleast some hope :evil:

ps. is there somekind of easy method to read that msdn website ?? even with the code workingi n my script i dont understand it.

Edited by Roach
Link to comment
Share on other sites

Haha well it was a good troubleshoot excercise for me ;) Thanks for your help man rlly appreciate it, you were the light in the dark that gave me atleast some hope :evil:

Sorry to come in late, but this is a somewhat documented issue with the Virtual Server COM interface, this blog entry has some details about it.

As far as working from AutoIt3 is concerned yours is the perfect fix, though I would have used the @ComputerName macro in place of "localhost" for the server name in ObjCreate().

Congrats and cheers.

ps. is there somekind of easy method to read that msdn website ?? even with the code workingi n my script i dont understand it.

There are any number of jokes about the obfuscated quality of the MSDN library. You'll get the best mileage from it if you use Internet Explorer to browse it, but it is what it is beyond that.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...