Page 1 of 1

Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 12:31
by BrentNewland
I'm having some real problems trying to run pskill.

What I'm trying to do is kill every process on the computer that comes from chrome.exe in a certain folder. I don't want to kill every chrome.exe process, because the one I am targeting is a portable copy.

Batch for testing this code: http://pastebin.com/14zrbyvq

Full batch: http://pastebin.com/cMH6BGEH (starting at line 672)

When I execute, it gives me the usage for pskill. The same exact command echoed shows fine and can be copied and pasted and will work fine.

When I turn echo on, I get some strange output, including some commands being truncated (ECHO being output as HO, for example).

If using the first batch file, set TKCHROME2 to any executable (such as c:\windows\notepad.exe) and open that executable.
Download PSTools from https://technet.microsoft.com/en-us/sys ... tools.aspx and put pskill.exe somewhere the batch can find it.

Tearing my hair out over this one, everything seems to be correct, but clearly something is being changed.

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 13:07
by aGerman
Just to make sure ...
What's the name of your batch file?
Do you have any files in the working directory that have the same name as any of the used commands?

Steffen

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 13:22
by BrentNewland
The first batch file I posted is named "t2.cmd".

The second is "bootstrap-new.cmd"

I've moved all other files to a subfolder, right now the folder with the script has (besides those two batch files):
msvc.txt
php.txt
scratch2.txt
chrome profile.7z
FOLDER chrome
FOLDER misc

The tools folder has:
nircmdc.exe
pskill.exe
sha1.exe
wget.exe

The most foolproof way to reproduce the problem is to run the second batch file, Extract pstools.zip (as mentioned in first post) to %temp%\toolkit\tools, then enter option 1 in the batch script to "Kill Chromium and relaunch".

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 13:48
by SIMMS7400
I had a similar issues; provide the FULL path to PsKill.exe and try again.

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 13:57
by aGerman
Also try CALLing the quoted path.

Code: Select all

call "%TK%\tools\pskill.exe" -t -nobanner %%F


Steffen

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 14:01
by BrentNewland

Code: Select all

SET TK=%temp%\toolkit
"%TK%\tools\pskill.exe" -t -nobanner %%F


I've already got it set to use a full path. I can copy the echoed command from the command prompt, repaste it, and it runs fine.

Adding "call " before the command did the trick. I wish I knew why that worked...

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 14:10
by aGerman
BrentNewland wrote:I wish I knew why that worked...

So do I :lol:
I had that issue (with other tools) several times before. So it was just out of my experiences.
FWIW Since your path doesn't contain any spaces it will probably work without CALL if you remove the quotation marks.

Steffen

Re: Issue with running Sysinternals PSKill from a batch file

Posted: 21 Sep 2016 14:17
by BrentNewland
I had tried it with and without quotes. I'm trying to make it accommodating towards different environments. I've got it working well on XP through 7 so far.