HƯỚNG DẪN LẬP TRÌNH AUTOIT BÀI 8: TƯƠNG TÁC VỚI COMMAND PROMPT(cmd) BẰNG AUTOIT - LẬP TRÌNH AUTOIT

Latest

Sunday, May 26, 2019

HƯỚNG DẪN LẬP TRÌNH AUTOIT BÀI 8: TƯƠNG TÁC VỚI COMMAND PROMPT(cmd) BẰNG AUTOIT

1. Function lấy kết quả từ CMD

Func _GetDOSOutput($sCommand)
   Local $iPID, $sOutput = ''
   $iPID = Run('"cmd"' & @ComSpec & '" /c' & $sCommand, "",@SW_HIDE, 2)
   While 1
      $sOutput &= StdoutRead($iPID,False, False)
      If @error Then
         ExitLoop
      EndIf
      Sleep(10)
   WEnd
   Return $sOutput
EndFunc
--> Ví dụ: Muốn xem danh sách các wifi đã sử dụng trên máy tính:
Chúng ta thêm bên dưới function:
MsgBox(0,"Ví dụ",_GetDOSOutput('netsh wlan show profile'))

2. Chương trình khôi phục mật khẩu Wifi
Tải code tham khảo Tại Đây
 Trong bài này có sử dụng đối tượng Listview, Function lấy kết quả từ "cmd", xử lý kết quả đưa vào đối tượng listview:
Tạo listview:
 GUICtrlCreateListView ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )
              --> Ví dụ: Local $listview = GUICtrlCreateListView("Profile|password", 8, 8, 605, 281) 
Tùy chỉnh chiều rộng các cột trong Listview:
             --> _GUICtrlListView_SetColumnWidth(-1,0,300)
                   _GUICtrlListView_SetColumnWidth(-1,1,300)
 
 Hàm truyền dữ liệu vào listview:
cách 1:
#include <GuiListView.au3>
_GUICtrlListView_AddItem ( $hWnd, $sText [, $iImage = -1 [, $iParam = 0]] )
             --> Ví dụ: Local $index = _GUICtrlListView_AddItem($listview,$profile)
Cách 2:
 #include <GuiListView.au3>
_GUICtrlListView_SetItemText ( $hWnd, $iIndex, $sText [, $iSubItem = 0] )
            --> Ví dụ: _GUICtrlListView_SetItemText($listview,$index,getPassword($profile),1)
 Các lệnh cmd đã dùng trong chương trình:
1. Lấy danh sách các wifi đã từng sử dụng trên máy tính
Local $cmd = _GetDOSOutput('netsh wlan show profile')
2. Hiển thị password cho từng wifi
Local $cmd = _GetDOSOutput(StringFormat('netsh wlan show profile '&$profilename &' key =clear'))

1 comment: