java


Getting hWnd from current process


I tried to get hWnd from current process using GetCurrentProcess function to display path to each process. But I got an error in this line: User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
How to convert it to the desired type?
The method GetWindowThreadProcessId(WinDef.HWND, IntByReference) in the type User32 is not applicable for the arguments (WinNT.HANDLE, IntByReference)
There is my code:
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
kernel32.GetCurrentProcess();
HANDLE hWnd = kernel32.GetCurrentProcess();
User32.INSTANCE.GetWindowThreadProcessId(hWnd, pid);
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010,
false, pid.getValue());
psapi.GetModuleFileNameExA(process, null, path, 1024);
System.out.println(Native.toString(path));
}
} finally {
kernel32.CloseHandle(snapshot);
}
UPD:
The problem was solved in this way:
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010,
false, processEntry.th32ProcessID.intValue());
if (process != null) {
int len = psapi.GetModuleFileNameExW(process, null, path,
1024);
if (len > 0) {
System.out.println(new String(path, 0, len));
} else {
System.out.println("GetModuleFileNameW failed");
}
} else {
System.out.println(kernel32.GetLastError());
}
System.out.println(process != null ? Native.toString(path) : "error");
}
} finally {
kernel32.CloseHandle(snapshot);
}
Thank you for help!
A) get a list of Process Identifiers (PID) using the Win32 API EnumProcesses or the Win32 APIs CreateToolhelp32Snapshot / Process32First / Process32Next / CloseHandle
B) with each PID, use the win32 API OpenProcess to obtain a HANDLE for the process (request for PROCESS_QUERY_INFORMATION as dwDesiredAccess). With that handle, use the Win32 API GetProcessImageFileName (and do not forget to close the HANDLE with CloseHandle)
Hope this helps (as that's not JAVA code, sorry for that)

Related Links

The SecureClassLoader's purpose
Should I create a class to hold a http status code and endpoint data
Thread “blocks” or “stops” at a certain point in my code - Networking / Server
HMAC SHA-256 difference between Java and PHP
OpenCSV defaults for escape char
HashMap containsKey returns false for Integer
How to get IP from WebSocket Session in JSP?
Which is memory efficient String or StringBuffer for concatenation in java [duplicate]
How to login using UserID in JAVA BOX SDK
Android AlertDialog with a common message for 3 buttons
Printing rows and columns in a 2D Array?
Deriving abstract classes and interface from UML class diagram
Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference using MovieDB API [duplicate]
Java Regex - To parse function name and argument name - throws PatternSyntaxException: Unclosed Character
Append number to end of url string
Converting zenkaku characters to hankaku and vice-versa in Talend MDM

Categories

HOME
yii2
kde
google-play
plot
c#-2.0
webpack-2
add
numeral.js
google-cloud-spanner
spring-tool-suite
event-handling
systemc
google-static-maps
evopdf
ab-testing
visual-composer
jprofiler
kryo
graphicsmagick
sylius
captiveportal
wijmo
cas
traffic
rst2pdf
typo3-6.2.x
facebook-apps
lightswitch-2013
microsoft-chart-controls
bosh
xquery-3.0
google-qpx-express-api
fog
webtest
mozilla
http-referer
ios5
web-mining
android-browser
service-discovery
vapor
hilbert-curve
hue
temporary-files
particles.js
eclipse-scout
ibpy
estimote
fakeiteasy
turbogears
acoustics
logfiles
avconv
osx-mavericks
atomicity
python-c-api
setter
kbuild
font-size
jspdf-autotable
gridpane
probability-density
adxstudio-portals
player
prettytensor
ubuntu-10.04
xpath-1.0
browser-link
ford-fulkerson
unity-networking
icu4j
tarjans-algorithm
android-listview
drawbitmap
createprocessasuser
sniffer
iiviewdeckcontroller
oberon
web-controls
p2
umbraco6
bigbluebutton
xc16
relocation
qcodo
issuu
flask-cors
typeof
poller
typo3-neos
uv-mapping
dbconnection
bulkloader
spring-validator
sharp-repository
anonymous-methods
browser-detection
broken-links
boost-filesystem
qt-jambi
yetanotherforum
iphone-web-app
lang
html-input
yslow
privilege
text-coloring
w3wp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App