JohnRichard Posted September 10, 2008 Share Posted September 10, 2008 hi all. i have this script which queries network information on remote computer using the WMI. List of information is displayed on array. What i want is that when i select the item in the Listview and right click it, i have the option or popup to copy it then paste in notepad. For short i want to copy the information on the listview. How will i do that? I have the code for _GUICtrlMenu_CreatePopup but i can't make it working. Can somebody help me here. Here is my code: #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListviewConstants.au3> #Include <GuiListView.au3> #include <GuiEdit.au3> #include <GuiMenu.au3> #include <GuiConstantsEx.au3> Global $idMenuInsert = 1000 Local $objItem, $listview, $Data Dim $NICInfo[1][4], $i = 1 $strComputer = InputBox("Network Information", "Enter computer name.") $ping = Ping($strComputer) If $ping Then $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colNicConfigs = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") If IsObj($colNicConfigs) Then For $objItem In $colNicConfigs ReDim $NICInfo[uBound($NICInfo) + 1][5] $NICInfo[$i][0] = $objItem.DNSHostName $strIPAddress = $objItem.IPAddress(0) $NICInfo[$i][1] = $strIPAddress $NICInfo[$i][2] = $objItem.MACAddress $NICInfo[$i][3] = $objItem.DHCPServer $NICInfo[$i][4] = $objItem.Description $i += 1 Next $NICInfo[0][0] = UBound($NICInfo) - 1 If $NICInfo[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf GUICreate("Network Information", 520, 125, 100, 100, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("", 10, 10, 495, 100) $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Copy", $idMenuInsert) _GUICtrlListView_AddColumn ($listview, "Computer Name", 100) _GUICtrlListView_AddColumn ($listview, "IP Address", 100) _GUICtrlListView_AddColumn ($listview, "MACAddress", 100) _GUICtrlListView_AddColumn ($listview, "DHCP Server", 100) _GUICtrlListView_AddColumn ($listview, "NIC Description", 180) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() For $i = 1 To UBound($NICInfo) - 1 $tmp = $NICInfo[$i][0] & "|" & $NICInfo[$i][1] & "|" & $NICInfo[$i][2] & "|" & $NICInfo[$i][3] & "|" & $NICInfo[$i][4] GUICtrlCreateListViewItem($tmp, $listview) Next While 1 If GUIGetMsg() = -3 Then Exit WEnd Else MsgBox(0, "Error", "Could not locate computer") EndIf Link to comment Share on other sites More sharing options...
JohnRichard Posted September 11, 2008 Author Share Posted September 11, 2008 hi guys. i'm sorry i have posted the wrong code. the previous one does not return any value. below is the correct code on which i'm trying to work the pop up menu to copy contents on listview item. code: #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListviewConstants.au3> #Include <GuiListView.au3> #include <GuiEdit.au3> #include <GuiMenu.au3> ;Global $idMenuInsert = 1000 Local $objItem, $listview, $Data Dim $NICInfo[1][5], $i = 1 $strComputer = InputBox("Network Information", "Enter computer name.") $ping = Ping($strComputer) If $ping Then $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colNicConfigs = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") If IsObj($colNicConfigs) Then For $objItem In $colNicConfigs ReDim $NICInfo[uBound($NICInfo) + 1][5] $NICInfo[$i][0] = $objItem.DNSHostName $strIPAddress = $objItem.IPAddress(0) $NICInfo[$i][1] = $strIPAddress $NICInfo[$i][2] = $objItem.MACAddress $NICInfo[$i][3] = $objItem.DHCPServer $NICInfo[$i][4] = $objItem.Description $i += 1 Next $NICInfo[0][0] = UBound($NICInfo) - 1 If $NICInfo[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf GUICreate("Network Information", 520, 125, 100, 100, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("", 10, 10, 495, 100) ;$hMenu = _GUICtrlMenu_CreatePopup() ;_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Copy", $idMenuInsert) _GUICtrlListView_AddColumn ($listview, "Computer Name", 100) _GUICtrlListView_AddColumn ($listview, "IP Address", 100) _GUICtrlListView_AddColumn ($listview, "MACAddress", 100) _GUICtrlListView_AddColumn ($listview, "DHCP Server", 100) _GUICtrlListView_AddColumn ($listview, "NIC Description", 180) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState() For $i = 1 To UBound($NICInfo) - 1 $tmp = $NICInfo[$i][0] & "|" & $NICInfo[$i][1] & "|" & $NICInfo[$i][2] & "|" & $NICInfo[$i][3] & "|" & $NICInfo[$i][4] GUICtrlCreateListViewItem($tmp, $listview) Next While 1 If GUIGetMsg() = -3 Then Exit WEnd Else MsgBox(16, "Error", "Could not locate computer!") EndIf Link to comment Share on other sites More sharing options...
JohnRichard Posted September 11, 2008 Author Share Posted September 11, 2008 can someone check and give me a help? i appreciate all your help. thanks. Link to comment Share on other sites More sharing options...
rasim Posted September 11, 2008 Share Posted September 11, 2008 JohnRichardPlease use a code tags for your code.expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListviewConstants.au3> #Include <GuiListView.au3> #include <GuiEdit.au3> #include <GuiMenu.au3> ;Global $idMenuInsert = 1000 Local $objItem, $listview, $Data Dim $NICInfo[1][5], $i = 1 $strComputer = InputBox("Network Information", "Enter computer name.") If $strComputer = "" Then $strComputer = "localhost" If Ping($strComputer) = 0 Then Exit MsgBox(16, "Error", "Could not locate computer!") $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colNicConfigs = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") If IsObj($colNicConfigs) = 0 Then Exit MsgBox(16, "Error", "$colNicConfigs is not an Object") For $objItem In $colNicConfigs ReDim $NICInfo[UBound($NICInfo) + 1][5] $NICInfo[$i][0] = $objItem.DNSHostName $strIPAddress = $objItem.IPAddress(0) $NICInfo[$i][1] = $strIPAddress $NICInfo[$i][2] = $objItem.MACAddress $NICInfo[$i][3] = $objItem.DHCPServer $NICInfo[$i][4] = $objItem.Description $i += 1 Next $NICInfo[0][0] = UBound($NICInfo) - 1 If $NICInfo[0][0] < 1 Then SetError(1, 1, 0) EndIf GUICreate("Network Information", 520, 125, 100, 100, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("", 10, 10, 495, 100) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $hMenu = GUICtrlCreateContextMenu($listview) $CopyItem = GUICtrlCreateMenuItem("Copy", $hMenu) ;$hMenu = _GUICtrlMenu_CreatePopup() ;_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Copy", $idMenuInsert) _GUICtrlListView_AddColumn ($listview, "Computer Name", 100) _GUICtrlListView_AddColumn ($listview, "IP Address", 100) _GUICtrlListView_AddColumn ($listview, "MACAddress", 100) _GUICtrlListView_AddColumn ($listview, "DHCP Server", 100) _GUICtrlListView_AddColumn ($listview, "NIC Description", 180) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() For $i = 1 To UBound($NICInfo) - 1 $tmp = $NICInfo[$i][0] & "|" & $NICInfo[$i][1] & "|" & $NICInfo[$i][2] & "|" & $NICInfo[$i][3] & "|" & $NICInfo[$i][4] GUICtrlCreateListViewItem($tmp, $listview) Next While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case $CopyItem _GetSelected() EndSwitch WEnd Func _GetSelected() Local $iText = GUICtrlRead(GUICtrlRead($listview)) MsgBox(0, "", $iText) EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $listview Switch $iCode Case $NM_RCLICK Local $tINFO = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iItem = DllStructGetData($tINFO, "Item") If $iItem = -1 Then _MenuPopup() Else _MenuPopup($GUI_ENABLE) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _MenuPopup($sState = $GUI_DISABLE) GUICtrlSetState($CopyItem, $sState) EndFunc Link to comment Share on other sites More sharing options...
JohnRichard Posted September 11, 2008 Author Share Posted September 11, 2008 thanks a lot rasim. it works great. sorry for not using code tags on my script. maybe on the future i will use code tags to easily handle the script. is there a way when i copy it i can paste it in notepad or somehow export it to excel. forgive me for i have so many ideas coming up in my mind. Link to comment Share on other sites More sharing options...
rasim Posted September 11, 2008 Share Posted September 11, 2008 JohnRichard is there a way when i copy it i can paste it in notepadUse functions: ControlSend() ControlSetText() 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