Page 1 of 1

deactivate the windows close button - X

Posted: 16 Aug 2011 06:38
by kouliscon
Hello all

i am running a script with the command of ROBOCOPY in order to do backups every time the user logs on and logs of from the workstation.

The users though press the windows command prompt X button and they close the window before the script finish its job.

Anybody can help with the following:

1) the X button to be deactivated.
2) in order for me to have the ability to close if needed (in some cases i need to close it fast) maybe to have a combination of keys like Ctrl + B or something?

thx in advance

Re: deactivate the windows close button - X

Posted: 16 Aug 2011 12:58
by Ed Dyreen
'
You can make a window not to respond to user input by setting it inactive, google CMDOW.EXE

Code: Select all

CMDOW @ /ina
I could be mistaken, maybe it's another CMDOW switch !

But you will also loose the ability to input anything, including a ctrl+break ! That's a problem :?
You would need to run another script that performs a WinClose ( $title, $text ) or ProcessClose ( $PID )

Re: deactivate the windows close button - X

Posted: 16 Aug 2011 23:38
by kouliscon
Hello Ed Dyreen

thx for the reply with the cmdow.exe.

About the script which you mention for the winclose do you know any, or any idea for code?

thx

Re: deactivate the windows close button - X

Posted: 17 Aug 2011 00:05
by Ed Dyreen
'
It depends, it's possible in batch but not very efficient

Code: Select all

TaskList.EXE /nh |FindStr.EXE /i /b /c:"*********"
>nul 2>&1 taskKill /t /f /im "*********"
Some of my base functions, an idea for the code

Code: Select all

:WinWaitOpen ( /Title: "STRING" /File: "STRING" /Timeout: "STRING" )
::
:: SJAB v1.142z beta
::
:: Will pause script execution until a window named @Title exists.
::
::INPUT:
:: @Title    STRING       Required;    @Title of window to query
:: @File    STRING       Optional;    @File of window to query
:: @Timeout    STRING       Optional;    Continiue script execution after @Timeout secs
::
::OUTPUT:
:: $error    Return;    0 for succes, 1 for timeout
::
SetLocal &%@forTS% ( "!Sub.%Sub.Depth%.Name!" ) %@TraceIn%
::(
   rem %@Debug_onFunction%
   ::(
      %@Debug% "" "inside !$Trace! Sub.!Sub.Depth!.Par.AsIS:" &echo.!Sub.%Sub.Depth%.Par.AsIS!_
      set "Sub.!Sub.Depth!.Use=:WinWaitOpen ( /Title: "STRING" /File: "STRING" /Timeout: "STRING" )"
   ::)

   %@DequEcho% PROC PAR
   ::(
      set "Par.FIX=Title File Timeout"
      %§PROC.PAR.FAST% "()"
   ::)
   %@Dequ% for %%! in ( Title File Timeout ) do echo.%%~!=!%%~!!_

   %@DequEcho% Valid
   ::(
      for %%! in ( Title ) do %ERR.Chk.IsDefined.TokenSTR% %()% >nul
      ::
      for %%! in (

         File

      ) do    if defined %%~! (
         ::
         set "%%~!=!%%~!:~0,25!"

      ) else    set "%%~!=*.*"
      ::
      for %%! in (

         Timeout

      ) do    if defined %%~! %§Digit.IsDigit.FAST% "!%%~!!" /Int_ERR
   ::)
   %@Dequ% for %%! in ( Title File Timeout ) do echo.%%~!=!%%~!!_

   %@DequEcho% Perform
   ::(
      ::%@Dequ% tasklist /nh /fi "WindowTitle eq !Title!" &%@Pause%
      ::(
         set "RULE=2>nul tasklist /nh /fi "WindowTitle eq !Title!" |>nul findstr.EXE /i /c:"%File%" ||"
         ::
         %§LOOPIf% /Eval: RULE /Timeout: "!Timeout!"
      ::)
   ::)
::)
%@Debug% /Pause "" "$error=!$error!" " outside !Sub.%Sub.Depth%.Name!"
(
   EndLocal

   set /a $error=%$error%
   exit /b %$error%
)

