Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 904
Благодарности: 162

Профиль | Отправить PM | Цитировать


Creat0R, изменил скрипт в шапке в соответствии с Вашим советом, но вкладка DriverErrors по прежнему не работает .
Вот, что у меня получилось:
читать дальше »
Код: Выделить весь код
#include <Constants.au3>
#include <EditConstants.au3>
#include <Encoding.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <DeviceAPI.au3>

; ErrorLogs
Global $hMain_GUI, $nErrorRenew_Button, $hInput, $hInputAll, $ListViewEv, $hListViewEv, $aErrorsNew

; DriversErrors
Global $aAssoc[1][2]
;Global $hTreeView

Opt("GUIOnEventMode", 1)

$hMain_GUI = GUICreate("Диагностика и Настройка XP SP3", 619, 442, 189, 122)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$Tab1 = GUICtrlCreateTab(8, 16, 601, 377)
;;;; EventErrors ;;;;
Dim $aToList = __ErrorLog()
$EventErrors = GUICtrlCreateTabItem("EventErrors")
$nErrorRenew_Button = GUICtrlCreateButton("Обновить", 440, 400, 85, 33)
GUICtrlSetOnEvent($nErrorRenew_Button, "ErrorRenew_Button")

GUICtrlCreateGroup("Расшифровка кода ошибки", 16, 65, 585, 63)
$hInput = GUICtrlCreateEdit('', 24, 80, 570, 39, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))
$ListViewEv = GUICtrlCreateListView('Список Errors логов системы', 16, 133, 585, 169, -1, $LVS_EX_GRIDLINES)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlCreateGroup("Полное описание выделенной ошибки", 16, 305, 585, 82)
$hInputAll = GUICtrlCreateEdit('', 24, 320, 570, 59, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL))

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY_Ev')

$hListViewEv = GUICtrlGetHandle($ListViewEv)
_GUICtrlListView_SetColumnWidth($hListViewEv, 0, 2000)
If $aToList <> 0 Then
    _GUICtrlListView_AddColumn($hListViewEv, '')
    For $i = 1 To UBound($aToList) - 1
        _GUICtrlListView_AddItem($hListViewEv, $aToList[$i])
    Next
    _GUICtrlListView_SetItemSelected($hListViewEv, 0)
EndIf


;;; DriversErrors ;;;
$DriverErrors = GUICtrlCreateTabItem("DriversErrors")
Dim $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
$hTreeView = GUICtrlCreateTreeView(14, 45, 253, 337, $iStyle, $WS_EX_STATICEDGE)
GUICtrlSetState(-1, $GUI_FOCUS)
$hListView = GUICtrlCreateListView("Key|Value", 272, 45, 332, 337)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_Ev")

;Assign image list to treeview
_GUICtrlTreeView_SetNormalImageList($hTreeView, _DeviceAPI_GetClassImageList())

Dim $total_devices = 0

_DeviceAPI_GetClasses()
While _DeviceAPI_EnumClasses()

	;Build list of devices within current class, if class doesn't contain any devices it will be skipped
	_DeviceAPI_GetClassDevices($p_currentGUID)

	;Skip classes without devices
	If _DeviceAPI_GetDeviceCount() > 0 and _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER) = '' Then


		;Add parent class to treeview
		$parent = _GUICtrlTreeView_Add($hTreeView, 0, _DeviceAPI_GetClassDescription($p_currentGUID))

		;Loop through all devices by index
		While _DeviceAPI_EnumDevices()

			$description = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DEVICEDESC)
			$friendly_name = _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME)

			;If a friendly name is available, use it instead of description
			If $friendly_name <> "" Then
			  $description = $friendly_name
		    EndIf


			;Add device to treeview below parent
			$handle = _GUICtrlTreeView_AddChild($hTreeView, $parent, $description)

			If $total_devices > 0 Then
				ReDim $aAssoc[$total_devices+1][2]
			EndIf

			;Add treeview item handle to array along with device Unique Instance Id (For lookup)
			$aAssoc[$total_devices][0] = $handle
			$aAssoc[$total_devices][1] = _DeviceAPI_GetDeviceId()

			;Update running total count of devices
			$total_devices += 1
		WEnd
	EndIf
WEnd

;Cleanup image list
_DeviceAPI_DestroyClassImageList()

_DeviceAPI_DestroyDeviceInfoList() ;Cleanup for good measure


GUICtrlCreateTabItem("")

GUISetState()

While 1
    Sleep(100)
WEnd


Func CLOSEClicked()
  Exit
EndFunc


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;      MAIN FUNCTIONS    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ErrorsLog Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func ErrorRenew_Button()
	        GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
			_GUICtrlListView_DeleteAllItems($hListViewEv)
			GUICtrlSetData($hInput, '')
            GUICtrlSetData($hInputAll, '')
            $aErrorsNew = __ErrorLog()
            If $aErrorsNew <>0 Then
                For $i = 1 To UBound($aErrorsNew) - 1
				_GUICtrlListView_AddItem($hListViewEv, $aErrorsNew[$i])
                Next
                _GUICtrlListView_SetItemSelected($hListViewEv, 0)
			EndIf
            sleep(1000)
			GUICtrlSetState($nErrorRenew_Button, $GUI_ENABLE)
            GUICtrlSetState($ListViewEv, $GUI_FOCUS)
EndFunc

