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

Last change on this file since 411 was 364, checked in by イグトランス (egtra), 17 years ago

FormatFloatFを実装

File size: 3.1 KB
RevLine 
[187]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
[364]12 SetPointer(lParam As VoidPtr, hwnd As VoidPtr)
13 FindWindowProc = FALSE '列挙を中断
[187]14End Function
15
[364]16Sub main(lpszCmdLine As LPTSTR)
17 Dim temporary[MAX_PATH] As TCHAR, temp2[1024] As TCHAR
[187]18
[364]19 Dim lpszBuffer As LPTSTR
20 lpszBuffer=calloc(SizeOf (TCHAR))
[187]21
[364]22 Dim szAppPath[MAX_PATH] As TCHAR
23 GetModuleFileName(GetModuleHandle(0), szAppPath, MAX_PATH)
[187]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を元にハンドルを取得
[364]36 Dim hProcess = OpenProcess(PROCESS_ALL_ACCESS,0,pdwProcessId[i])
[187]37 If hProcess=0 Then Continue
38
39 'そのプロセスにおける実行モジュールのインスタンスハンドルを取得
40 Dim hModule As HINSTANCE
41 Dim cbReturned As DWord
42 If EnumProcessModules(hProcess, VarPtr(hModule), sizeof(HINSTANCE), cbReturned )=0 Then Continue
43
44 '実行ファイル名を取得
45 GetModuleFileNameEx(hProcess,hModule,temporary,MAX_PATH)
46
47 Dim bWow64 As BOOL
48 Dim lpszPlatform As LPSTR
49 IsWow64Process(hProcess,bWow64)
50 If bWow64 Then
51 lpszPlatform="Win32"
52 Else
53 lpszPlatform="Win64"
54 End If
55
56
57 '------------------------------
58 ' ウィンドウタイトルを取得
59 '------------------------------
60
61 'スナップショットを取得
62 Dim hSnapshot As HANDLE
63 hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0)
64
65 Dim te As THREADENTRY32
66 FillMemory(VarPtr(te),SizeOf(THREADENTRY32),0)
67 te.dwSize=SizeOf(THREADENTRY32)
68 If Thread32First(hSnapshot,te) Then
69 Do
70 If te.th32OwnerProcessID=pdwProcessId[i] Then
71 Exit Do
72 End If
73 Loop While Thread32Next(hSnapshot,te)
74 End If
75
[364]76 Dim hwnd = 0 As HWND
[187]77 EnumThreadWindows(te.th32ThreadID,AddressOf(FindWindowProc),VarPtr(hwnd) As LPARAM)
78
79 While GetParent(hwnd)
80 hwnd=GetParent(hwnd)
81 Wend
82
[364]83 Dim szWndTitle[1024] As TCHAR
[187]84 szWndTitle[0]=0
85 If hwnd Then GetWindowText(hwnd,szWndTitle,1024)
86
87 CloseHandle(hSnapshot)
88
89
90 CloseHandle(hProcess)
91
92
93 '自分自身は無視
94 If lstrcmpi(temporary,szAppPath)=0 Then
95 Continue
96 End If
97
98
99
100 '--------------------
101 ' バッファへ追加
102 '--------------------
103
[364]104 wsprintf(temp2,ToTCStr(Ex"\q%s\q,%d,%s,%s\r\n"),temporary,pdwProcessId[i],lpszPlatform,szWndTitle)
[187]105
106 lpszBuffer=realloc(lpszBuffer,lstrlen(lpszBuffer)+lstrlen(temp2)+1)
107 lstrcat(lpszBuffer,temp2)
108 Next
109
110 free(pdwProcessId)
111
112
113 '-----------------------
114 ' ファイルへ保存
115 '-----------------------
116
117 _splitpath(szAppPath,temporary,temp2,NULL,NULL)
118 lstrcat(temporary,temp2)
[364]119 lstrcat(temporary,ToTCStr("list.dat"))
[187]120
[364]121 Dim hFile = CreateFile(temporary,GENERIC_WRITE,0,ByVal 0,CREATE_ALWAYS,0,0)
[187]122
123 Dim dwAccBytes As DWord
124 WriteFile(hFile,lpszBuffer,lstrlen(lpszBuffer),VarPtr(dwAccBytes),ByVal 0)
125
126 CloseHandle(hFile)
127
128 free(lpszBuffer)
129End Sub
130
131main(PathGetArgs(GetCommandLine()))
Note: See TracBrowser for help on using the repository browser.