获取资源管理器路径
XP
#include <windows.h> #include <stdio.h> int main() { TCHAR str[100] = TEXT("Hello World"); HWND hwnd = NULL; hwnd = FindWindowEx(NULL, NULL, TEXT("CabinetWClass"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("WorkerW"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ReBarWindow32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ComboBoxEx32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ComboBox"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("Edit"), NULL); SendMessage(hwnd, WM_GETTEXT, 100, (LPARAM)str); //SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)str); //GetWindowText(hwnd, str, 100); //MessageBox(NULL, str, TEXT("Cap"), 0); wprintf(TEXT("%s\n"), str); return 0; }
关于GetWindowText为什么不可以用:
http://www.cnblogs.com/MuyouSome/p/3333390.html
Copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application.
WIN7
#include <windows.h> #include <stdio.h> int main() { TCHAR str[100] = TEXT("Hello World"); HWND hwnd = NULL; hwnd = FindWindowEx(NULL, NULL, TEXT("CabinetWClass"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("WorkerW"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ReBarWindow32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("Address Band Root"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("msctls_progress32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ComboBoxEx32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ComboBox"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("Edit"), NULL); SendMessage(hwnd, WM_GETTEXT, 100, (LPARAM)str); //SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)str); MessageBox(NULL, str, TEXT("Cap"), 0); //wprintf(TEXT("%s\n"), str); return 0; }
上面这个还是比较鸡肋的:
需要点击下地址栏才会出现ComboBoxEx32->ComboBox->Edit
测试:
通过点击向下箭头,刷新路径显示
#include <windows.h> #include <stdio.h> #include <locale.h> int main() { TCHAR str[1024] = TEXT("Hello World"); HWND hwnd = NULL; HWND hToolbat; hwnd = FindWindowEx(NULL, NULL, TEXT("CabinetWClass"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("WorkerW"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ReBarWindow32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("Address Band Root"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("msctls_progress32"), NULL); hToolbat = FindWindowEx(hwnd, NULL, TEXT("ToolbarWindow32"), NULL); SendMessage(hToolbat, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(0, 0)); SendMessage(hToolbat, WM_LBUTTONUP, MK_LBUTTON, MAKELONG(0, 0)); SendMessage(hToolbat, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(0, 0)); SendMessage(hToolbat, WM_LBUTTONUP, MK_LBUTTON, MAKELONG(0, 0)); hwnd = FindWindowEx(hwnd, NULL, TEXT("ComboBoxEx32"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("ComboBox"), NULL); hwnd = FindWindowEx(hwnd, NULL, TEXT("Edit"), NULL); if(hwnd == NULL) { wprintf(L"%s\n", L"error"); return -1; } SendMessage(hwnd, WM_GETTEXT, 1024, (LPARAM)str); MessageBox(NULL, str, TEXT("Caption"), 0); return 0; }
利用好wmic命令
E:\MyDocument\Desktop>wmic process /? PROCESS - Process management. HINT: BNF for Alias usage. (<alias> [WMIObject] | <alias> [<path where>] | [<alias>] <path where>) [<verb c lause>]. USAGE: PROCESS ASSOC [<format specifier>] PROCESS CALL <method name> [<actual param list>] PROCESS CREATE <assign list> PROCESS DELETE PROCESS GET [<property list>] [<get switches>] PROCESS LIST [<list format>] [<list switches>]
wmic process where caption="notepad.exe" get commandline /value
wmic process where name="notepad.exe" get executablepath
Keep it simple!