Func WM_NOTIFY_Ev($hWnd, $iMsg, $wParam, $lParam)
	 WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $ID = DllStructGetData($tNMITEMACTIVATE, 'Code')
    Switch $hFrom
        Case $hListViewEv
            Switch $ID
                Case $LVN_ITEMCHANGED
                    If (BitAND(DllStructGetData($tNMITEMACTIVATE, 'Changed'), $LVIF_STATE)) And _
                            (BitAND(DllStructGetData($tNMITEMACTIVATE, 'NewState'), $LVIS_SELECTED)) _
                            And (Not BitAND(DllStructGetData($tNMITEMACTIVATE, 'OldState'), $LVIS_FOCUSED)) Then
                        _ErrorHelp($Index)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func __ErrorLog()
    GUICtrlSetState($nErrorRenew_Button, $GUI_DISABLE)
    Local $sLog = '', $hError, $aErrorsTemp, $i
    Dim $aErrors[1]
    $hError = Run('CSCRIPT.exe ' & @SystemDir & '\eventquery.vbs /v /fi "Type eq ERROR" /fo TABLE /NH', '', @SW_HIDE, $STDOUT_CHILD)
    While 1
        $sLog &= StdoutRead($hError)
        If @error Then ExitLoop
       ; Sleep(10)
    WEnd
    If Not $sLog Then Return 0
    $aErrorsTemp = StringSplit(_Encoding_866To1251($sLog), @LF)
    If Not IsArray($aErrorsTemp) Then Return 0
	Dim $aErrors[$aErrorsTemp[0]]
    For $i = 1 To $aErrorsTemp[0]
        If StringInStr($aErrorsTemp[$i], "ошибка") Then
            $aErrors[0] += 1
            $aErrors[$aErrors[0]] = StringStripWS(StringStripCR($aErrorsTemp[$i]), 7)
        EndIf
    Next
    If $aErrors[0] < 1 Then Return 0
	ReDim $aErrors[$aErrors[0]+1]
    Return $aErrors
EndFunc   ;==>__ErrorLog


Func _ErrorHelp($Index)
    Local $iNumberError, $hHelp, $sLog = ''
    GUICtrlSetState($hListViewEv, $GUI_DISABLE)
	$sItemText = _GUICtrlListView_GetItemText($hListViewEv, $Index)
    $iNumberError = StringRegExpReplace($sItemText, "(?s).*?ошибка (.*?)\s+?.*", '\1')
    $hHelp = Run('net helpmsg ' & $iNumberError, '', @SW_HIDE, $STDOUT_CHILD)
    While 1
        $sLog &= StdoutRead($hHelp)
        If @error Then ExitLoop
        ;Sleep(10)
    WEnd
    $sLog = StringStripWS(StringStripCR(_Encoding_866To1251($sLog)), 7)
    GUICtrlSetData($hInput, 'Ошибка № ' & $iNumberError & '  -  ' & $sLog)
	GUICtrlSetData($hInputAll, $sItemText)
    GUICtrlSetState($hListViewEv, $GUI_ENABLE)
EndFunc   ;==>_ErrorHelp

;; End ErrorLog Section  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DriverErrors Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func WM_NOTIFY_Dr($hWnd, $iMsg, $wParam, $lParam)
	;#forceref $hWnd, $iMsg, $wParam
	Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView

	$hWndTreeview = $hTreeView
	If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
	$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
	$iCode = DllStructGetData($tNMHDR, "Code")
	Switch $hWndFrom
		Case $hWndTreeview
			Switch $iCode
				Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
					RefreshDeviceProperties()
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

;Triggered when a device is selected in the treeview
Func RefreshDeviceProperties()
	Local $hSelected = _GUICtrlTreeView_GetSelection($hTreeView)

	;Don't do anything if a class name (root item) was clicked
	If _GUICtrlTreeView_Level($hTreeView, $hSelected) = 0 Then Return

	;Lookup treeview item handle in global array
	For $X = 0 to Ubound($aAssoc)-1

		If $hSelected = $aAssoc[$X][0] Then
			;MsgBox(0,"", "Handle: " & $aAssoc[$X][0] & @CRLF & "Unique Instance Id: " & $aAssoc[$X][1])

			;Build list of ALL device classes
			_DeviceAPI_GetClassDevices()

			;Loop through all devices by index
			While _DeviceAPI_EnumDevices()
				If $aAssoc[$X][1] = _DeviceAPI_GetDeviceId() Then

					;Empty listview
					_GUICtrlListView_DeleteAllItems($hListView)

					GUICtrlCreateListViewItem ("Hardware ID: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_HARDWAREID), $hListView )
					GUICtrlCreateListViewItem ("Unique Instance ID: |" & _DeviceAPI_GetDeviceId(), $hListView )
					GUICtrlCreateListViewItem ("Manufacturer: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_MFG), $hListView )
					GUICtrlCreateListViewItem ("Driver: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_DRIVER), $hListView )
					GUICtrlCreateListViewItem ("Friendly Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_FRIENDLYNAME), $hListView )
					GUICtrlCreateListViewItem ("Physical Device Object Name: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_PHYSICAL_DEVICE_OBJECT_NAME), $hListView )
					GUICtrlCreateListViewItem ("Upper Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_UPPERFILTERS), $hListView )
					GUICtrlCreateListViewItem ("Lower Filters: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_LOWERFILTERS), $hListView )
					GUICtrlCreateListViewItem ("Enumerator: |" & _DeviceAPI_GetDeviceRegistryProperty($SPDRP_ENUMERATOR_NAME), $hListView )

					;Resize columns to fit text
					_GUICtrlListView_SetColumnWidth($hListView, 0,$LVSCW_AUTOSIZE)
					_GUICtrlListView_SetColumnWidth($hListView, 1,$LVSCW_AUTOSIZE)
				EndIf
			WEnd
		EndIf
	Next
EndFunc
;; End DriverErrors Section  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Где я накосячил, сэнсей?

-------
мы рождены, чтоб сказку сделать былью


Отправлено: 23:58, 07-09-2010 | #6