Sign in to follow this  
Followers 0
tazlikesrobots

VB script to Auto it conversion did not work

7 posts in this topic

I used VB convert to convert a VB script, but I did not have any luck with the conversion. Anyone have an idea what I did wrong??

VB Script source

strComputer = "."
Set colProcesses = GetObject("winmgmts:" & _
   "{impersonationLevel=impersonate}!\\" & strComputer & _
   "\root\cimv2").ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcesses

    Return = objProcess.GetOwner(strNameOfUser)
    If Return <> 0 Then
        Wscript.Echo "Could not get owner info for process " & _  
            objProcess.Name & VBNewLine _
            & "Error = " & Return
    Else 
        Wscript.Echo "Process " _
            & objProcess.Name & " is owned by " _ 
            & "\" & strNameOfUser & "."
    End If
Next

Code Generated by VB convert

; ----------------------------------------------------------------------------
;
; VBScript to AutoIt Converter v0.4
;
; ----------------------------------------------------------------------------

#include <bk-logfile.au3>

$strComputer = "."
 $colProcesses = ObjGet("winmgmts:" & _
   "{impersonationLevel=impersonate}!\\" & $strComputer & _
   "\root\cimv2").ExecQuery("Select * from Win32_Process")

For $objProcess in $colProcesses

    Return = $objProcess.GetOwner($strNameOfUser)
    If Return <> 0 Then
        _WriteLog ("Could not get owner info for process " & _  )
            $objProcess.Name (& $VBNewLine _)
            & "Error = " & Return
    Else 
        _WriteLog ("Process " _)
            & $objProcess.Name (& " is owned by " _ )
            & "\" & $strNameOfUser & "."
    EndIf
Next

Share this post


Link to post
Share on other sites



There are some pretty obvious problems with ")" there -- the errors you get when trying to run it should point this out pretty clearly. Start by clening up the obvious syntax issues.

After that, there are issues with constants used by vbs like VBNewLine and Return that you should readily find replacements for in AutoIt (like @CR or @CRLF).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try to separte the execution.

$strComputer = "."
$objProcesses = ObjGet("winmgmts:" & _
   "{impersonationLevel=impersonate}!\\" & $strComputer & _
   "\root\cimv2")
$colProcesses = $objProcesses.ExecQuery("Select * from Win32_Process")

- added $strComputer to script.

Edited by Joon

Share this post


Link to post
Share on other sites

Thanks for the help! I am fairly new to autoit and VB scripting, but I am catching on on what to do! :P

Share this post


Link to post
Share on other sites

Thanks for the help! I am fairly new to autoit and VB scripting, but I am catching on on what to do! :P

I see that you are trying to get the hang of using WMI in AutoIt scripts. I would recommend you take a peek at my CompInfo Library. (Link in my signature) It uses WMI on most of the functions to obtain information about computer systems.

I hope this helps some,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I see that you are trying to get the hang of using WMI in AutoIt scripts. I would recommend you take a peek at my CompInfo Library. (Link in my signature) It uses WMI on most of the functions to obtain information about computer systems.

I hope this helps some,

JS

Thanks for the information :P It is great to have examples to look at when learning new code. Not to mention you got some awesome functions written.

Share this post


Link to post
Share on other sites

Thanks for the information :P It is great to have examples to look at when learning new code. Not to mention you got some awesome functions written.

No problem. I am glad they helped you.

Thanks,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
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
Sign in to follow this  
Followers 0