Jump to content

Imbed MMC/.MSC


IcemanND
 Share

Recommended Posts

I am trying to imbed an MMC console into a GUI but so far none of my attempts to use GUICtrlCreateObj with an object created from MMC20.Application. It will create the object but it will not show within the GUI, either it shows nothing in the GUI, or it opens the Disk Management Console in its own window.

Any help appreciated.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $objMMC = ObjCreate("MMC20.Application")
$objMMC.load("DiskMgmt.msc")

$parent = GUICreate("Embedded Web control Test", 800, 600, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))

GUICtrlCreateButton ("Single Partition", 16, 5, 150, 32)
GUICtrlCreateButton ("Double Partition", 200, 5, 150, 32)

$GUIActiveX = GUICtrlCreateObj($objMMC, 5, 50, 740, 590)
GUISetState()       ;Show GUI


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

GUIDelete()

Exit
Edited by IcemanND
Link to comment
Share on other sites

An .MSC file is just an XML file. You can open it in Scite (or whatever) and take a look. So just loading it into your GUI (especially the provided code) isn't going to give you the proper results. You currently have it try to "run" DiskMgmt.msc, which Windows knows how because .MSC files are associated with MMC.EXE. This is why it opens in a new window since Windows can't launch an .MSC by itself.

Most of this MSC looks to be an icon. Looking at it a little bit, I am going to wager a guess that all those GUIDs match up to the registry and WMI, but don't take my word on it.

MMC 3.0 Namespace List

Look at this one project that Psalty tried:

Link to comment
Share on other sites

Psalty was attempting to read the info and display the info or build his own GUI. I'm after displaying the existing console just within my own GUI. Not interested in trying to read the info out. If I wanted to go that route and create my own I'd use this:

But why do all the work if I can re-use Microsoft's own tools. I can live with the window popping up but the GUI would look cleaner if I could load it in its own element.

As you see in the example I provided I was trying with MMC 2.0, I have not seen an entry point into MMC 3.0 that I can get to work, so that may be more successful if I can find that and build it from 3.0 instead.

Link to comment
Share on other sites

Hi,

I don't think this is what your after, but here goes.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $sTitle = "[TITLE:Disk Management; CLASS:MMCMainFrame]"
Global $sPathMSC = @SystemDir & "\diskmgmt.msc"
Global $sNewMSC = @ScriptDir & "\hidden_diskmgmt.msc"
Global $hFO, $sRead, $hMSC, $parent

; Read diskmgmt.msc into a variable.
$hFO = FileOpen($sPathMSC)
$sRead = FileRead($hFO)
FileClose($hFO)

; Change "SW_SHOWNORMAL" to "SW_HIDE" in the read variable.
$sRead = StringReplace($sRead, "SW_SHOWNORMAL", "SW_HIDE")

; Write the read varibale to a new file (as I don't think it's appropriate to edit the original file).
$hFO = FileOpen($sNewMSC, 2)
FileWrite($hFO, $sRead)
FileClose($hFO)
$sRead = 0

; Shell execute mmc with the new msc file path as parameter.
ShellExecute("mmc.exe", $sNewMSC)

; Once the window exists get a handle to it, if not then bail out.
$hMSC = WinWait($sTitle, "", 5)
If Not $hMSC Then
    FileDelete($sNewMSC)
    Exit
EndIf


$parent = GUICreate("diskmgmt.msc in AutoIt Gui", 800, 600)

; Set the MSC window style to be a child window
_WinAPI_SetWindowLong($hMSC, -16, $WS_CHILD) ; $GWL_STYLE = -16

; Set Autoit Gui to be the parent of the MSC window.
_WinAPI_SetParent($hMSC, $parent)

; Set the MSC window to be shown.
WinSetState($hMSC, "", @SW_SHOW)

;Show AutoIt Gui
GUISetState(@SW_SHOW, $parent)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ; Close the MSC window and delete the edited MSC file when exiting AutIt Gui.
            WinClose($hMSC)
            FileDelete($sNewMSC)
            Exit
    EndSwitch
WEnd

