List of running processes in golang, Windows version

How to get a list of running processes in golang under Windows?

I need something like:

List of the current process in the Golang

but can also be used under Windows.

+6
source share
3 answers

I just implemented the function you need (EnumProcess as above). Check out https://github.com/AllenDang/w32 . You might want to wait until my craving request passes :) Usage example: https://gist.github.com/3083408

+7
source

You need to use the Windows API EnumProcesses . The syscall package on Windows allows you to load arbitrary DLLs and their functions (i.e. Via LoadLibrary / GetProcAddress). This way you can get EnumProcesses in psapi.dll . This gives you a list of PIDs; you can use OpenProcess and EnumProcessModules to get the process name.

Someone may already have done this work, but I don’t know anything. If you cannot find anything, look at the source of the syscall package (say src / pkg / syscall / zsyscall_windows_386.go ) and do something similar to what was done for other Windows API functions.

+4
source

as per syscall package docs: this package is blocked. Code outside the standard Go repository must be ported to use the appropriate package in the golang.org/x/sys repository.

You can use golang.org/x/sys/windows, it has Process32First and Process32Next to list system processes.

+2
source

Source: https://habr.com/ru/post/919816/


All Articles