java - How find a certain process using JNA? -


i´m working on java program. has run app administrator and, when execution ends, things. in beginning, used

string cmd[] = new string [3]; cmd [0] = "cmd"; cmd [1] = "/c"; cmd [2] = "runas /user:..." process p = runtime.getruntime().exec(cmd); 

but problem cannot enter password (i tried it, didn´t find solution). after, used jna make it, this:

boolean createprocesswithlogonw     (wstring lpusername,      wstring lpdomain,      wstring lppassword,      int dwlogonflags,      wstring lpapplicationname,      wstring lpcommandline,      int dwcreationflags,      pointer lpenvironment,      wstring lpcurrentdirectory,      startupinfo  lpstartupinfo,      process_information lpprocessinfo); 

here, problem how make wait execution of program until process ends (maybe, in jna, there forms this, big , don´t know how it...)

i thought way it, don´t know if it´s possible... this:

kernel32 kernel32 = (kernel32) native.loadlibrary(kernel32.class, w32apioptions.unicode_options);     tlhelp32.processentry32.byreference processentry = new tlhelp32.processentry32.byreference();            winnt.handle snapshot = kernel32.createtoolhelp32snapshot(tlhelp32.th32cs_snapprocess, new windef.dword(0)); try   {     while (kernel32.process32next(snapshot, processentry))      {                      system.out.println(processentry.th32processid + "\t" + native.tostring(processentry.szexefile));     } } 

whit this, have id , name of process. possible find name of user run process?? if succeed, (the process run administrator one)

regards.

i solved it.

public boolean jambo_loco (int pid) {      kernel32 kernel32 = (kernel32) native.loadlibrary(kernel32.class, w32apioptions.unicode_options);     tlhelp32.processentry32.byreference processentry = new tlhelp32.processentry32.byreference();                winnt.handle snapshot = kernel32.createtoolhelp32snapshot(tlhelp32.th32cs_snapprocess, new windef.dword(0));     try       {         int = 0;          int size = processentry.dwsize.intvalue();          while (kernel32.process32next(snapshot, processentry) && < size)          {                          if (processentry.th32processid.intvalue() == pid)                 return true;             i++;         }      }          {         kernel32.closehandle(snapshot);     }     return false; } 

a loop, in other side, invoques many times method when returns true.

regards.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -