Valnurat

Convert VBS to AU

9 posts in this topic

Who could help me to convert this vbs to AuoIT?

on error resume next

dim oCPAppletMgr 'Control Applet manager object.
dim oClientAction 'Individual client action.
dim oClientActions 'A collection of client actions.

'Get the Control Panel manager object.
set  oCPAppletMgr=CreateObject("CPApplet.CPAppletMgr")
if err.number <> 0 then
    Wscript.echo "Couldn't create control panel application manager"
    WScript.Quit
end if

'Get a collection of actions.
set oClientActions=oCPAppletMgr.GetClientActions
if err.number<>0 then
    wscript.echo "Couldn't get the client actions"
    set oCPAppletMgr=nothing
    WScript.Quit
end if

'Display each client action name and perform it.
For Each oClientAction In oClientActions

    if oClientAction.Name = "Request & Evaluate Machine Policy" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Software Metering Usage Report Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Updates Source Scan Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Request & Evaluate User Policy" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Hardware Inventory Collection Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Software Inventory Collection Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Application Global Evaluation Task" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Software Updates Assignments Evaluation Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Discovery Data Collection Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "MSI Product Source Update Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
    if oClientAction.Name = "Standard File Collection Cycle" then
        wscript.echo "Performing action " + oClientAction.Name 
        oClientAction.PerformAction
    end if
next

set oClientActions=nothing
set oCPAppletMgr=nothing

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites



Whether this is related to this:

https://www.autoitscript.com/forum/forum/34-system-center-configuration-manager/

and this:

 

 

??

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

The conversion was quite easy:

Local $oClientAction ; 'Individual client action.
Local $oClientActions ; 'A collection of client actions.
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

; 'Get the Control Panel manager object.
Local $oCPAppletMgr = ObjCreate("CPApplet.CPAppletMgr")
If @error Then
    ConsoleWrite("Couldn't create control panel application manager")
    Exit
EndIf

; 'Get a collection of actions.
$oClientActions = $oCPAppletMgr.GetClientActions

; 'Display each client action name and perform it.
For $oClientAction In $oClientActions

    If $oClientAction.Name = "Request & Evaluate Machine Policy" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Software Metering Usage Report Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Updates Source Scan Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Request & Evaluate User Policy" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Hardware Inventory Collection Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Software Inventory Collection Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Application Global Evaluation Task" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Software Updates Assignments Evaluation Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Discovery Data Collection Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "MSI Product Source Update Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
    If $oClientAction.Name = "Standard File Collection Cycle" Then
        ConsoleWrite("Performing action " & $oClientAction.Name)
        $oClientAction.PerformAction
    EndIf
Next

$oClientActions = Null
$oCPAppletMgr = Null

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Is this what you need ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

:)

Yes, It was.

Thank you

Btw. When is the func _ErrFunc used?

 

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
38 minutes ago, Valnurat said:

:)

Yes, It was.

Thank you

Btw. When is the func _ErrFunc used?

 

On the third line of the script. When an object error is triggered - the error function is executed.

Share this post


Link to post
Share on other sites

Thank you.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

I have a issue with this. When I run it I get an error while trying to create the control panel for application manager.

Can someone help me with why.

; 'Get the Control Panel manager object.
Local $oCPAppletMgr = ObjCreate("CPApplet.CPAppletMgr")
If @error Then
    ConsoleWrite("Couldn't create control panel application manager")
    Exit
EndIf

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

@Valnurat it works fine for me if I run as 64bit,  which you may need to do depending on the version of Config Mgr. you're running.

 

#AutoIt3Wrapper_UseX64 = Y

; 'Get the Control Panel manager object.
Local $oCPAppletMgr = ObjCreate("CPApplet.CPAppletMgr")
If @error Then
    ConsoleWrite(@error & " Couldn't create control panel application manager" & @CRLF)
    Exit
Else
    If IsObj($oCPAppletMgr) Then ConsoleWrite("Object created" & @CRLF)
EndIf

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Yes, that was the problem.

Thank you.


Yours sincerely

