Jump to content
Valnurat

Convert VBS to AU

Recommended Posts

Valnurat

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
mLipok

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 UDF * 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 * Good coding practices in AutoIt * 

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: 2018-03-17

Share this post


Link to post
Share on other sites
mLipok

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 UDF * 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 * Good coding practices in AutoIt * 

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: 2018-03-17

Share this post


Link to post
Share on other sites
Valnurat

:)

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
Juvigy
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
Valnurat

Thank you.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Valnurat

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
JLogan3o13

@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
Valnurat

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

    • jdegraff
      By jdegraff
      I'm trying to add a bit of functionality to the FastStone File Rename dialog. I can access every control that I need to except the one that contains the files to be renamed. If I do some exploring in a vbScript shell I get
      :c  = "TTntTreeView.UnicodeClass1"
      :?aut.ControlTreeView(win,"",c,"GetItemCount","","")
      5
      You can see that the treeview control reports having five items, which is the number displayed. If I manually select (mouse) item #3 I can see the result by
      :?aut.ControlTreeView(win,"",c,"GetSelected","1","")
      #3
      But I do not know how to get the text for the selected item. If "#3" is the item reference then I should be able to
      :?aut.ControlTreeView(win,"",c,"GetText","1","#3")
      or
      :?aut.ControlTreeView(win,"",c,"GetText","1","#3")
      if I go strictly by the help file, but it returns nothing.
      :?aut.ControlTreeView(win,"",c,"Exists","","3")
      1
      So it appears that item 3 exists, but
      :?aut.ControlTreeView(win,"",c,"GetText","","3")
      does not have any text???
      :?aut.ControlTreeView(win,"",c,"Exists","","9")
      1
      and it also appears item 9 exists (it does not)
      :?aut.ControlTreeView(win,"",c,"Select","","")
      1
      causes the first item to be selected, as does
      :?aut.ControlTreeView(win,"",c,"Select","","3")
      1
      Here is the output from the Window Info tool
      >>>> Window <<<<
      Title:  Batch Image Convert / Rename
      Class:  TBatchConvert
      Position:   501, 83
      Size:   760, 520
      Style:  0x16CD0000
      ExStyle:    0x00010100
      Handle: 0x0000000001950796
      >>>> Control <<<<
      Class:  TTntTreeView.UnicodeClass
      Instance:   1
      ClassnameNN:    TTntTreeView.UnicodeClass1
      Name:   
      Advanced (Class):   [CLASS:TTntTreeView.UnicodeClass; INSTANCE:1]
      ID: 37030040
      Text:   
      Position:   354, 79
      Size:   378, 188
      ControlClick Coords:    108, 86
      Style:  0x54010039
      ExStyle:    0x00000200
      Handle: 0x0000000002350898
      >>>> Mouse <<<<
      Position:   970, 279
      Cursor ID:  0
      Color:  0xE1E1E1
      >>>> StatusBar <<<<
      >>>> ToolsBar <<<<
      >>>> Visible Text <<<<
      Batch Rename
      ...
      D:\temp\picsave\
      Images + Videos (*.jpg;*.jpe;*.jpeg;*.bmp;*.gif;*.tif;*.tiff;*.cur;*.ico;*.png;*.pcx;*.jp2;*.j2k;*.tga;*.ppm;*.wmf;*.psd;*.crw;*.nef;*.cr2;*.orf;*.raf;*.dng;*.mrw;*.pef;*.srf;*.arw;*.rw2;*.x3f;*.sr2;*.srw;*.nrw;*.rwl;*.eps;*.avi;*.mpeg;*.mpg;*.wmv;*.mov;*.mp4;*.mts;*.mkv;*.m4v)
      Search and Replace
      Use Filename Template
      No Sort
      Clear
      Remove
      Add All
      Add
      Preview
      Close
      Rename
      No Change
      ?
       
       


    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • 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.
×