Is there a command to close a running program

Discuss and share scripts and script files...
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Is there a command to close a running program

Post by serendipity »

Huidong wrote:TSKILL defraggler in cmd worked!
But again,
run "cmd /c TSKILL defraggler"
does not work!
where are you trying that command from?
address bar?

PS: are you using :: in front of run?

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Things go weird. I run the command from Scripting - Run Script... on the menu.
I rebooted by machine and once again I can kill notepad with that command. then I run the following:

Code: Select all

"Defrag selected (Recursive)"
  run "cmd /c tskill defraggler";
  open '"D:\Portable\Defraggler\df.exe" <selitems> /S';
Defraggler did not get killed, and df.exe wasn't run either; then I tried the same command to kill notepad, this time, it failed!
Then I rebooted my machine again, and tried to kill notepad, still it failed!
Any clue?

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Also later I changed the line to

Code: Select all

run "cmd /c tskill defraggler", , 1;
But at that time I can't even kill notepad!

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Is there a command to close a running program

Post by serendipity »

Huidong wrote:Things go weird. I run the command from Scripting - Run Script... on the menu.
I rebooted by machine and once again I can kill notepad with that command. then I run the following:

Code: Select all

"Defrag selected (Recursive)"
  run "cmd /c tskill defraggler";
  open '"D:\Portable\Defraggler\df.exe" <selitems> /S';
Defraggler did not get killed, and df.exe wasn't run either; then I tried the same command to kill notepad, this time, it failed!
Then I rebooted my machine again, and tried to kill notepad, still it failed!
Any clue?
Sorry, no idea. Except make sure that before "run" and "open" you have atleast one space.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Yes I have two spaces. I mean this is not a particular problem for defraggler, it's all about running cmd /c tskill thru XY, It worked twice, for both notepad and defraggler! Then the same command stops working! But running cmd.exe alone always work. I guess that's the problem of XY?

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Is there a command to close a running program

Post by nas8e9 »

Huidong wrote:TSKILL defraggler in cmd worked!
But again,
run "cmd /c TSKILL defraggler"
does not work!
I can't get it to work either; Sysinternals pskill (as described above) however does work for me on Windows 7 x64 SP1.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Could you show me how to use pskill, please?

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

I tried

Code: Select all

run "pskill -t defraggler"
in XY, didn't work, but in cmd.exe, it worked. I put pskill in system32.
What's wrong here?

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Is there a command to close a running program

Post by serendipity »

Huidong wrote:Yes I have two spaces. I mean this is not a particular problem for defraggler, it's all about running cmd /c tskill thru XY, It worked twice, for both notepad and defraggler! Then the same command stops working! But running cmd.exe alone always work. I guess that's the problem of XY?
Should have asked earlier, how about:
run (TSKILL defraggler);

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Holy sh*t!!! I finally figured out what was the problem!!! Not about using either cmd or pskill, the nasty, mysterious "bug" is that when the current tab is a folder in a sandbox (using Sandboxie), then neither run "cmd ..." nor run "pskill" works, however, when the current tab is not in a sandboxed folder, as far as I know, any place except in the sandbox, both cmd and pskill work!!! This is mysterious, since I thought running a command from Scripting - Run Script... should not have anything to do with the current tab location! Any clue what's going on?? Ghost!

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Is there a command to close a running program

Post by serendipity »

Huidong wrote:Holy sh*t!!! I finally figured out what was the problem!!! Not about using either cmd or pskill, the nasty, mysterious "bug" is that when the current tab is a folder in a sandbox (using Sandboxie), then neither run "cmd ..." nor run "pskill" works, however, when the current tab is not in a sandboxed folder, as far as I know, any place except in the sandbox, both cmd and pskill work!!! This is mysterious, since I thought running a command from Scripting - Run Script... should not have anything to do with the current tab location! Any clue what's going on?? Ghost!
OK so that's the culprit. when you run:
::run "cmd /c TSKILL defraggler"

it first starts cmd in that folder. you will see if you run cmd with /k instead of /c :
run "cmd /k TSKILL defraggler"

what happens with this?
run "cmd /K cd /d c:\ & TSKILL defraggler";

this will first go to c:\ and then execute the task kill.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Really good news!
run "cmd /K cd /d c:\ & TSKILL defraggler";
did not work, but I did use your command to do sth very handy:

Code: Select all

"Run regedit as SYSTEM"
  run "cmd /k cd /d C:\Windows\System32\ & PsExec -s -i regedit"
Back to the issue, when I run tskill when the current tab is in sandbox, the cmd did open in C:\, but it reports that end process failed because access is denied. Moreover, even when the current tab is out of sandbox, in which case tskill can kill defraggler, but the cmd window remains open so the next command (calling df.exe) can not start. This did not happen using /c.
But thanks very much, learning a lot of things.

Huidong
Posts: 213
Joined: 18 May 2011 21:55

Re: Is there a command to close a running program

Post by Huidong »

Can you explain what /d is for? THanks

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Is there a command to close a running program

Post by nas8e9 »

Huidong wrote:Can you explain what /d is for? THanks
It's a parameter of the cd (change directory) command that makes cd traverse drive boundaries; without it

Code: Select all

cd c:\windows\system32
while the current location is on D:, wouldn't change to C:; when entering just C: however, you would be in \windows\system32. The /d parameter changes the current location as well, i.e. if the current location is on D: you'd end up in C:\Windows\System32 without first having to enter just C:.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Is there a command to close a running program

Post by PeterH »

I don't understand exactly what you mean with "current tab is in sandbox"

But as I understand the function of a sandbox, then it's to disallow changes from inside to the outside - especially killing tasks outside of the sandbox? That is: keep system safe, whatever program in sandbox tries to do...

Post Reply