source: trunk/bin/SubOperation/enum_process64/enum_process64.abp@ 351

Last change on this file since 351 was 187, checked in by dai, 18 years ago

AB本体のバイナリを登録

File size: 3.1 KB
Line 
1#include "enum_process64.idx"
2
3#include <api_shlwapi.sbp>
4#include <api_psapi.sbp>
5#include <api_tlhelp32.sbp>
6
7' ↓ ここからプログラムが実行されます
8
9
10' EnumWindowsProcコールバック関数
11Function FindWindowProc(hwnd As HWND, lParam As LPARAM) As BOOL
12 Set_LONG_PTR(lParam As VoidPtr,hwnd As Int64)
13 FindWindowProc=FALSE '列挙を中断
14End Function
15
16Sub main(lpszCmdLine As LPSTR)
17 Dim temporary[MAX_PATH] As Byte, temp2[1024] As Byte
18
19 Dim lpszBuffer As LPSTR
20 lpszBuffer=calloc(1)
21
22 Dim szAppPath[MAX_PATH] As Byte
23 GetModuleFileName(GetModuleHandle(0),szAppPath,MAX_PATH)
24
25 Dim pdwProcessId As *DWord
26 pdwProcessId=malloc(8192*SizeOf(DWord))
27
28 'プロセスを列挙
29 Dim cbNeeded As DWord
30 EnumProcesses(pdwProcessId,8192*sizeof(DWORD),cbNeeded)
31
32 Dim i As Long
33 For i=0 To ELM(cbNeeded/SizeOf(DWord))
34
35 'プロセスIDを元にハンドルを取得
36 Dim hProcess As HANDLE
37 hProcess=OpenProcess(PROCESS_ALL_ACCESS,0,pdwProcessId[i])
38 If hProcess=0 Then Continue
39
40 'そのプロセスにおける実行モジュールのインスタンスハンドルを取得
41 Dim hModule As HINSTANCE
42 Dim cbReturned As DWord
43 If EnumProcessModules(hProcess, VarPtr(hModule), sizeof(HINSTANCE), cbReturned )=0 Then Continue
44
45 '実行ファイル名を取得
46 GetModuleFileNameEx(hProcess,hModule,temporary,MAX_PATH)
47
48 Dim bWow64 As BOOL
49 Dim lpszPlatform As LPSTR
50 IsWow64Process(hProcess,bWow64)
51 If bWow64 Then
52 lpszPlatform="Win32"
53 Else
54 lpszPlatform="Win64"
55 End If
56
57
58 '------------------------------
59 ' ウィンドウタイトルを取得
60 '------------------------------
61
62 'スナップショットを取得
63 Dim hSnapshot As HANDLE
64 hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0)
65
66 Dim te As THREADENTRY32
67 FillMemory(VarPtr(te),SizeOf(THREADENTRY32),0)
68 te.dwSize=SizeOf(THREADENTRY32)
69 If Thread32First(hSnapshot,te) Then
70 Do
71 If te.th32OwnerProcessID=pdwProcessId[i] Then
72 Exit Do
73 End If
74 Loop While Thread32Next(hSnapshot,te)
75 End If
76
77 Dim hwnd As HWND
78 hwnd=0
79 EnumThreadWindows(te.th32ThreadID,AddressOf(FindWindowProc),VarPtr(hwnd) As LPARAM)
80
81 While GetParent(hwnd)
82 hwnd=GetParent(hwnd)
83 Wend
84
85 Dim szWndTitle[1024] As Byte
86 szWndTitle[0]=0
87 If hwnd Then GetWindowText(hwnd,szWndTitle,1024)
88
89 CloseHandle(hSnapshot)
90
91
92 CloseHandle(hProcess)
93
94
95 '自分自身は無視
96 If lstrcmpi(temporary,szAppPath)=0 Then
97 Continue
98 End If
99
100
101
102 '--------------------
103 ' バッファへ追加
104 '--------------------
105
106 wsprintf(temp2,Ex"\q%s\q,%d,%s,%s\r\n",temporary,pdwProcessId[i],lpszPlatform,szWndTitle)
107
108 lpszBuffer=realloc(lpszBuffer,lstrlen(lpszBuffer)+lstrlen(temp2)+1)
109 lstrcat(lpszBuffer,temp2)
110 Next
111
112 free(pdwProcessId)
113
114
115 '-----------------------
116 ' ファイルへ保存
117 '-----------------------
118
119 _splitpath(szAppPath,temporary,temp2,NULL,NULL)
120 lstrcat(temporary,temp2)
121 lstrcat(temporary,"list.dat")
122
123 Dim hFile As HANDLE
124 hFile=CreateFile(temporary,GENERIC_WRITE,0,ByVal 0,CREATE_ALWAYS,0,0)
125
126 Dim dwAccBytes As DWord
127 WriteFile(hFile,lpszBuffer,lstrlen(lpszBuffer),VarPtr(dwAccBytes),ByVal 0)
128
129 CloseHandle(hFile)
130
131 free(lpszBuffer)
132End Sub
133
134main(PathGetArgs(GetCommandLine()))
Note: See TracBrowser for help on using the repository browser.