Suspend windows process with a macro

0

I'm working on a little something and i need to 'simplify' a windows operation and i'm kinda stuck, i don't know if you guys can help me figure it out here.. so here's my problem and how i want it to be solved:

I need to be able to suspend a specific windows process for X seconds at the press of 1 or 2 buttons. Ideally one button to suspend it with a X seconds delay before it resumes, but could be 1 button to suspend it and another 1 to resume it.

What i expect it to be (then agian, could be a little different): create a .exe file and bind the file shortcut to a programmable button on one of my macro button on my keyboard. I need help to figure out a way to code this into something.. i tried to use a tool called pssuspend.exe but i couldn't get it to work.

Thanks for the help !

Pier-Olivier Pellerin

Posted 2017-12-28T13:46:31.693

Reputation: 1

Without too much work and as a basic solution you can create a shortcut file to your pssuspend.exe, then edit the properties of it to add the process name to suspend as a parameter in the "Target" field. You can bind a shortcut key combo and set if it is to run minimised for example. You could do the same again for the resume. Can you suspend the process you have in mind without elevating? – HelpingHand – 2017-12-28T19:32:46.213

Thanks for the reply. But i can't figure out how to edit the properties of this .exe ? any hints ? Also, i'd like it to work while using another full screen application without the need of minimizing it. – Pier-Olivier Pellerin – 2017-12-29T00:27:19.743

You create a shortcut to it and edit the properties of that. – HelpingHand – 2017-12-29T08:39:49.127

Thanks again for the reply sir ! It seems to work when I click on my shortcut, it runs pssuspend with the correct arguments, but the new issue is that when I assign the macro key of my keyboard to this shortcut, it will ignore all arguments and only open the basic file without the custom arguments.. is there a workaround? Is there a way to create some sort of BAT file to help me ? – Pier-Olivier Pellerin – 2017-12-29T12:39:16.670

In that case, what about a little exe wrapper: Download and install AutoIt (https://www.autoitscript.com/site/autoit/). Create a new text file, give it the name "suspend.au3". Add the 3 lines: Run("C:\SysinternalsSuite\pssuspend.exe onedrive", "", @SW_HIDE) Sleep(5000) Run("C:\SysinternalsSuite\pssuspend.exe onedrive -r", "", @SW_HIDE) Adjust the process as required from onedrive above. You can save and then right click and choose "Complie Script (x86)". This will generate you an exe. Adjust it you want to sleep (e.g. 3 secs) and unsuspend, create an exe for each task etc.

– HelpingHand – 2017-12-29T13:04:43.420

I'm curious to know if the AutoIt approach proved more useful for the behaviour you're after? – HelpingHand – 2018-01-01T12:38:11.080

Answers

1

Google search feed for 15 September 2018:

PsSuspend tool from PsTools (Microsoft sysinternals utilities pack)

Since this is some kind official tool, it may be the best choice for simple scripts and automation.

Running PsSuspend with a process ID directs it to suspend or resume the process of that ID on the local computer. If you specify a process name PsSuspend will suspend or resume all processes that have that name. Specify the -r switch to resume suspended processes.

Usage: pssuspend [- ] [-r] [\\computer [-u username] [-p password]] <process name | process id>

Simple program using Windows API: SuspendThread and ReasumeThread

Windows has some functions realated to suspending and reasuming threads (so process some kind alos). The kernel32.dll library provides SuspendThread and ReasumeThread. Warning! There also are 64-bit counterparts for this functions Wow64SuspendThread and Wow64ResumeThread (which doesn't have official documentation).

There is nice, small application that uses that technique also version in C/C++ also on CodeProject (source code available).

Usage: pausep PID [/r] (/r switch reasumes the process).

There is version in C# .NET also on CodeProject.

Also look at this Stackoverflow answer

More user-friendly, command line (Powershell) method from that answer:

As I said Windows command line has not any utility to do that but you can invoke a Windows API function from PowerShell. First install Invoke-WindowsApi script then you can write this:

Invoke-WindowsApi "kernel32" ([bool]) "DebugActiveProcess" @([int]) @(process_id_here)

Similar technique was used to create this PowerScript script created for process pausing.

PsychoX

Posted 2017-12-28T13:46:31.693

Reputation: 111

0

I write this to replace PsSuspend for my use case. (not full PsSusend features are included)

https://github.com/craftwar/suspend

It supports unicode and multiple target processes.
You don't need run PsSuspend multiple times to suspend multiple processes. (It's very slow)

craftwar

Posted 2017-12-28T13:46:31.693

Reputation: 1