Sign in to follow this  
Followers 0
RogFleming

how to make contextmenu work with GuiTreeView UDF

7 posts in this topic

Need help to create a Context menu to a Dynamically Created object with GuiTreeView UDF

my code so far

#include <Misc.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiTreeView.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <AD.au3>
#include <array.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>


;Global $vLvl1, $vLvl2, $vLvl3, $vLvl4, $SelectedValue

$mainform = GUICreate("Organizational Tree", 600, 900)
$tviewPI = _GuiCtrlTreeView_Create($mainform,10, 10, 580, 880, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_Checkboxes), $WS_EX_CLIENTEDGE)
$MainOU = _GUICtrlTreeView_Add($tviewPI,0,"Workstation Organizational Units")

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

;_AD_Open()
;$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
;_ArrayDisplay($aOUs)
;_AD_Close()

;Test OU GRoup
$TestParentOU=_GUICtrlTreeView_AddChild($tviewPI, $tviewPI,"Test OU Group")
;$tstou = _ArrayFindAll($aOUs,"OU=Test Workstation",0,0,0,1,1)
;For $i = 1 To UBound($tstou,1) - 1
$TestChildOU1=_GUICtrlTreeView_AddChild($tviewPI,$TestParentOU,"Level 1 OU")
$TestObj1=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj1")
$TestObj2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj2")
$TestChildOU2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 2 OU")
$TestObj3=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj1")
$TestObj4=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj2")
;Next

GUICtrlSetColor(-1, 0x0000C0)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
     EndSelect
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView, $tInfo
    $hWndTreeView = $tviewPI
    If Not IsHWnd($tviewPI) Then $hWndTreeView = GUICtrlGetHandle($tviewPI)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeView
            Switch $iCode
                Case $NM_RCLICK

                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $TVtext = _GUICtrlTreeView_GetText($tviewPI,$TVhItem)
                ToolTip("HnWd"&" : "&$TVhItem&" "&"Text found on the handle"&" : "&$TVtext,0.0)

                $tviewPICon = GUICtrlCreateContextMenu($TVhItem)
                $tviewPIConGetWks = GUICtrlCreateMenuItem("Get workstations", $tviewPICon)
                $tviewPIConCheckReg = GUICtrlCreateMenuItem("Check Registry", $tviewPICon)
                $tviewPIConCheckfiles = GUICtrlCreateMenuItem("Check for Files", $tviewPICon)
                $tviewPIConGetProcessList = GUICtrlCreateMenuItem("Process List", $tviewPICon)
                $tviewPIConGetUserProfiles = GUICtrlCreateMenuItem("Get User Profiles Names", $tviewPICon)
            EndSwitch
        EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func GetWorkstations($getObject)
    Global $workstationnames = _AD_GetObjectsInOU($getObject, "(&(objectcategory=computer)(objectclass=computer))", 2, "name")
    _ArrayDisplay($workstationnames)
EndFunc

Share this post


Link to post
Share on other sites



I figured out the issue, it has to do with have a Contextmenu in a Treeview frame. Context menu works if I outside the treeview window. Any ideas how I can get around this issue would be helpful.

Share this post


Link to post
Share on other sites

What do you mean by "Context menu works if I outside the treeview window"? Does that mean the mouse is outside the TreeView and you activate the menu by keyboard, or ...?

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

What do you mean by "Context menu works if I outside the treeview window"? Does that mean the mouse is outside the TreeView and you activate the menu by keyboard, or ...?

;)

It mean once the mouse is outside the Treeview window and in the main window area the right click context menu works.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well, in your reproducer the only context menu outside the TreeView is the default Windows context (Move/Size/Close/etc).

There is a working example by GaryFrost but it's a little dated and needs minor tweaking to work with the current version and the current GuiTreeView.au3 UDF:

#include <GuiConstants.au3> ; Inclusion file for the GUI interface controls
#include <GuiTreeView.au3>

Global $TreeView
Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 1

;Events
Global Const $NM_FIRST = 0
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
Global Const $NM_RCLICK = ($NM_FIRST - 5)

#endregion

Opt("WinTitleMatchMode", 2)

$main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10)