Kenneth.

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

  • Similar Content

    • ur
      By ur
      I am maintaining all the reusable code in a separate file as library.au3.
      In that file I have referenced some dependent files using fileinstall, so that they will be extracted when necessary.
       
      Problem is, if I use a function in the library.au3 in another script which doesn't require this dependent file, as I am including the whole file using include tag, it is embedding that file also.
      Is there any way to exclude that.
       
    • GTAVLover
      By GTAVLover
      I recently tried to use ControlClick method to send a mouse click command to a button in a application, but I noticed that it is not working when I give first parameter as a window handle (HWND). But, when I give class name or window title, it works fine. I used AutoItX3 and VBScript. 
      Following are the commands I tried in VBScript:
      Dim WINAPI: Set WINAPI = WScript.CreateObject("WinAPIWrapper.WINAPI") Dim AutoItX3: Set AutoItX3 = WScript.CreateObject("AutoItX3.Control") Dim WindowHandle: WindowHandle = WINAPI.WinAPI_FindWindow("my window title", "my window class") 'Window handle obtains fine by my wrapper function 'Above window handle is obtained as a hexadecimal string. (I.E. - 0x00000000) I tried it like: WScript.Echo CStr(AutoItX3.ControlClick(WindowHandle, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(CLng("&h" + Replace(WindowHandle, "0x", "")), "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK WScript.Echo CStr(AutoItX3.ControlClick(0x00000000, "", "[CLASS:Button; INSTANCE:1]")) // DOES NOT WORK Only following commands work: WScript.Echo CStr(AutoItX3.ControlClick("[CLASS:my window class]", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE WScript.Echo CStr(AutoItX3.ControlClick("My window title", "", "[CLASS:Button; INSTANCE:1]")) // WORKS FINE  
      If any of your suggestions don't work, I will have to write a wrapper function myself to send mouse click commands. I chosen AutoIt V3 because it is good specially when comes to send keystrokes to applications. Please tell me why this won't work when I give window handle as first parameter.
      Thanks in advance.
    • lattey
      By lattey
      i have a vbscript that called an autoit exe file and autoit exe file will return value to vbscript.
      vbscriptto call the exe and create array:
      Set objShell = CreateObject("WScript.Shell") objShell.Run ( "C:\Datalog\test.exe") Dim intCtr: intCtr=-1 Dim tempArr() Set UID = CreateObject("System.Collections.ArrayList") CurLot = "" For Each filelog in FileList LogFile = Split(filelog, "~")(1) Set otf = fso.OpenTextFile("C:\Datalog\" & LogFile, 1) intCtr=intCtr+1 sFile = Split(LogFile, "_") CurStep = sFile(4) Redim preserve tempArr(intCtr) tempArr(intCtr)=CurStep next autoit:
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> Global $Count = 10 Global $CheckBox[$Count] global $array1[1] $hGUI = GUICreate("Test", 500, 500) Global $array_Pstep[10] = ["P1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10"] $Spacing = 24 For $i = 0 To UBound($array_Pstep) - 1 $CheckBox[$i] = GUICtrlCreateCheckbox($array_Pstep[$i], 80, $Spacing + (20 * $i), 65, 17) Next $submit = GUICtrlCreateButton("submit",10, 300, 80, 30) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg case $submit _ArrayDisplay($array1) Case Else For $i = 0 To $Count - 1 If $CheckBox[$i] = $Msg Then MsgBox("", "Pressed", $i) _ArrayAdd($array1, $array_Pstep[$i]) ExitLoop EndIf Next EndSwitch WEnd i need to compare the array in vbscript and array return by autoit. but i dont know how to pass the value of array in autoit to vbscript. Please help.
    • sumandevadiga
      By sumandevadiga
      Hello 
      Trying to add below code in my main script but this is not functioning can you advise what else i need to do?
       
      Dim fn As String Const myDir As String = "C:\AR\" '<- alter here Const newFolder As String = "C:\AR1\" '<- alter here fn = Dir(myDir & "AR_*.xlsm") Do While fn <> "" FileCopy myDir & fn, newFolder & Replace(fn, "AR", "AI") fn = Dir Loop  
    • Valnurat
      By Valnurat
      Is there any change that I can return a code for success or not success in my script?
      I have a script that look in a SQL db and write to the registry.
      I want to return some kind of a control, because I will call my script *.exe from VBScript.
      _Main() Func _Main() Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner Local $oConnection = _ADO_Connection_Create() _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'" $oRecordset = _ADO_Execute($oConnection, $sQUERY) $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False) $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray) RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0]) EndFunc