gabritb01 Posted November 7, 2020 Share Posted November 7, 2020 (edited) Hi, I'm not able to find how to identify and click items in a mmc console (services.msc) using autoit. Could someone tell me which functions should I use? Thanks. Edited November 7, 2020 by gabritb01 Link to comment Share on other sites More sharing options...
caramen Posted November 7, 2020 Share Posted November 7, 2020 Hello, you could try with UIAutomation. Check my signature. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
TheXman Posted November 7, 2020 Share Posted November 7, 2020 (edited) If creating and/or maintaining Windows services is your primary goal, then using the SC.EXE command or WMI's Win32_Service class are probably much more reliable than trying to use mouse clicks on a mmc window. Edited November 7, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
gabritb01 Posted November 7, 2020 Author Share Posted November 7, 2020 I made a gui with more info about services and beside other options, I need to open services.msc with a selected item. Link to comment Share on other sites More sharing options...
TheXman Posted November 7, 2020 Share Posted November 7, 2020 (edited) 4 hours ago, gabritb01 said: I need to open services.msc with a selected item. I'm assuming "item" means service. If so, then here's a very simple way to open the service.msc and select an existing service. #RequireAdmin #include <Constants.au3> If Not ShellExecute("services.msc") Then Exit 1 $hMMC = WinWait("[TITLE:Services; CLASS:MMCMainFrame]", "", 3) If Not $hMMC Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Timed out waiting for services.msc window.") Send("{tab}Print Spooler") Tested & working on Windows 7. Edited November 7, 2020 by TheXman Added #RequireAdmin for Windows 10 gabritb01 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
orbs Posted November 8, 2020 Share Posted November 8, 2020 MMC is subject to automation by COM. have a look at these MSDN articles: MMC 2.0 Automation Object Model Using VBScript with the MMC 2.0 Automation Object Model also, it took a while, but i managed to hunt-down this piece of code i once made according to the above. (even considered making it a full-blown UDF someday, but...) you can get the idea from this example. it involves the "Users and Groups" snap-in, but you can adapt it. oh, and it comes with a bonus - how to implement a COM Error Handler in a UDF, so it does not collide with whatever COM Error Handler the main script employs. enjoy! expandcollapse popup; MSDN root topic: https://msdn.microsoft.com/en-us/library/aa815049(v=vs.85).aspx ; MSDN VB example: https://msdn.microsoft.com/en-us/library/aa815371(v=vs.85).aspx #RequireAdmin #AutoIt3Wrapper_UseX64=Y ; UDF Global $__g_MMC_oCOMError = Null Global $__g_MMC_iCOMError = 0 Global $__g_MMC_sCOMError = '' Func _MMC_GroupShowProperties($sGroup) $__g_MMC_oCOMError = ObjEvent('AutoIt.Error', '__MMC_COMError') Local Const $sMMC_NodeTypeGUID_Groups = '{5D6179CA-17EC-11D1-9AA9-00C04FD8FE93}' Local $oMMC_Application, $oMMC_Document Local $oMMC_Views, $oMMC_View Local $oMMC_Items, $oMMC_Item $oMMC_Application = ObjCreate('MMC20.Application') $oMMC_Application.Load('lusrmgr.msc') $oMMC_Application.Show() $oMMC_Document = $oMMC_Application.Document $oMMC_Views = $oMMC_Document.Views $oMMC_View = $oMMC_Views.Item(1) ; the ListView results pane (?) $oMMC_Items = $oMMC_View.ListItems() For $oMMC_Item In $oMMC_Items If $oMMC_Item.Nodetype = $sMMC_NodeTypeGUID_Groups Then $oMMC_View.ExecuteScopeNodeMenuItem('_EXPLORE', $oMMC_Item) Next $oMMC_View = $oMMC_Views.Item(2) ; the ListView results pane $oMMC_Items = $oMMC_View.ListItems() For $oMMC_Item In $oMMC_Items If $oMMC_Item.Name = $sGroup Then $oMMC_View.Select($oMMC_Item) $oMMC_View.ExecuteSelectionMenuItem('_PROPERTIES') EndIf Next $oMMC_Application.UserControl = 1 Return SetError($__g_MMC_iCOMError, 0, $__g_MMC_iCOMError = 0 ? True : False) EndFunc ;==>_MMC_GroupShowProperties Func __MMC_COMError() $__g_MMC_iCOMError = $__g_MMC_oCOMError.number ; use to check when a COM Error occurs. reset it to 0 after handling the error $__g_MMC_sCOMError = _ 'err.number: ' & $__g_MMC_iCOMError & @CRLF & _ 'err.number (hex): ' & Hex($__g_MMC_iCOMError, 8) & @CRLF & _ 'err.description: ' & $__g_MMC_oCOMError.description & @CRLF & _ 'err.windescription: ' & $__g_MMC_oCOMError.windescription & @CRLF & _ 'err.lastdllerror: ' & $__g_MMC_oCOMError.lastdllerror & @CRLF & _ 'err.scriptline: ' & $__g_MMC_oCOMError.scriptline & @CRLF & _ 'err.source: ' & $__g_MMC_oCOMError.source & @CRLF & _ 'err.helpfile: ' & $__g_MMC_oCOMError.helpfile & @CRLF & _ 'err.helpcontext: ' & $__g_MMC_oCOMError.helpcontext ConsoleWrite($__g_MMC_sCOMError & @CRLF) EndFunc ;==>__MMC_COMError ; MAIN Global $oCOMError = ObjEvent('AutoIt.Error', '__COMError') If Not _MMC_GroupShowProperties('Administrators') Then MsgBox(0, 'Error', 'COM error occurred in UDF.') Global $oMMC_Application = ObjCreate('MMC20.Application') $oMMC_Application.UndefinedAction() Func __COMError() Local $iCOMError = $oCOMError.number ; use to check when a COM Error occurs. reset it to 0 after handling the error Local $sCOMError = _ 'err.number: ' & $iCOMError & @CRLF & _ 'err.number (hex): ' & Hex($iCOMError, 8) & @CRLF & _ 'err.description: ' & $oCOMError.description & @CRLF & _ 'err.windescription: ' & $oCOMError.windescription & @CRLF & _ 'err.lastdllerror: ' & $oCOMError.lastdllerror & @CRLF & _ 'err.scriptline: ' & $oCOMError.scriptline & @CRLF & _ 'err.source: ' & $oCOMError.source & @CRLF & _ 'err.helpfile: ' & $oCOMError.helpfile & @CRLF & _ 'err.helpcontext: ' & $oCOMError.helpcontext MsgBox(0, '', '!COM error in main script') ConsoleWrite('!COM error in main script' & @CRLF) ConsoleWrite($sCOMError & @CRLF) EndFunc ;==>__COMError TheXman 1 Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
gabritb01 Posted November 9, 2020 Author Share Posted November 9, 2020 Thanks to all, TheXman's solution works fine. The other solutions are less intuitive for a person who do this only for hobby. Link to comment Share on other sites More sharing options...
rudi Posted November 12, 2020 Share Posted November 12, 2020 to handle services I'd like to suggest to use powershell: PS C:\Windows\System32\WindowsPowerShell\v1.0> get-command *service CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Get-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet New-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Restart-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Resume-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Set-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Start-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Stop-Service 3.1.0.0 Microsoft.PowerShell.Management Cmdlet Suspend-Service 3.1.0.0 Microsoft.PowerShell.Management PS C:\Windows\System32\WindowsPowerShell\v1.0> get-service spooler Status Name DisplayName ------ ---- ----------- Running spooler Druckwarteschlange PS C:\Windows\System32\WindowsPowerShell\v1.0> cu Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now