closing programs in dos

  1. #1
    kathy32181 is offline Newbie

    closing programs in dos

    Hi, I'm using Dos to call some other programs and some excel macros. The macros I call open other programs, but I can't close them, so i figured i would close the programs through dos. i know that shell will open and close .exe programs if the program has a course of action that has a beginning and an end, but if i open outlook for instance, it never 'finishes' and stays open until i close it manually. how do i close these neverending programs? thanks!

    Kate


  2. #2
    HippyWarlock is offline Elite Member
    What DOS ver have you got?

    DOCUMENT:Q145701 24-AUG-1998 [vbwin]
    TITLE:HOWTO: Close Shelled Process When Finished under Windows 95/98

    To force Windows 95 or Windows 98 to close the MS-DOS window you can use the Visual Basic Shell function with the /C option of COMMAND.COM.

    The /C option of COMMAND.COM will close the MS-DOS window under Windows 95 or Windows 98. The Visual Basic syntax for using the /C option of COMMAND.COM to execute a MS-DOS program is as follows where <pathname> is the path and name of the program to execute and any command line options for it:

    h = Shell("COMMAND.COM /C <pathname>")

    Windows 3.1, Windows for Workgroups 3.11, and Windows NT 3.51 will still
    behave the same if you use the /C option of COMMAND.COM. So, you can use
    this technique without having to check which operating system the program
    is running on.

  3. #3
    kathy32181 is offline Newbie
    Hi Hippy, thanks for responding.
    sorry, i didn't make myself clear: i don't want to close the DOS window, i want to close the programs that I've opened, and not only the ones i opened with the shell function. so, for example, i open outlook in vba, during a macro that i call through dos. in the same batch file, i want to close outlook through dos when i'm done. let me know if you have any questions. thanks again!

    Kate

    i'm using windows 2000
    Version 5.00.2195

  4. #4
    HippyWarlock is offline Elite Member
    You may have a problem - ME DOS and upwards aren't real DOS and lost some of there rug pulling powers.

    I'll look into it, but remind me - bit busy with my keeping my forum stable at the mo (not this one btw)

  5. #5
    kathy32181 is offline Newbie
    great, thanks again, hippy!

  6. #6
    warrocky is offline Newbie
    Damm , I have the same problem and I can't find the answer anywhere , I just subscribed to this forum just hoping that someone knew but noone seems to ever had that problem .

    warrocky

  7. #7
    jephree is offline ¨*·.¸ «.·°·..·°·.» ¸.·*¨
    Found this DOS Resource. Don't know if it is what you were looking for, but thought it might be.

    http://www.geocities.com/SiliconVall...2/dos62ref.zip

    Excerpt:

    BREAK

    Sets or clears extended CTRL+C checking. You can use this command at the
    command prompt or in your CONFIG.SYS file.

    You can press CTRL+C to stop a program or an activity (file sorting, for
    example). Typically, MS-DOS checks for CTRL+C only while it reads from the
    keyboard or writes to the screen or a printer. If you set BREAK to ON, you
    extend CTRL+C checking to other functions, such as disk read and write
    operations.

    Syntax

    BREAK [ON|OFF]

    To display the current BREAK setting, use the following syntax:

    BREAK

    In your CONFIG.SYS file, use the following syntax:

    BREAK=ON|OFF

    Parameter

    ON|OFF
    Turns extended CTRL+C checking on or off.


    The default setting for BREAK is OFF. You can include the BREAK command in
    your CONFIG.SYS file to enable extended CTRL+C checking every time you start
    your system.


    To specify that MS-DOS is to check for CTRL+C only while it is reading from
    the keyboard or writing to the screen or printer, type the following
    command:

    break off

    To specify that MS-DOS is to check for CTRL+C while it is reading from a
    disk or the keyboard or writing to a disk or the screen, type the following
    command:

    break on

    To turn on this extended CTRL+C checking every time you start your system,
    include the following command in your CONFIG.SYS file:

    break=on

  8. #8
    BigT is offline Valued Member
    To execute a Windows program from a DOS prompt use the "Start" command. i.e. to start Outlook type or put in a batch file "start outlook.exe"

    To stop one form DOS is much more difficult. By using the start command, the batch file will fire up the application you want but then continue running the batch file to its conclusion. Also there is not a command to stop a program from DOS anyway. For example say you have two instances of Excel, how would the simple batch file know which instance to stop? Every process (i.e. App running) has a PID that identifies it but you need some very advanced scripting to be able to control that from the command line. You'd be better off writing a console app if you have VB or else Microsoft's Services For Unix (SFU) might have the sort of scripting options you're looking for. http://www.microsoft.com/windows/sfu...ds/default.asp Although it is meant for cross platform integration, it allows you to use UNIX's advanced scripting capabilities and tools (such as Bash and Vi) on a Windows box

  9. #9
    warrocky is offline Newbie
    Well , I'm not sure about the break command , but I think it only works for batch processes. And even if it was to stop all operations I could use shutdown -f , still , using the PID seems the best choice , the problem is how.


    warrocky

  10. #10
    Here, this might help:

    Depending on the version of windows that you use, the program you want is either kill.exe or taskkill.exe. Both are in the %windir%\system32 or %windir%\system folders, so you should be in the path.


    kill.exe /?
    or
    taskkill.exe /?

    TASKKILL [/S system [/U username [/P [password]]]]
    { [/FI filter] [/PID processid | /IM imagename] } [/F] [/T]

    Description:
    This command line tool can be used to end one or more processes.
    Processes can be killed by the process id or image name.

    Parameter List:
    /S system Specifies the remote system to connect to.

    /U [domain\]user Specifies the user context under which
    the command should execute.

    /P [password] Specifies the password for the given
    user context. Prompts for input if omitted.

    /F Specifies to forcefully terminate
    process(es).

    /FI filter Displays a set of tasks that match a
    given criteria specified by the filter.

    /PID process id Specifies the PID of the process that
    has to be terminated.

    /IM image name Specifies the image name of the process
    that has to be terminated. Wildcard '*'
    can be used to specify all image names.

    /T Tree kill: terminates the specified process
    and any child processes which were started by it.

    /? Displays this help/usage.

    Filters:
    Filter Name Valid Operators Valid Value(s)
    ----------- --------------- --------------
    STATUS eq, ne RUNNING | NOT RESPONDING
    IMAGENAME eq, ne Image name
    PID eq, ne, gt, lt, ge, le PID value
    SESSION eq, ne, gt, lt, ge, le Session number.
    CPUTIME eq, ne, gt, lt, ge, le CPU time in the format
    of hh:mm:ss.
    hh - hours,
    mm - minutes, ss - seconds
    MEMUSAGE eq, ne, gt, lt, ge, le Memory usage in KB
    USERNAME eq, ne User name in [domain\]user
    format
    MODULES eq, ne DLL name
    SERVICES eq, ne Service name
    WINDOWTITLE eq, ne Window title

    NOTE: Wildcard '*' for the /IM switch is accepted only with filters.

    NOTE: Termination of remote processes will always be done forcefully
    irrespective of whether /F option is specified or not.

    Examples:
    TASKKILL /S system /F /IM notepad.exe /T
    TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
    TASKKILL /F /IM notepad.exe /IM mspaint.exe
    TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
    TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
    TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
    TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"

+ Reply to Thread
Page 1 of 2 1 2 LastLast