$TreeView = GUICtrlCreateTreeView(10, 10, 150, 150)
$nItem2 = GUICtrlCreateTreeViewItem("Item2", $TreeView)
$nItem1 = GUICtrlCreateTreeViewItem("Item1", $TreeView)
$nItem3 = GUICtrlCreateTreeViewItem("Item3", $TreeView)
$nSubItem2 = GUICtrlCreateTreeViewItem("SubItem2", $nItem1)
$nSubItem1 = GUICtrlCreateTreeViewItem("SubItem1", $nItem1)
$nSubItem4 = GUICtrlCreateTreeViewItem("SubItem4", $nSubItem1)
$nSubItem5 = GUICtrlCreateTreeViewItem("SubItem5", $nSubItem4)
$nSubItem6 = GUICtrlCreateTreeViewItem("SubItem6", $nSubItem5)
$nSubItem3 = GUICtrlCreateTreeViewItem("SubItem3", $nSubItem1)
$nSubItem7 = GUICtrlCreateTreeViewItem("SubItem7", $nItem3)

$Menu = GUICtrlCreateContextMenu($TreeView)
$contexCut = GUICtrlCreateMenuItem("Cut", $Menu)
$contexCopy = GUICtrlCreateMenuItem("Copy", $Menu)
$contexPaste = GUICtrlCreateMenuItem("Paste", $Menu)

GUISetState()

;Register WM_NOTIFY  events
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1

    $msg = GUIGetMsg()
;~   ConsoleWrite($msg[3] & @TAB & $msg[4] & @LF)
    Switch $msg

        ;-----------------------------------------------------------------------------------------
        ;This case statement exits and updates code if needed
        Case $GUI_EVENT_CLOSE
            Exit


            ;-----------------------------------------------------------------------------------------
            ;put all the misc. stuff here
        Case Else
            ;;;
    EndSwitch
WEnd

Func TreeView_Click()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("TreeView_Click")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>TreeView_Click

Func TreeView_DoubleClick()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("TreeView_DoubleClick")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>TreeView_DoubleClick

Func TreeView_RightClick($s_text)
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("Item selected: " & $s_text)
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>TreeView_RightClick

;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
        Case $wParam = $TreeView
            Select
                Case $event = $NM_CLICK
                    TreeView_Click()
                Case $event = $NM_DBLCLK
                    TreeView_DoubleClick()
                Case $event = $NM_RCLICK
                    Local Const $TVHT_NOWHERE = 1
                    Local Const $TVHT_ONITEMICON = 2
                    Local Const $TVHT_ONITEMLABEL = 4
                    Local Const $TVHT_ONITEMINDENT = 8
                    Local Const $TVHT_ONITEMBUTTON = 16
                    Local Const $TVHT_ONITEMRIGHT = 32
                    Local Const $TVHT_ONITEMSTATEICON = 64
                    Local Const $TVHT_ABOVE = 256
                    Local Const $TVHT_BELOW = 512
                    Local Const $TVHT_TORIGHT = 1024
                    Local Const $TVHT_TOLEFT = 2048
                    Local Const $TEST = BitOR($TVHT_ONITEMICON, $TVHT_ONITEMLABEL, $TVHT_ONITEMSTATEICON, $TVHT_ONITEMINDENT, $TVHT_ONITEMBUTTON, $TVHT_ONITEMRIGHT)
                    $opt_bak = Opt("MouseCoordMode", 2)
                    $mpos = MouseGetPos()
                    Opt("MouseCoordMode", $opt_bak)
                    $tpos = ControlGetPos("", "", $TreeView)
                    If Not @error Then
                        $x = $mpos[0] - $tpos[0] ;left offset
                        $y = $mpos[1] - $tpos[1] ;$top offset
                        $hitinfo = DllStructCreate("int;int;uint;uint") ;not sure if uint or ptr should go here...will look it up..32 bits is 32 bits
                        If Not @error Then
                            DllStructSetData($hitinfo, 1, $x)
                            DllStructSetData($hitinfo, 2, $y)
                            DllStructSetData($hitinfo, 3, 0)
                            DllStructSetData($hitinfo, 4, 0)
                            GUICtrlSendMsg($TreeView, $TVM_HITTEST, 0, DllStructGetPtr($hitinfo))
                            $hit = DllStructGetData($hitinfo, 3) ;flags returned
                            $i = DllStructGetData($hitinfo, 4) ;handle
                            $hitinfo = 0 ;DllStructDelete($hitinfo) ; seems no DllStructDelete in beta version 1.99
                            If BitAND($hit, $TVHT_ONITEMRIGHT) Then Return 0
                            If BitAND($hit, $TEST) = 0 Then Return 0
                            TreeView_RightClick(_GUICtrlTreeView_GetText($TreeView, $i))
                        EndIf
                    EndIf
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
EndFunc   ;==>WM_Notify_Events

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint

Note most especially that context menus are created once and left to the Windows API to get called up. They are not created on the fly when the control gets right-clicked (as in your WM_NOTIFY function).

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I used this as a basis but the problem was the mixing of theGUICtrlCreateTreeView

Commands and (_GUICtrlTreeView_GetText Hit test. I have been told if your going to

start using the UDF then you need to keep using the UDF. The problem, has been I

can read the Treeview item with the hit test, but I cannot get the WM_COMMAND and

WM_CONTEXTMENU to activate properly inside the TREEVIEW area of the main GUI.

Current Version

DblClick pulls a list of workstations from a OU

RightClick creates a WEB Interface and dumps a lot of WMI information.

I was never able to get a CONTEXTMENU to work correct when using TreeView UDF

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

;Cannot use $WM_CONTEXTMENU it is overrided by $WM_NOTIFY


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView, $tInfo
    $hWndTreeView = $tviewPI
    If Not IsHWnd($tviewPI) Then $hWndTreeView = GUICtrlGetHandle($tviewPI)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeView
            Switch $iCode

            Case $NM_RCLICK
                    WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)

            Case $NM_ClICK
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $TVtext = _GUICtrlTreeView_GetText($tviewPI,$TVhItem)
                ;Global $SelectedTV = $TVtext
                ;ToolTip("HnWd"&" : "&$TVhItem&" "&"Text found"&" : "&$TVtext,0.0)
            Case $NM_DBLCLK
                Local $TVhItem
                _GUICtrlTreeView_DeleteChildren($tviewPI,$TVhItem)
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $TVtext = _GUICtrlTreeView_GetText($tviewPI,$TVhItem)

                 If _GUICtrlTreeView_GetChildCount($tviewPI,$TVhItem) =-1 Then
                    $tstoumembers = _AD_GetObjectsInOU($TVtext, "(&(objectcategory=computer)(objectclass=computer))", 2, "name"); searches the OU PCs
                    For $i = 1 To UBound($tstoumembers,1) - 1
                    _GUICtrlTreeView_AddChild($tviewPI,$TVhItem,$tstoumembers[$i])
                    Next
                EndIf
            EndSwitch
        EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
                Local $TVhItem
                _GUICtrlTreeView_DeleteChildren($tviewPI,$TVhItem)
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $sComputerName = _GUICtrlTreeView_GetText($tviewPI,$TVhItem)

                _AD_Open()
                $sFQDN = _AD_SamAccountNameToFQDN($sComputerName & "$")
                $wks = _AD_GetObjectProperties($sFQDN,"")
                ;_ArrayDisplay($wks)
                _AD_Close()


                _IEErrorHandlerRegister ()
                $oIE = _IECreate()
                ;$GUIActiveX = GUICtrlCreateObj($oIE, (@DesktopWidth/2)-194,3,(@DesktopWidth/2)+183,600)

                $sHTML = ""
                $sHTML &= "<HTML>" & @CR
                $sHTML &= "<HEAD>" & @CR
                $sHTML &= "<TITLE>Active Diectory Workstation Properties</TITLE>" & @CR
                $sHTML &= "</HEAD>" & @CR
                $sHTML &= "<FRAMESET rows='25,200'>" & @CR
                $sHTML &= " <FRAME NAME=Top SRC=about:blank>" & @CR
                $sHTML &= " <FRAMESET cols='100,500'>" & @CR
                $sHTML &= "   <FRAME NAME=Menu SRC=about:blank>" & @CR
                $sHTML &= "   <FRAME NAME=Main SRC=about:blank>" & @CR
                $sHTML &= " </FRAMESET>" & @CR
                $sHTML &= "</FRAMESET>" & @CR
                $sHTML &= "</HTML>"
                _IEDocWriteHTML ($oIE, $sHTML)
                _IEAction ($oIE, "refresh")
                Local $oFrameTop = _IEFrameGetObjByName ($oIE, "Top")
                Local $oFrameMenu = _IEFrameGetObjByName ($oIE, "Menu")
                Local $oFrameMain = _IEFrameGetObjByName ($oIE, "Main")
                _IEBodyWriteHTML ($oFrameTop, '<b>Workstation Properties for'&' '&$sComputerName&'<b/>')
                _IEBodyWriteHTML ($oFrameMenu, '<b>'&$sComputerName&'</b>')

                $dHTMLTitle = ""
                $dHTML= ""
                $dHTMLTitle &= '<tr bgcolor="yellow"><td>' & "Computer</td><td>&nbsp;" & $sComputerName  & "</td></tr>" & @CRLF
                $dHTML = $dHTML & @CR
                $dHTML = $dHTML & '<html><head></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> AD Attribute </th><th> Value </th></tr>'
                For $db = 1 to UBound($wks,1) -1
                $dHTML &= "<tr><td>"&$wks[$db][0]&"</td><td>&nbsp;"&$wks[$db][1]&"</td></tr>" & @CRLF
                Next
                TCPNameToIP($sComputerName)
                If @error Then
                $dHTML &= "<tr><td>"&$sComputerName&"</td><td>&nbsp;"&"Is not responding to DNS Lookup."&"</td></tr>" & @CRLF

                _IEDocWriteHTML ($oFrameMain, $dHTML)
                _IEAction ($oFrameMain, "refresh")
                Else
                $dHTML = $dHTML & '<html><style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Process List </th><th> Value </th></tr>'

                $wbemFlagReturnImmediately = 0x10
                $wbemFlagForwardOnly = 0x20
                $colItems = ""

                $objWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2")
                $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
                                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

                If IsObj($colItems) then
                   Local $Object_Flag = 0
                   For $objItem In $colItems
                      $Object_Flag = 1
                  $dHTML = $dHTML & '<head>'&" "&'</head>' &@CRLF
                  $dHTML = $dHTML & '<head>'&" "&'</head>' &@CRLF

                  ;$dHTML = $dHTML & '<html><style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Process List </th><th> Process ID </th></tr>'
                  $dHTML &= "<tr><td>"& $objItem.Caption &"</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF
                  #cs
                  $dHTML &= "<tr><td>CommandLine</td><td>&nbsp;" & $objItem.CommandLine & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>CreationClassName</td><td>&nbsp;" & $objItem.CreationClassName & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>CreationDate</td><td>&nbsp;" & WMIDateStringToDate($objItem.CreationDate) & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>CSCreationClassName</td><td>&nbsp;" & $objItem.CSCreationClassName & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>CSName</td><td>&nbsp;" & $objItem.CSName & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>Description</td><td>&nbsp;" & $objItem.Description & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ExecutablePath</td><td>&nbsp;" & $objItem.ExecutablePath & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ExecutionState</td><td>&nbsp;" & $objItem.ExecutionState & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>Handle</td><td>&nbsp;" & $objItem.Handle & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>HandleCount</td><td>&nbsp;" & $objItem.HandleCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>InstallDate</td><td>&nbsp;" & WMIDateStringToDate($objItem.InstallDate) & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>KernelModeTime</td><td>&nbsp;" & $objItem.KernelModeTime & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>MaximumWorkingSetSize</td><td>&nbsp;" & $objItem.MaximumWorkingSetSize & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>MinimumWorkingSetSize</td><td>&nbsp;" & $objItem.MinimumWorkingSetSize & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>OSCreationClassName</td><td>&nbsp;" & $objItem.OSCreationClassName & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>OSName</td><td>&nbsp;" & $objItem.OSName & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>OtherOperationCount</td><td>&nbsp;" & $objItem.OtherOperationCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>OtherTransferCount</td><td>&nbsp;" & $objItem.OtherTransferCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>PageFaults</td><td>&nbsp;" & $objItem.PageFaults & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>PageFileUsage</td><td>&nbsp;" & $objItem.PageFileUsage & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ParentProcessId</td><td>&nbsp;" & $objItem.ParentProcessId & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>PeakPageFileUsage</td><td>&nbsp;" & $objItem.PeakPageFileUsage & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>PeakVirtualSize</td><td>&nbsp;" & $objItem.PeakVirtualSize & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>PeakWorkingSetSize</td><td>&nbsp;" & $objItem.PeakWorkingSetSize & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>Priority</td><td>&nbsp;" & $objItem.Priority & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>PrivatePageCount</td><td>&nbsp;" & $objItem.PrivatePageCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ProcessId</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>QuotaNonPagedPoolUsage</td><td>&nbsp;" & $objItem.QuotaNonPagedPoolUsage & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>QuotaPagedPoolUsage</td><td>&nbsp;" & $objItem.QuotaPagedPoolUsage & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>QuotaPeakNonPagedPoolUsage</td><td>&nbsp;" & $objItem.QuotaPeakNonPagedPoolUsage & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>QuotaPeakPagedPoolUsage</td><td>&nbsp;" & $objItem.QuotaPeakPagedPoolUsage & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ReadOperationCount</td><td>&nbsp;" & $objItem.ReadOperationCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ReadTransferCount</td><td>&nbsp;" & $objItem.ReadTransferCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>SessionId</td><td>&nbsp;" & $objItem.SessionId & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>Status</td><td>&nbsp;" & $objItem.Status & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>TerminationDate</td><td>&nbsp;" & WMIDateStringToDate($objItem.TerminationDate) & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>ThreadCount</td><td>&nbsp;" & $objItem.ThreadCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>UserModeTime</td><td>&nbsp;" & $objItem.UserModeTime & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>VirtualSize</td><td>&nbsp;" & $objItem.VirtualSize & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>WindowsVersion</td><td>&nbsp;" & $objItem.WindowsVersion & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>WorkingSetSize</td><td>&nbsp;" & $objItem.WorkingSetSize & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>WriteOperationCount</td><td>&nbsp;" & $objItem.WriteOperationCount & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>WriteTransferCount</td><td>&nbsp;" & $objItem.WriteTransferCount & "</td></tr>" & @CRLF
                  #ce
              Next
                  $dHTML = $dHTML & '<html><style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Registered Services </th><th> Running State </th></tr>'

                          $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", _
                                                      $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

            If IsObj($colItems) then
               Local $Object_Flag = 0
               For $objItem In $colItems
                  $Object_Flag = 1
                  $dHTML = $dHTML & '<head>'&" "&'</head>' &@CRLF
                  $dHTML = $dHTML & '<head>'&" "&'</head>' &@CRLF
                  ;$dHTML = $dHTML & '<html><head></head><body> <style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Service Attribute </th><th> Value </th></tr>'
                  ;$dHTML &= "<tr><td>AcceptPause</td><td>&nbsp;" & $objItem.AcceptPause & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>AcceptStop</td><td>&nbsp;" & $objItem.AcceptStop & "</td></tr>" & @CRLF
                  $dHTML &= "<tr><td>"&$objItem.Caption&"</td><td>&nbsp;" & $objItem.State & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>CheckPoint</td><td>&nbsp;" & $objItem.CheckPoint & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>CreationClassName</td><td>&nbsp;" & $objItem.CreationClassName & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>Description</td><td>&nbsp;" & $objItem.Description & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>DesktopInteract</td><td>&nbsp;" & $objItem.DesktopInteract & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>DisplayName</td><td>&nbsp;" & $objItem.DisplayName & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>ErrorControl</td><td>&nbsp;" & $objItem.ErrorControl & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>ExitCode</td><td>&nbsp;" & $objItem.ExitCode & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>InstallDate</td><td>&nbsp;" & WMIDateStringToDate($objItem.InstallDate) & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>PathName</td><td>&nbsp;" & $objItem.PathName & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>ProcessId</td><td>&nbsp;" & $objItem.ProcessId & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>ServiceSpecificExitCode</td><td>&nbsp;" & $objItem.ServiceSpecificExitCode & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>ServiceType</td><td>&nbsp;" & $objItem.ServiceType & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>Started</td><td>&nbsp;" & $objItem.Started & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>StartMode</td><td>&nbsp;" & $objItem.StartMode & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>StartName</td><td>&nbsp;" & $objItem.StartName & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>State</td><td>&nbsp;" & $objItem.State & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>Status</td><td>&nbsp;" & $objItem.Status & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>SystemCreationClassName</td><td>&nbsp;" & $objItem.SystemCreationClassName & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>SystemName</td><td>&nbsp;" & $objItem.SystemName & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>TagId</td><td>&nbsp;" & $objItem.TagId & "</td></tr>" & @CRLF
                  ;$dHTML &= "<tr><td>WaitHint</td><td>&nbsp;" & $objItem.WaitHint & "</td></tr>" & @CRLF
               Next

              EndIf
                    $dHTML = $dHTML & '<html><style>table {font-size: 10pt; font-family: arial;} th {background-color: buttonface; font-decoration: bold;} </style><table BORDER="1"><tr><th> Computer Properties </th><th> Value </th></tr>'
                    $dHTMLTitle &= '<tr bgcolor="yellow"><td>' & "Computer</td><td>&nbsp;" & $sComputerName  & "</td></tr>" & @CRLF
                    ;$objWMIService = ObjGet("winmgmts:\\" & $sComputerName & "\root\CIMV2")
                    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", _
                                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

                    If IsObj($colItems) then
                       Local $Object_Flag = 0
                       For $objItem In $colItems
                          $Object_Flag = 1
                          $dHTML &= "<tr><td>BootDevice</td><td>&nbsp;" & $objItem.BootDevice & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>BuildNumber</td><td>&nbsp;" & $objItem.BuildNumber & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>BuildType</td><td>&nbsp;" & $objItem.BuildType & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Caption</td><td>&nbsp;" & $objItem.Caption & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CodeSet</td><td>&nbsp;" & $objItem.CodeSet & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CountryCode</td><td>&nbsp;" & $objItem.CountryCode & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CreationClassName</td><td>&nbsp;" & $objItem.CreationClassName & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CSCreationClassName</td><td>&nbsp;" & $objItem.CSCreationClassName & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CSDVersion</td><td>&nbsp;" & $objItem.CSDVersion & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CSName</td><td>&nbsp;" & $objItem.CSName & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>CurrentTimeZone</td><td>&nbsp;" & $objItem.CurrentTimeZone & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>DataExecutionPrevention_32BitApplications</td><td>&nbsp;" & $objItem.DataExecutionPrevention_32BitApplications & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>DataExecutionPrevention_Available</td><td>&nbsp;" & $objItem.DataExecutionPrevention_Available & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>DataExecutionPrevention_Drivers</td><td>&nbsp;" & $objItem.DataExecutionPrevention_Drivers & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>DataExecutionPrevention_SupportPolicy</td><td>&nbsp;" & $objItem.DataExecutionPrevention_SupportPolicy & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Debug</td><td>&nbsp;" & $objItem.Debug & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Description</td><td>&nbsp;" & $objItem.Description & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Distributed</td><td>&nbsp;" & $objItem.Distributed & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>EncryptionLevel</td><td>&nbsp;" & $objItem.EncryptionLevel & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>ForegroundApplicationBoost</td><td>&nbsp;" & $objItem.ForegroundApplicationBoost & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>FreePhysicalMemory</td><td>&nbsp;" & $objItem.FreePhysicalMemory & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>FreeSpaceInPagingFiles</td><td>&nbsp;" & $objItem.FreeSpaceInPagingFiles & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>FreeVirtualMemory</td><td>&nbsp;" & $objItem.FreeVirtualMemory & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>InstallDate</td><td>&nbsp;" & WMIDateStringToDate($objItem.InstallDate) & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>LargeSystemCache</td><td>&nbsp;" & $objItem.LargeSystemCache & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>LastBootUpTime</td><td>&nbsp;" & WMIDateStringToDate($objItem.LastBootUpTime) & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>LocalDateTime</td><td>&nbsp;" & WMIDateStringToDate($objItem.LocalDateTime) & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Locale</td><td>&nbsp;" & $objItem.Locale & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Manufacturer</td><td>&nbsp;" & $objItem.Manufacturer & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>MaxNumberOfProcesses</td><td>&nbsp;" & $objItem.MaxNumberOfProcesses & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>MaxProcessMemorySize</td><td>&nbsp;" & $objItem.MaxProcessMemorySize & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Name</td><td>&nbsp;" & $objItem.Name & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>NumberOfLicensedUsers</td><td>&nbsp;" & $objItem.NumberOfLicensedUsers & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>NumberOfProcesses</td><td>&nbsp;" & $objItem.NumberOfProcesses & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>NumberOfUsers</td><td>&nbsp;" & $objItem.NumberOfUsers & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Organization</td><td>&nbsp;" & $objItem.Organization & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>OSLanguage</td><td>&nbsp;" & $objItem.OSLanguage & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>OSProductSuite</td><td>&nbsp;" & $objItem.OSProductSuite & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>OSType</td><td>&nbsp;" & $objItem.OSType & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>OtherTypeDescription</td><td>&nbsp;" & $objItem.OtherTypeDescription & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>PlusProductID</td><td>&nbsp;" & $objItem.PlusProductID & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>PlusVersionNumber</td><td>&nbsp;" & $objItem.PlusVersionNumber & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Primary</td><td>&nbsp;" & $objItem.Primary & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>ProductType</td><td>&nbsp;" & $objItem.ProductType & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>QuantumLength</td><td>&nbsp;" & $objItem.QuantumLength & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>QuantumType</td><td>&nbsp;" & $objItem.QuantumType & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>RegisteredUser</td><td>&nbsp;" & $objItem.RegisteredUser & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>SerialNumber</td><td>&nbsp;" & $objItem.SerialNumber & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>ServicePackMajorVersion</td><td>&nbsp;" & $objItem.ServicePackMajorVersion & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>ServicePackMinorVersion</td><td>&nbsp;" & $objItem.ServicePackMinorVersion & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>SizeStoredInPagingFiles</td><td>&nbsp;" & $objItem.SizeStoredInPagingFiles & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Status</td><td>&nbsp;" & $objItem.Status & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>SuiteMask</td><td>&nbsp;" & $objItem.SuiteMask & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>SystemDevice</td><td>&nbsp;" & $objItem.SystemDevice & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>SystemDirectory</td><td>&nbsp;" & $objItem.SystemDirectory & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>SystemDrive</td><td>&nbsp;" & $objItem.SystemDrive & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>TotalSwapSpaceSize</td><td>&nbsp;" & $objItem.TotalSwapSpaceSize & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>TotalVirtualMemorySize</td><td>&nbsp;" & $objItem.TotalVirtualMemorySize & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>TotalVisibleMemorySize</td><td>&nbsp;" & $objItem.TotalVisibleMemorySize & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>Version</td><td>&nbsp;" & $objItem.Version & "</td></tr>" & @CRLF
                          $dHTML &= "<tr><td>WindowsDirectory</td><td>&nbsp;" & $objItem.WindowsDirectory & "</td></tr>" & @CRLF
                      Next
                  EndIf
                        EndIf
                            _IEDocWriteHTML ($oFrameMain, $dHTML)
                            _IEAction ($oFrameMain, "refresh")
                        EndIf


