Jump to content

Interact with mmc consoles


Recommended Posts

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 - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

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 by TheXman
Link to comment
Share on other sites

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 by TheXman
Added #RequireAdmin for Windows 10
Link to comment
Share on other sites

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!

; 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

 

 

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

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

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...