Issue with running Sysinternals PSKill from a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Issue with running Sysinternals PSKill from a batch file

#1 Post by BrentNewland » 21 Sep 2016 12:31

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Issue with running Sysinternals PSKill from a batch file

#2 Post by aGerman » 21 Sep 2016 13:07

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

BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Re: Issue with running Sysinternals PSKill from a batch file

#3 Post by BrentNewland » 21 Sep 2016 13:22

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".

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Issue with running Sysinternals PSKill from a batch file

#4 Post by SIMMS7400 » 21 Sep 2016 13:48

I had a similar issues; provide the FULL path to PsKill.exe and try again.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Issue with running Sysinternals PSKill from a batch file

#5 Post by aGerman » 21 Sep 2016 13:57

Also try CALLing the quoted path.

Code: Select all

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


Steffen

BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Re: Issue with running Sysinternals PSKill from a batch file

#6 Post by BrentNewland » 21 Sep 2016 14:01

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...

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Issue with running Sysinternals PSKill from a batch file

#7 Post by aGerman » 21 Sep 2016 14:10

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

BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Re: Issue with running Sysinternals PSKill from a batch file

#8 Post by BrentNewland » 21 Sep 2016 14:17

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.

Post Reply