EndFunc

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch _WinAPI_LoWord ($iwParam)

        Case $idMcShield
            ;MsgBox(4096,"","Starting McShield Scan.",2)
            GetActiveProc($TVtext,"DTEScanProc.exe","McShield.exe")
            ;Exit

        Case $idWorkstations
            ;MsgBox(4096,"","Starting Workstation Scan.",2)
            GetActiveWorkstations($TVtext,"WorkstationScanner.exe","WorkstationScanner.log")
            ;Exit

        Case $idMcVTPS
            GetActiveMcVTPS()

        Case $idExit
            ProcessClose("ScanMonitor1.exe")
            ProcessClose("ScanMonitor2.exe")
            ProcessClose("ScanMonitor3.exe")
            ProcessClose("ScanMonitor4.exe")
            Exit

        Case $adWorkstations
            MsgBox(4096,"Process Warning","It will take a few minutes to load all the workstation objects. "&$iwParam)
            GetActiveWorkstationsAD("WorkstationScanner.exe","WorkstationScanner.log")
        Case $adMcShield
            MsgBox(4096,"Process Warning","It will take a few minutes to load all the workstation objects. "&$iwParam)
            GetActiveMcShieldfromAD()

        Case $adMcVTPS
            MsgBox(4096,"Process Warning","It will take a few minutes to load all the workstation objects. "&$iwParam)
            GetActiveMcVTPSFromAD()

        Case $idAbout
            MsgBox(4096,"","OU Admin Workstation 1.5.",2)

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

follow the link to my example

Edited by RogFleming

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
Sign in to follow this  
Followers 0