O
O
OOOCYBER2021-09-11 13:57:09
.NET
OOOCYBER, 2021-09-11 13:57:09

How to find out with what parameters the program is running?

How to find out with what console parameters a specific, third-party process is launched using C# tools?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2021-09-11
@OOOCYBER

1) We call the sports lotto so that you can connect the free google service;
2) Go to https://google.com and write a simple request "c# find out the parameters of the running application"
3) Follow the first link: Getting information from the "Command line" column...
4) ctrl+c and ctrl+v:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Management;
 
namespace ConsoleApplication7 {
    class Program {
        static void Main(string[] args) {
            Process[] processList = Process.GetProcesses();
            Process p = processList.Where(temp => temp.Id == 844).FirstOrDefault();
            if (p != null) {
                GetCommandLine(p.Id);
            }
            Console.ReadLine();
        }
        public static void GetCommandLine(int id) {
            using (ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + id)) {
                foreach (ManagementObject mo in mos.Get()) {
                    Console.WriteLine(mo["CommandLine"]);
                }
 
            }
        }
    }
}

A
Alexander, 2021-09-11
@Adler_lug

private static string GetCommandLine(this Process process)
{
    using (ManagementObjectCollection objects = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id).Get())
    {
        return objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString();
    }
}

Other options are here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question