Tried it in Win XP x86

Edited by smashly
Link to comment
Share on other sites

Actually, that is very close to what I am wanting. As I said I'm not after scripting it just showing it and allowing the user to interact with it if needed. Now I just have to work out how to place it and re-size it to fit into my GUI and show or hide it when the Tab it would live on is selected/deselected.

Link to comment
Share on other sites

This is going into a much longer script but here is the test I have currently come up with that works. If there is a better solution let me know.

NOTE: Since this script is meant to run from WinPE 3.0 I will leave a modified copy of the MSC file in the boot.wim, this is why I removed the FileDelete lines to remove the modified MSC.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#Include <GuiStatusBar.au3>

Global $sTitle = "[TITLE:Disk Management; CLASS:MMCMainFrame]"
Global $sPathMSC = @SystemDir & "\diskmgmt.msc"
Global $sNewMSC = @ScriptDir & "\hidden_diskmgmt.msc"
Global $hFO, $sRead, $hMSC, $parent

; Read diskmgmt.msc into a variable.
If Not FileExists ($sNewMSC) Then 
    $hFO = FileOpen($sPathMSC)
    $sRead = FileRead($hFO)
    FileClose($hFO)

    ; Change "SW_SHOWNORMAL" to "SW_HIDE" in the read variable.
    $sRead = StringReplace($sRead, "SW_SHOWNORMAL", "SW_HIDE")

    ; Write the read varibale to a new file (as I don't think it's appropriate to edit the original file).
    $hFO = FileOpen($sNewMSC, 2)
    FileWrite($hFO, $sRead)
    FileClose($hFO)
    $sRead = 0
EndIf
; Shell execute mmc with the new msc file path as parameter.
ShellExecute("mmc.exe", $sNewMSC)
; Once the window exists get a handle to it, if not then bail out.
$hMSC = WinWait($sTitle, "", 5)
If Not $hMSC Then
    Exit
EndIf


$parent = GUICreate("diskmgmt.msc in AutoIt Gui", 801, 602, -1, -1)
GUICtrlCreateMenu("&File")
$tab = GUICtrlCreateTab(0, 0, 800, 561)
$StatusBar = _GUICtrlStatusBar_Create($parent)
Dim $StatusBar_PartsWidth[4] = [90, 230, 310, -1]
_GUICtrlStatusBar_SetParts($StatusBar, $StatusBar_PartsWidth)
_GUICtrlStatusBar_SetText($StatusBar, "MAC Address:", 0)
_GUICtrlStatusBar_SetText($StatusBar, "00:11:22:33:44:55", 1)
_GUICtrlStatusBar_SetText($StatusBar, "IP Address:", 2)
_GUICtrlStatusBar_SetText($StatusBar, @IPAddress1, 3)
GUICtrlCreateTabItem("Main")
GUICtrlCreateTabItem("Partitioning")
GUICtrlCreateButton ("Single Partition", 16, 35, 150, 32)
GUICtrlCreateButton ("Double Partition", 200, 35, 150, 32)
GUICtrlCreateTabItem("")


; Set the MSC window style to be a child window
_WinAPI_SetWindowLong($hMSC, $GWL_STYLE, $WS_CHILD) ; $GWL_STYLE = -16

; Set Autoit Gui to be the parent of the MSC window.
_WinAPI_SetParent($hMSC, $parent)
_WinAPI_SetWindowPos($hMSC, $HWND_TOP, 2, 75, 795, 460, $SWP_DRAWFRAME)
; Set the MSC window to be shown.
;WinSetState($hMSC, "", @SW_SHOW)

;Show AutoIt Gui
GUISetState(@SW_SHOW, $parent)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ; Close the MSC window and delete the edited MSC file when exiting AutIt Gui.
            WinClose($hMSC)
            Exit
        Case $tab
            Switch GUICtrlRead ($tab)
                Case 0
                    WinSetState($hMSC, "", @SW_HIDE)
                Case 1
                    WinSetState($hMSC, "", @SW_SHOW)
            EndSwitch
    EndSwitch
WEnd
Edited by IcemanND
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...