PDA

View Full Version : حرفه ای: گرفتن مسیر کامل پروسس ها در ویندوز7 و 8



mi5coder
شنبه 31 فروردین 1392, 21:35 عصر
سلام دوستان
کد زیر به خوبی تو xp جواب میده اما تو 7 به طور ناقص و تو 8 هم کلا نمیتونه مسیر کامل پروسس ها رو نشون بده. فقط اسم فایلهای اجرایی رو میگه.
اگه دوستان میدونن چطور مشکل رو حل کنم، ممنون میشم





uses
.... , PsAPI, TlHelp32;

function RunningProcessesList(FullPath: Boolean; seperation:string=#13+#10): string;

function ProcessFileName(PID: DWORD): string;
var
Handle: THandle;
begin
Result := '';
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
if Handle <> 0 then
try
SetLength(Result, MAX_PATH);
if FullPath then
begin
if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end
else
begin
if GetModuleBaseNameA(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end;
finally
CloseHandle(Handle);
end;
end;

var
SnapProcHandle: THandle;
ProcEntry: TProcessEntry32;
NextProc: Boolean;
FileName: string;
OK: boolean;
begin
SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
OK := (SnapProcHandle <> INVALID_HANDLE_VALUE);
if OK then
try
ProcEntry.dwSize := SizeOf(ProcEntry);
NextProc := Process32First(SnapProcHandle, ProcEntry);
while NextProc do
begin
if ProcEntry.th32ProcessID = 0 then
begin
// PID 0 is always the "System Idle Process" but this name cannot be
// retrieved from the system and has to be fabricated.
FileName := 'System Idle Process';
end
else
begin
FileName := ProcessFileName(ProcEntry.th32ProcessID);
if FileName = '' then
FileName := ProcEntry.szExeFile;
end;
if Result = '' then
Result := FileName
else
Result := Result + seperation + FileName;
NextProc := Process32Next(SnapProcHandle, ProcEntry);
end;
finally
CloseHandle(SnapProcHandle);
end;

end;

SayeyeZohor
شنبه 31 فروردین 1392, 23:50 عصر
System Idle Process
System
smss.exe
csrss.exe
wininit.exe
csrss.exe
winlogon.exe
services.exe
lsass.exe
svchost.exe
nvvsvc.exe
svchost.exe
svchost.exe
dwm.exe
svchost.exe
svchost.exe
svchost.exe
nvxdsync.exe
nvvsvc.exe
svchost.exe
wlanext.exe
conhost.exe
spoolsv.exe
sched.exe
svchost.exe
avguard.exe
BSQLServer.exe
taskhostex.exe
ipoint.exe
itype.exe
explorer.exe
SynTPEnh.exe
EvtEng.exe
dasHost.exe
openvpnas.exe
HssSrv.exe
hsswd.exe
HeciServer.exe
Jhi_service.exe
PandoraService.exe
PMBDeviceInfoProvider.exe
RegSrvc.exe
VESMgr.exe
VESMgrSub.exe
VESMgrSub.exe
VCFw.exe
ZeroConfigService.exe
NetworkClient.exe
nvtray.exe
dllhost.exe
RAVBg64.exe
RAVBg64.exe
rundll32.exe
C:\Program Files (x86)\Internet Download Manager\IDMan.exe
avshadow.exe
pcee4.exe
C:\Program Files (x86)\Internet Download Manager\IEMonitor.exe
C:\Program Files (x86)\Avira\AntiVir Desktop\avgnt.exe
PanProcess.exe
avmailc.exe
avwebgrd.exe
WmiPrvSE.exe
unsecapp.exe
alg.exe
svchost.exe
SearchIndexer.exe
svchost.exe
SpfService64.exe
devmonsrv.exe
obexsrv.exe
C:\Program Files (x86)\CyberLink\Power2Go8\CLMLSvc_P2G8.exe
C:\Program Files (x86)\Hotspot Shield\bin\openvpntray.exe
SynTPHelper.exe
dllhost.exe
VAIOUpdt.exe
VUAgent.exe
BTHSAmpPalService.exe
BTHSSecurityMgr.exe
RIconMan.exe
IntelMeFWService.exe
LMS.exe
daemonu.exe
VCPerfService.exe
SOHDms.exe
UNS.exe
svchost.exe
wmpnetwk.exe
dllhost.exe
vim.exe
vim.exe
VCSystemTray.exe
VCService.exe
VCAgent.exe
C:\Program Files\Sony\VAIO Care\listener.exe
vds.exe
C:\Program Files (x86)\Embarcadero\RAD Studio\10.0\bin\bds.exe
C:\Program Files (x86)\Embarcadero\RAD Studio\10.0\bin\bds.exe
C:\Program Files (x86)\The KMPlayer\KMPlayer.exe
C:\Program Files (x86)\NAP\Uni Ware\EmamSadeghWare.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Embarcadero\RAD Studio\10.0\bin\bds.exe
audiodg.exe
SearchProtocolHost.exe
taskeng.exe
SearchFilterHost.exe
C:\Users\Dear_User\Documents\RAD Studio\Projects\Win32\Debug\Project2.exe



function RunningProcessesList(FullPath: Boolean; seperation:string=#13+#10): string;

function ProcessFileName(PID: DWORD): string;
var
Handle: THandle;
begin
Result := '';
Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);
if Handle <> 0 then
try
SetLength(Result, MAX_PATH);
if FullPath then
begin
if GetModuleFileNameEx(Handle, 0, PChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end
else
begin
if GetModuleBaseNameA(Handle, 0, PansiChar(Result), MAX_PATH) > 0 then
SetLength(Result, StrLen(PChar(Result)))
else
Result := '';
end;
finally
CloseHandle(Handle);
end;
end;

var
SnapProcHandle: THandle;
ProcEntry: TProcessEntry32;
NextProc: Boolean;
FileName: string;
OK: boolean;
begin
SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
OK := (SnapProcHandle <> INVALID_HANDLE_VALUE);
if OK then
try
ProcEntry.dwSize := SizeOf(ProcEntry);
NextProc := Process32First(SnapProcHandle, ProcEntry);
while NextProc do
begin
if ProcEntry.th32ProcessID = 0 then
begin
// PID 0 is always the "System Idle Process" but this name cannot be
// retrieved from the system and has to be fabricated.
FileName := 'System Idle Process';
end
else
begin
FileName := ProcessFileName(ProcEntry.th32ProcessID);
if FileName = '' then
FileName := ProcEntry.szExeFile;
end;
if Result = '' then
Result := FileName
else
Result := Result + seperation + FileName;
NextProc := Process32Next(SnapProcHandle, ProcEntry);
end;
finally
CloseHandle(SnapProcHandle);
end;
end;



اين كد رو امتحان كن جواب نداد بگو راه ديگه بگم

mi5coder
یک شنبه 01 اردیبهشت 1392, 19:48 عصر
ضمن تشکر عرض کنم که شما تنها در یکجا به جای pchar از pansichar استفاده کردی که هیچ تاثیری رو اصل موضوع نداره.

دیگر دوستان متخصص اینجا نظری ندارند ؟

SayeyeZohor
یک شنبه 01 اردیبهشت 1392, 20:17 عصر
بله درسته
خب شما منظورتون رو كامل بگين كه مي خواين چي كار كنين؟

SayeyeZohor
یک شنبه 01 اردیبهشت 1392, 20:22 عصر
شما مي تونين از كامپوننت ProcessInfo هم استفاده كنين

BORHAN TEC
یک شنبه 01 اردیبهشت 1392, 20:38 عصر
سلام

یک راهنمایی کلی برای بدست آوردن مسیر کامل پروسه: موقعی که بخواهید نام ماجولهای مورد استفاده یک پروسه را بدست آورید اولین آیتمی که بدست می آید مسیر کامل فایل اجرایی پروسه خواهد بود. :چشمک:

موفق باشید...

Mask
دوشنبه 02 اردیبهشت 1392, 09:02 صبح
اگه شما در ویندوزهای 64 بیتی مشکل دارید ، این امر عادیه و برای بدست آوردن مسیر پروسه های 64 بیتی برنامه شما باید مثل یه لینکر عمل کرده و با هسته 64 بیتی ، با این پروسه ها کار کنه.

Felony
پنج شنبه 05 اردیبهشت 1392, 06:20 صبح
نمونه ضمیمه با WMI لیست مورد نظر رو به دست میاره ، البته برای به دست آوردن آدرس تمام پروسه ها باید دسترسی Admin داشته باشه .