:WinWaitClose ( /Title: "STRING" /File: "STRING" )
::
:: SJAB v1.142z beta
::
:: Will pause script execution until a window named @Title does not exists.
::
::INPUT:
:: @Title    STRING       Required;    @Title of window to query
:: @File    STRING       Optional;    @File of window to query
::
SetLocal &%@forTS% ( "!Sub.%Sub.Depth%.Name!" ) %@TraceIn%
::(
   rem %@Debug_onFunction%
   ::(
      %@Debug% "" "inside !$Trace! Sub.!Sub.Depth!.Par.AsIS:" &echo.!Sub.%Sub.Depth%.Par.AsIS!_
      set "Sub.!Sub.Depth!.Use=:WinWaitClose ( /Title: "STRING" /File: "STRING" )"
   ::)

   %@DequEcho% PROC PAR
   ::(
      set "Par.FIX=Title File"
      %§PROC.PAR.FAST% "()"
   ::)
   %@Dequ% %@echon% &for %%! in ( Title File ) do echo.%%~!=!%%~!!_

   %@DequEcho% VALID
   ::(
      for %%! in ( Title ) do %ERR.Chk.IsDefined.TokenSTR% %()% >nul
   ::)
   %@Dequ% %@echon% &for %%! in ( Title File ) do echo.%%~!=!%%~!!_

   %@DequEcho% Perform
   ::(
      if defined File (
         ::
         set "RULE=2>nul tasklist /nh /fi "WindowTitle eq !Title!" |>nul findstr.EXE /i /c:"%File%" &&"

      ) else    set "RULE=2>nul tasklist /nh /fi "WindowTitle eq !Title!" |>nul findstr.EXE /i /c:"*.*" &&"
      ::
      %§LOOPIf% /Eval: RULE
   ::)
::)
%@DequEcho% outside !Sub.%Sub.Depth%.Name! &%@Pause%
(
   EndLocal

   exit /b %$error%
)

:ProcessClose ( /Title: "STRING" /File: "STRING" )
::
:: SJAB v1.142z beta
::
:: Will close any window named @Title.
::
::INPUT:
:: @Title    STRING    Required;    @Title of window to query
:: @File    STRING    Optional;    additional @File restraint
::
SetLocal &%@forTS% ( "!Sub.%Sub.Depth%.Name!" ) %@TraceIn%
::(
   rem %@Debug_onFunction%
   ::(
      %@Debug% "" "inside !$Trace! Sub.!Sub.Depth!.Par.AsIS:" &echo.!Sub.%Sub.Depth%.Par.AsIS!_
      set "Sub.!Sub.Depth!.Use=:ProcessClose ( /Title: "STRING" /File: "STRING" )"
   ::)

   %@DequEcho% PROC PAR
   ::(
      set "Par.FIX=Title File"
      %§PROC.PAR.FAST% "()"
   ::)
   %@Dequ% for %%! in ( Title File ) do echo.%%~!=!%%~!!_

   %@DequEcho% VALID
   ::(
      for %%! in ( Title ) do %ERR.Chk.IsDefined.TokenSTR% %()% >nul

      if defined File (
         ::
         set "FetchFile=!File!"

      ) else    set "FetchFile=*"
   ::)
   %@Dequ% for %%! in ( Title FetchFile ) do echo.%%~!=!%%~!!_

   %@DequEcho% Perform
   ::(
      for %%! in (

         "!Title!"

      ) do (
         set "?=%%~!"
         ::
         set "?=!?:~0,25!"
      )

      ::%@Dequ% echo. taskKill.EXE /t /f /im "!FetchFile!" /fi "WINDOWTITLE eq !?!*" &%@Pause%
      ::(
         >nul 2>&1 taskKill.EXE /t /f /im "!FetchFile!" /fi "WINDOWTITLE eq !?!*"
      ::)
   ::)
::)
%@DequEcho% outside !Sub.%Sub.Depth%.Name! &%@Pause%
(
   EndLocal

   exit /b %$error%
)