How to get Process object of already running process? - c++-cli

I want a create a C++ program that can find an already running process and then redirect its Standard Output to my own stream for re-direction. I can find countless examples on how to start a new process but I want to try and do something like:
Process^ proc = new Process();
proc->Attach("notepad.exe");
And then have control over the already running notepad.exe process.. Is this possible? If not then I guess I can find a way to start the process from within my application, however then my question would be how can I start a process and send command-line arguments to the process as if I were starting it up in console.

I believe you want GetProcessesByName. It will return an array of all the processes that match the name you give.
array<Process^>^ notepadProcesses = Process::GetProcessesByName("notepad");

Related

Why do I get "No process is associated with this object." when calling process.Close() or process.Kill()?

I have a C# program that is launching TShark.exe which is the background equivalent of WireShark. I would like to close all instances that I start. It appears to start just fine, run in the background and log network traffic to a file as it should. However, when I try to close it, I get a "No process is associated with this object." exception.
Here is how I'm starting the processes:
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
Arguments = $"-i {nic} -t ad -w {GenerateLogPath(nic)}",
FileName = "\"C:\\Program Files\\Wireshark\\tshark.exe\"",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
};
WireSharkProcesses.Add(System.Diagnostics.Process.Start(processStartInfo));
I've tried several methods to close/kill these processes. First, I kept a list of all processes that I had started in my app and called the following on them without success:
process.CloseWindow();
process.Close();
process.Kill();
I kept getting the "No process is associated with this object." exception.
So, I used:
var processes = System.Diagnostics.Process.GetProcesses();
And got a list of all processes on my machine and looped through them and attempted to close those who's process name was "tshark" or "dumpcap". I attempted this with .CloseWindow(), .Close(), and .Kill() all of which failed and threw the above exception.
I even went into TaskManager and attempted to END TASK on them. They appeared to be removed, but upon closing and re-opening TaskManager, they magically reappeared. There are also now several instances of "tshark" and "dumpcap" that show up when I call GetProcesses(), but are not in the list of processes that Task Manager shows.
What am I missing here?? Short of rebooting my machine, how do I get these processes to exit? Is this just a wireshark problem, or a general problem with killing processes?
Are you using WinPcap or Npcap? If you're using WinPcap, you could try switching to Npcap and using that instead. See Gerald Comb's comment #32 on the recently closed Wireshark Bug 14701.
By the way, in case you weren't aware, tshark is capable of capturing on more than one interface at a time, so in theory only a single instance is required. I understand that this can sometimes cause reassembly problems though, so if that's what you're trying to avoid or if you just want to keep packets separated by interface, then yes, you'll have to start multiple instances.

How to execute Workfusion RPA business process using API call or using cmd?

I am new to Workfusion RPA.
I have created one business process from IDE and when i run manually it is working perfectly fine.
Now my Question is:
1. Can we export any executable file so that i can execute it from command prompt?
2. Is there any way we can expose REST api for that business process, so that i can call from any other application?.
please help in this
Thank you in advance
one approach you can take is you can schedule business process to continuesly execute and read a file from directory,cloud storage or sharepoint and you can write rest service or script to change a flag in the file that way you can control the business process execution if the flag is false bp will end in next schedule again it will read the file
There is REST API available to launch and control business processes.
Documentation can be retrieved through such URL:
https://workfusion_deployment_hostname/workfusion/api/swagger-ui.html
task_management section, /v2/workfusion/task/file method. Request body can be as simple as this:
{
"campaignUuid": "b8b95933-....",
"mainData": "column1,column2\nvalue1,value2"
}

How to use console.profile in a WinJS enabled app?

I'm currently working on an app using javascript which has a recursive function. I would like to use console.profile in order to inspect it, but I can't find exactly how to get the output of the profile session.
I start my session with the following;:
console.profile("sessionName")
But the following doesn't log anything to console on my machine:
console.profileEnd("sessionName");
The following doesn't seem to catch anything either
var d = console.profileEnd("sessionName");
How should it be done?
You should use the Visual Studio 2012 profiler with Debug\Start performance analysis paused, and then unpause it from the point in your program you wish to take a profile.

Allow only one running instance of a program

How can i restrict my program to run only instance? Currently i'm running my program as daemon(starts and stops automatically), and when user clicks and tries to launch again(which is not a valid usecase), process gets launched in user context and i would like to avoid this for many reasons.
How can i achieve this?
As of now i'm getting list of processes and doing some checks and exiting at the begining itself but this method is not clean, though it solves my problem.
can someone give me a better solution?
And i'm using ps to get process list, is there any reliable API to get this done?
Use a named semaphore with count of 1. On startup, check if this semaphore is taken. If it is, quit. Otherwise, take it.
Proof of concept code: (put somewhere near application entry point)
#include <semaphore.h>
...
if (sem_open(<UUID string for my app>, O_CREAT, 600, 1) == SEM_FAILED) {
exit(0);
}
From the sem_open documentation,
The returned semaphore descriptor is available to the calling process until it is closed with sem_close(), or until the caller exits or execs.

Is there a way to get feedback from a process in XUL?

I'm starting to develop an extension which must interact with an external application. I can run the external application as described here, but I do not see a way to get any feedback. The only information I get is the exit status, while I need to read the application output, as it would appear on a terminal (stdout). Is there a way to do this?
After running the nsiProcess, loop while checking the isRunning attribute. When it stops running, check the exitValue attribute. As I understand it, this may behave differently on different platforms, but I did use it successfully on Windows.