How Can AutoClose (Insert Yes) After Start CloseCode By Pid?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

How Can AutoClose (Insert Yes) After Start CloseCode By Pid?

#1 Post by r2du-soft » 07 Jun 2014 05:49

hi
when i close(kill) a process whit this code:


Code: Select all


@echo off &setlocal

set "process=myprocess.exe"

for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq %process%" 2^>nul') do set PID1=%%i
taskkill /pid %PID1% /t



then myprocess.exe show a massage: are you sure you want to quit this application?
this massage have two button: YES No
i need a code for insert this massage yes (OR) i need a code for auto close myprocess.exe and don't show that massage!...
i how cat do this?
thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#2 Post by foxidrive » 07 Jun 2014 06:37

It would seem that your program is generating the message.

One way would be to use the /f switch to force it closed.

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#3 Post by r2du-soft » 07 Jun 2014 06:42

foxidrive wrote:It would seem that your program is generating the message.

One way would be to use the /f switch to force it closed.


thanks foxidrive
i tested this code:

Code: Select all

taskkill /f /pid %PID1% /t


but this still does not work :(

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#4 Post by foxidrive » 07 Jun 2014 07:09

r2du-soft wrote:but this still does not work :(


What did you see on the console window? Add pause on the bottom line to see.

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#5 Post by r2du-soft » 07 Jun 2014 07:41

foxidrive wrote:
r2du-soft wrote:but this still does not work :(


What did you see on the console window? Add pause on the bottom line to see.


i added pause and cmd show me this words:

Code: Select all

ERROR: The process with PID 5608 (child process of PID 4748) could not be terminated.
Reason: Access is denied.
Press any key to continue . . .

I would add this process is for antivirus process and i have close GUI (User Interface) and i do not want create a virus or ... or i do not want use for disable antivirus. :roll:
i just want close GUI.
Last edited by r2du-soft on 07 Jun 2014 07:52, edited 1 time in total.

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#6 Post by Aacini » 07 Jun 2014 07:50

You may try to send a Y key to the keyboard before the taskkill is executed:

Code: Select all

@if (@CodeSection == @Batch) @then

@echo off &setlocal

set "process=myprocess.exe"

for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq %process%" 2^>nul') do set PID1=%%i
cscript //nologo //E:JScript "%~F0"
taskkill /pid %PID1% /t
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys("Y");


Antonio

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#7 Post by r2du-soft » 07 Jun 2014 08:52

Aacini wrote:You may try to send a Y key to the keyboard before the taskkill is executed:

Code: Select all

@if (@CodeSection == @Batch) @then

@echo off &setlocal

set "process=myprocess.exe"

for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq %process%" 2^>nul') do set PID1=%%i
cscript //nologo //E:JScript "%~F0"
taskkill /pid %PID1% /t
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys("Y");


Antonio



not worked (not insert y for close!) :cry:
this code send y but not send to antivirus for close!

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#8 Post by Aacini » 07 Jun 2014 10:18

Perhaps the antivirus flush the keyboard buffer before present the Yes/No message. Try to send the Y key after the antivirus present the message:

Code: Select all

start /B taskkill /pid %PID1% /t
timeout /T 2
cscript //nologo //E:JScript "%~F0"


Antonio

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#9 Post by r2du-soft » 07 Jun 2014 13:27

Aacini wrote:Perhaps the antivirus flush the keyboard buffer before present the Yes/No message. Try to send the Y key after the antivirus present the message:

Code: Select all

start /B taskkill /pid %PID1% /t
timeout /T 2
cscript //nologo //E:JScript "%~F0"


Antonio




thanks

this code worked but have a problem!
when start this code a windows open whit caption"ESET Smart Security" amd massage "Ate you sure you want to quit Eset Smart Security?" Buttons YES No
when start my codes this windows is not activated! and y not sent to this windows for quit,But if i click on this windows and activated that,then y send after 2 Second (timeout /T 2) in this windows and Eset Quit.
I how fix this?
Thank you my friend


Code: Select all

@if (@CodeSection == @Batch) @then

@echo off &setlocal

set "process=egui.exe"

for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq %process%" 2^>nul') do set PID1=%%i
taskkill /pid %PID1% /t
timeout /T 2
cscript //nologo //E:JScript "%~F0"
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys("Y");

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#10 Post by Squashman » 07 Jun 2014 13:44

I would look at using an AutoHotKey script.

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#11 Post by Aacini » 07 Jun 2014 14:04

Ok. We may use JScript's AppActivate method to activate the Eset message window before send the Y.

Code: Select all

@if (@CodeSection == @Batch) @then

@echo off &setlocal

set "process=egui.exe"

for /f "tokens=2" %%i in ('tasklist /nh /fi "imagename eq %process%" 2^>nul') do set PID1=%%i
taskkill /pid %PID1% /t
timeout /T 2
cscript //nologo //E:JScript "%~F0"
goto :EOF

@end

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.AppActivate("ESET Smart Security");
WshShell.SendKeys("Y");


The AppActivate method require the same string on the title bar of the window to activate. If this works, try to eliminate the timeout.

Antonio

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#12 Post by r2du-soft » 07 Jun 2014 15:05

Thanks foxidrive , Squashman , Aacini
my problem solved by you're helps and Aacini helps
thanks my friends

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#13 Post by Aacini » 07 Jun 2014 16:11

@r2du-soft: Excuse me. Does the AppActivate/SendKeys method works? Does it work with no timeout? This type of details will help us in future similar problems. :wink:

Antonio

r2du-soft
Posts: 68
Joined: 09 Sep 2011 12:13

Re: How Can AutoClose (Insert Yes) After Start CloseCode By

#14 Post by r2du-soft » 07 Jun 2014 17:06

Aacini wrote:@r2du-soft: Excuse me. Does the AppActivate/SendKeys method works? Does it work with no timeout? This type of details will help us in future similar problems. :wink:

Antonio


Yes i tested AppActivate/SendKeys and that's good work and close process by pid and insert y(yes) in that massage :)
peradventure i tested codes with remove timeout,Again code good work and can (insert y(yes) in that massage and) close Eset GUI

i must be added: we just can with this code close/kill Eset GUI and not close/kill Eset Basic/parent process :)

I really thank you for all helps

Post Reply