delphi - Not getting path of various System Processes by getModuleFileNameEx -


i have created function path of various network processes , svchost, firefox etc. here code:

    function getprocesspath(var pid:integer):string;     var        handle: thandle;     begin    result := '';     try        handle := openprocess(process_query_information or process_vm_read, false, pid);        if handle <> 0       begin       try           setlength(result, max_path);           if getmodulefilenameex(handle, 0, pchar(result), max_path) > 0               setlength(result, strlen(pchar(result)))           else              result := '';              closehandle(handle);      end;      end;    except       on e:exception      showmessage(e.classname+':'+e.message);     end;     end; 

my problem not path of processes. works fine getting path of firefox, , other similiar user level processes. processes alg, svchost, cannot path method. guess must use diff. api. please me in regard.

thanks in advance

you need set debug privileges here how done

function ntsetprivilege(sprivilege: string; benabled: boolean): boolean; var   htoken: thandle;   tokenpriv: token_privileges;   prevtokenpriv: token_privileges;   returnlength: cardinal; begin   result := true;   // windows nt/2000/xp , later.   if not (win32platform = ver_platform_win32_nt) exit;   result := false;    // obtain processes token   if openprocesstoken(getcurrentprocess(),     token_adjust_privileges or token_query, htoken)   begin     try       // locally unique identifier (luid) .       if lookupprivilegevalue(nil, pchar(sprivilege),         tokenpriv.privileges[0].luid)       begin         tokenpriv.privilegecount := 1; // 1 privilege set          case benabled of           true: tokenpriv.privileges[0].attributes  := se_privilege_enabled;           false: tokenpriv.privileges[0].attributes := 0;         end;          returnlength := 0; // replaces var parameter         prevtokenpriv := tokenpriv;          // enable or disable privilege          adjusttokenprivileges(htoken, false, tokenpriv, sizeof(prevtokenpriv),           prevtokenpriv, returnlength);       end;           closehandle(htoken);     end;   end;   end;     ntsetprivilege('sedebugprivilege',true);//call on form create 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -