0

I found this C# and I want to improve on it in Go: https://github.com/roachadam/MinerKiller/blob/master/MinerKiller/MinerKiller.cs

My first question, is how do I detect if a process window is hidden. ie this code:

if (p.MainWindowHandle == IntPtr.Zero )

My Second question is how to get the command line of a process. ie this C# code

private string GetCommandLine(Process process)
{
     string cmdLine = null;
     using (var searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
     {
          var matchEnum = searcher.Get().GetEnumerator();
          if (matchEnum.MoveNext())
          {
              cmdLine = matchEnum.Current["CommandLine"]?.ToString();
          }
      }
      return cmdLine;
}
Dmitry Harnitski
  • 5,838
  • 1
  • 28
  • 43
dom
  • 321
  • 2
  • 12
  • You cannot migrate, but you want to improve. Can be challenging with your current `GO` experience. Will it make sense to improve it using C#? – Dmitry Harnitski Jan 03 '19 at 22:49

1 Answers1

2

While the go standard library's os package provides a lot of nice utilities for interfacing with operating system functionality, they are much "lower level" then what you are referencing from the .NET System.Management classes. You will most likely have to implement the behavior of these classes yourself to achieve the desired outcome (using the tool from Go's os package as your primary "building blocks")

That said, there is a psutil port in Go (gopsutil - https://github.com/shirou/gopsutil/) that provides utilities for retrieving info on running processes as well as system utilization. This will most likely provide the higher level abstraction you can use to implement your program.

If gopsutil is too opinionated or high level for you needs, I would also check out the operating system specific packages in the golang subrepositories.

Documented here: https://godoc.org/golang.org/x/sys

Source here: https://github.com/golang/sys/

syllabix
  • 2,240
  • 17
  • 16