HTFC Forums

H.T.F.C.

How To Fix Computers





Go Back   HTFC Forums > Software Newsgroups > Windows XP

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2007, 11:00 PM
116
 
Posts: n/a
Default Closing a program with script...

I am looking for some assistance in locating who to or perhaps some sample
script for closing a running program. I am having difficulty with people
shutting down app's when they go home for the evening. Perhaps something
that I can Task Schedule to run every evening.

Thanks
David
Reply With Quote
Sponsored Links
  #2  
Old 08-18-2007, 04:32 AM
Gary S. Terhune
 
Posts: n/a
Default Re: Closing a program with script...

What apps? Oddly enough, while it's easy to run an app using a VB script, I
find no method to easily exit an app. But here's one example of a kludge
that will work for some apps. Using calculator as an example (calc needs to
already be open):

dim WshShell
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "calculator"
WshShell.SendKeys "%{f4}"
WScript.Quit

Problem is, to identify the application and activate it requires the name of
the app as it appears in the title bar, or the Process ID. I'm not sure how
to obtain a Process ID, but that's what you'd want. Using the title of the
app is not useful in many cases, because it varies. For example, while the
title bar for Calculator is always the same, apps like Word and IE list the
open document's name, followed by the app's name, like this: "My Test
Document - Microsoft Word".

I'm curious: Why it's important that the apps be closed in the first place.

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"116" <116@discussions.microsoft.com> wrote in message
news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>I am looking for some assistance in locating who to or perhaps some sample
> script for closing a running program. I am having difficulty with people
> shutting down app's when they go home for the evening. Perhaps something
> that I can Task Schedule to run every evening.
>
> Thanks
> David



Reply With Quote
  #3  
Old 08-18-2007, 04:38 PM
116
 
Posts: n/a
Default Re: Closing a program with script...

Thanks for the assist. I will give this a try. Reason being, there certain
DB utilities I run on a weekly basis. And with users still login into the DB
I have to go to each work station, or remote in to log them out.

"Gary S. Terhune" wrote:

> What apps? Oddly enough, while it's easy to run an app using a VB script, I
> find no method to easily exit an app. But here's one example of a kludge
> that will work for some apps. Using calculator as an example (calc needs to
> already be open):
>
> dim WshShell
> set WshShell = WScript.CreateObject("WScript.Shell")
> WshShell.AppActivate "calculator"
> WshShell.SendKeys "%{f4}"
> WScript.Quit
>
> Problem is, to identify the application and activate it requires the name of
> the app as it appears in the title bar, or the Process ID. I'm not sure how
> to obtain a Process ID, but that's what you'd want. Using the title of the
> app is not useful in many cases, because it varies. For example, while the
> title bar for Calculator is always the same, apps like Word and IE list the
> open document's name, followed by the app's name, like this: "My Test
> Document - Microsoft Word".
>
> I'm curious: Why it's important that the apps be closed in the first place.
>
> --
> Gary S. Terhune
> MS-MVP Shell/User
> www.grystmill.com
>
> "116" <116@discussions.microsoft.com> wrote in message
> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
> >I am looking for some assistance in locating who to or perhaps some sample
> > script for closing a running program. I am having difficulty with people
> > shutting down app's when they go home for the evening. Perhaps something
> > that I can Task Schedule to run every evening.
> >
> > Thanks
> > David

>
>
>

Reply With Quote
  #4  
Old 08-18-2007, 05:51 PM
Pegasus \(MVP\)
 
Posts: n/a
Default Re: Closing a program with script...

You can obtain the process ID of an active task, e.g. for
Firefox, with this command:
for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a

Here is the script equivalent:
Option Explicit
Const App = "FIREFOX"
Dim ObjWshShell, ObjExec
Dim ComSpec, SystemRoot, line

Set ObjWshShell = WScript.CreateObject("WScript.Shell")
ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")

Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")

line = ObjExec.StdOut.ReadLine
line = ObjExec.StdOut.ReadLine
While Len(line) > 0
If InStr(UCase(line), App) > 0 Then
line=LTrim(Right(line, Len(line) - InStr(line," ")))
WScript.Echo("Process ID for """ & App & """ is " &
Left(line,InStr(line," ")))
End If
line = ObjExec.StdOut.ReadLine
Wend


http://www.stadt-solothurn.ch/de/akt...&info_id=54610
"Gary S. Terhune" <none> wrote in message
news:emtBqhU4HHA.600@TK2MSFTNGP05.phx.gbl...
> What apps? Oddly enough, while it's easy to run an app using a VB script,
> I find no method to easily exit an app. But here's one example of a kludge
> that will work for some apps. Using calculator as an example (calc needs
> to already be open):
>
> dim WshShell
> set WshShell = WScript.CreateObject("WScript.Shell")
> WshShell.AppActivate "calculator"
> WshShell.SendKeys "%{f4}"
> WScript.Quit
>
> Problem is, to identify the application and activate it requires the name
> of the app as it appears in the title bar, or the Process ID. I'm not sure
> how to obtain a Process ID, but that's what you'd want. Using the title of
> the app is not useful in many cases, because it varies. For example, while
> the title bar for Calculator is always the same, apps like Word and IE
> list the open document's name, followed by the app's name, like this: "My
> Test Document - Microsoft Word".
>
> I'm curious: Why it's important that the apps be closed in the first
> place.
>
> --
> Gary S. Terhune
> MS-MVP Shell/User
> www.grystmill.com
>
> "116" <116@discussions.microsoft.com> wrote in message
> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>>I am looking for some assistance in locating who to or perhaps some sample
>> script for closing a running program. I am having difficulty with people
>> shutting down app's when they go home for the evening. Perhaps something
>> that I can Task Schedule to run every evening.
>>
>> Thanks
>> David

>
>



Reply With Quote
  #5  
Old 08-18-2007, 07:29 PM
Gary S. Terhune
 
Posts: n/a
Default Re: Closing a program with script...

You'll find this reference handy:
http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"116" <116@discussions.microsoft.com> wrote in message
news:59AA4BD3-6BF9-49DD-96F0-B3E9837FF97A@microsoft.com...
> Thanks for the assist. I will give this a try. Reason being, there
> certain
> DB utilities I run on a weekly basis. And with users still login into the
> DB
> I have to go to each work station, or remote in to log them out.
>
> "Gary S. Terhune" wrote:
>
>> What apps? Oddly enough, while it's easy to run an app using a VB script,
>> I
>> find no method to easily exit an app. But here's one example of a kludge
>> that will work for some apps. Using calculator as an example (calc needs
>> to
>> already be open):
>>
>> dim WshShell
>> set WshShell = WScript.CreateObject("WScript.Shell")
>> WshShell.AppActivate "calculator"
>> WshShell.SendKeys "%{f4}"
>> WScript.Quit
>>
>> Problem is, to identify the application and activate it requires the name
>> of
>> the app as it appears in the title bar, or the Process ID. I'm not sure
>> how
>> to obtain a Process ID, but that's what you'd want. Using the title of
>> the
>> app is not useful in many cases, because it varies. For example, while
>> the
>> title bar for Calculator is always the same, apps like Word and IE list
>> the
>> open document's name, followed by the app's name, like this: "My Test
>> Document - Microsoft Word".
>>
>> I'm curious: Why it's important that the apps be closed in the first
>> place.
>>
>> --
>> Gary S. Terhune
>> MS-MVP Shell/User
>> www.grystmill.com
>>
>> "116" <116@discussions.microsoft.com> wrote in message
>> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>> >I am looking for some assistance in locating who to or perhaps some
>> >sample
>> > script for closing a running program. I am having difficulty with
>> > people
>> > shutting down app's when they go home for the evening. Perhaps
>> > something
>> > that I can Task Schedule to run every evening.
>> >
>> > Thanks
>> > David

>>
>>
>>



Reply With Quote
  #6  
Old 08-18-2007, 08:15 PM
Gary S. Terhune
 
Posts: n/a
Default Re: Closing a program with script...

After fixing the line return problems in the script, engendered by NG
transfer, I can't make it work. I get a command window flashing by, then
nothing. I'm using Calculator as a test, rather than Firefox, which I don't
have installed. Tried it in a command window, also, with no return. Tried
with Calc open and with it closed.

Using the command line in a command window, I get "'Tasklist'" is not a
recognized internal or external command, operable program or batch file."

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:OjM25fb4HHA.1184@TK2MSFTNGP04.phx.gbl...
> You can obtain the process ID of an active task, e.g. for
> Firefox, with this command:
> for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a
>
> Here is the script equivalent:
> Option Explicit
> Const App = "FIREFOX"
> Dim ObjWshShell, ObjExec
> Dim ComSpec, SystemRoot, line
>
> Set ObjWshShell = WScript.CreateObject("WScript.Shell")
> ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")
>
> Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")
>
> line = ObjExec.StdOut.ReadLine
> line = ObjExec.StdOut.ReadLine
> While Len(line) > 0
> If InStr(UCase(line), App) > 0 Then
> line=LTrim(Right(line, Len(line) - InStr(line," ")))
> WScript.Echo("Process ID for """ & App & """ is " &
> Left(line,InStr(line," ")))
> End If
> line = ObjExec.StdOut.ReadLine
> Wend
>
>
> http://www.stadt-solothurn.ch/de/akt...&info_id=54610
> "Gary S. Terhune" <none> wrote in message
> news:emtBqhU4HHA.600@TK2MSFTNGP05.phx.gbl...
>> What apps? Oddly enough, while it's easy to run an app using a VB script,
>> I find no method to easily exit an app. But here's one example of a
>> kludge that will work for some apps. Using calculator as an example (calc
>> needs to already be open):
>>
>> dim WshShell
>> set WshShell = WScript.CreateObject("WScript.Shell")
>> WshShell.AppActivate "calculator"
>> WshShell.SendKeys "%{f4}"
>> WScript.Quit
>>
>> Problem is, to identify the application and activate it requires the name
>> of the app as it appears in the title bar, or the Process ID. I'm not
>> sure how to obtain a Process ID, but that's what you'd want. Using the
>> title of the app is not useful in many cases, because it varies. For
>> example, while the title bar for Calculator is always the same, apps like
>> Word and IE list the open document's name, followed by the app's name,
>> like this: "My Test Document - Microsoft Word".
>>
>> I'm curious: Why it's important that the apps be closed in the first
>> place.
>>
>> --
>> Gary S. Terhune
>> MS-MVP Shell/User
>> www.grystmill.com
>>
>> "116" <116@discussions.microsoft.com> wrote in message
>> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>>>I am looking for some assistance in locating who to or perhaps some
>>>sample
>>> script for closing a running program. I am having difficulty with
>>> people
>>> shutting down app's when they go home for the evening. Perhaps
>>> something
>>> that I can Task Schedule to run every evening.
>>>
>>> Thanks
>>> David

>>
>>

>
>



Reply With Quote
  #7  
Old 08-18-2007, 09:57 PM
Pegasus \(MVP\)
 
Posts: n/a
Default Re: Closing a program with script...

Tasklist.exe is a standard WinXP command. It resides in the
System32 folder. If I had to resolve this issue then I would
perform these steps from a Command Prompt:
- Check if tasklist.exe exists in the System32 folder.
- Invoke it from the Command Prompt.
- Ensure that the path includes the System32 folder.
- Check if the batch file version works.


"Gary S. Terhune" <none> wrote in message
news:O2jEiwc4HHA.4676@TK2MSFTNGP05.phx.gbl...
> After fixing the line return problems in the script, engendered by NG
> transfer, I can't make it work. I get a command window flashing by, then
> nothing. I'm using Calculator as a test, rather than Firefox, which I
> don't have installed. Tried it in a command window, also, with no return.
> Tried with Calc open and with it closed.
>
> Using the command line in a command window, I get "'Tasklist'" is not a
> recognized internal or external command, operable program or batch file."
>
> --
> Gary S. Terhune
> MS-MVP Shell/User
> www.grystmill.com
>
> "Pegasus (MVP)" <I.can@fly.com> wrote in message
> news:OjM25fb4HHA.1184@TK2MSFTNGP04.phx.gbl...
>> You can obtain the process ID of an active task, e.g. for
>> Firefox, with this command:
>> for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a
>>
>> Here is the script equivalent:
>> Option Explicit
>> Const App = "FIREFOX"
>> Dim ObjWshShell, ObjExec
>> Dim ComSpec, SystemRoot, line
>>
>> Set ObjWshShell = WScript.CreateObject("WScript.Shell")
>> ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")
>>
>> Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")
>>
>> line = ObjExec.StdOut.ReadLine
>> line = ObjExec.StdOut.ReadLine
>> While Len(line) > 0
>> If InStr(UCase(line), App) > 0 Then
>> line=LTrim(Right(line, Len(line) - InStr(line," ")))
>> WScript.Echo("Process ID for """ & App & """ is " &
>> Left(line,InStr(line," ")))
>> End If
>> line = ObjExec.StdOut.ReadLine
>> Wend
>>
>>
>> http://www.stadt-solothurn.ch/de/akt...&info_id=54610
>> "Gary S. Terhune" <none> wrote in message
>> news:emtBqhU4HHA.600@TK2MSFTNGP05.phx.gbl...
>>> What apps? Oddly enough, while it's easy to run an app using a VB
>>> script, I find no method to easily exit an app. But here's one example
>>> of a kludge that will work for some apps. Using calculator as an example
>>> (calc needs to already be open):
>>>
>>> dim WshShell
>>> set WshShell = WScript.CreateObject("WScript.Shell")
>>> WshShell.AppActivate "calculator"
>>> WshShell.SendKeys "%{f4}"
>>> WScript.Quit
>>>
>>> Problem is, to identify the application and activate it requires the
>>> name of the app as it appears in the title bar, or the Process ID. I'm
>>> not sure how to obtain a Process ID, but that's what you'd want. Using
>>> the title of the app is not useful in many cases, because it varies. For
>>> example, while the title bar for Calculator is always the same, apps
>>> like Word and IE list the open document's name, followed by the app's
>>> name, like this: "My Test Document - Microsoft Word".
>>>
>>> I'm curious: Why it's important that the apps be closed in the first
>>> place.
>>>
>>> --
>>> Gary S. Terhune
>>> MS-MVP Shell/User
>>> www.grystmill.com
>>>
>>> "116" <116@discussions.microsoft.com> wrote in message
>>> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>>>>I am looking for some assistance in locating who to or perhaps some
>>>>sample
>>>> script for closing a running program. I am having difficulty with
>>>> people
>>>> shutting down app's when they go home for the evening. Perhaps
>>>> something
>>>> that I can Task Schedule to run every evening.
>>>>
>>>> Thanks
>>>> David
>>>
>>>

>>
>>

>
>



Reply With Quote
  #8  
Old 08-18-2007, 10:17 PM
Gary S. Terhune
 
Posts: n/a
Default Re: Closing a program with script...

Doh... There's the problem. TASKLIST.EXE doesn't exist on this system,
anywhere. Weird. But then again neither do this user's TIF index.dat or
History index.dat files (referring to another thread), but part of that may
be because when I set it up, I changed the TIF directory to a different
partition. (It's my wife's business machine and I don't dare mess with it
too much now.)

Guess I'll have to wait till I get back to my own machines to get any
****her.

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:eNcYkpd4HHA.1188@TK2MSFTNGP04.phx.gbl...
> Tasklist.exe is a standard WinXP command. It resides in the
> System32 folder. If I had to resolve this issue then I would
> perform these steps from a Command Prompt:
> - Check if tasklist.exe exists in the System32 folder.
> - Invoke it from the Command Prompt.
> - Ensure that the path includes the System32 folder.
> - Check if the batch file version works.
>
>
> "Gary S. Terhune" <none> wrote in message
> news:O2jEiwc4HHA.4676@TK2MSFTNGP05.phx.gbl...
>> After fixing the line return problems in the script, engendered by NG
>> transfer, I can't make it work. I get a command window flashing by, then
>> nothing. I'm using Calculator as a test, rather than Firefox, which I
>> don't have installed. Tried it in a command window, also, with no return.
>> Tried with Calc open and with it closed.
>>
>> Using the command line in a command window, I get "'Tasklist'" is not a
>> recognized internal or external command, operable program or batch file."
>>
>> --
>> Gary S. Terhune
>> MS-MVP Shell/User
>> www.grystmill.com
>>
>> "Pegasus (MVP)" <I.can@fly.com> wrote in message
>> news:OjM25fb4HHA.1184@TK2MSFTNGP04.phx.gbl...
>>> You can obtain the process ID of an active task, e.g. for
>>> Firefox, with this command:
>>> for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a
>>>
>>> Here is the script equivalent:
>>> Option Explicit
>>> Const App = "FIREFOX"
>>> Dim ObjWshShell, ObjExec
>>> Dim ComSpec, SystemRoot, line
>>>
>>> Set ObjWshShell = WScript.CreateObject("WScript.Shell")
>>> ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")
>>>
>>> Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")
>>>
>>> line = ObjExec.StdOut.ReadLine
>>> line = ObjExec.StdOut.ReadLine
>>> While Len(line) > 0
>>> If InStr(UCase(line), App) > 0 Then
>>> line=LTrim(Right(line, Len(line) - InStr(line," ")))
>>> WScript.Echo("Process ID for """ & App & """ is " &
>>> Left(line,InStr(line," ")))
>>> End If
>>> line = ObjExec.StdOut.ReadLine
>>> Wend
>>>
>>>
>>> http://www.stadt-solothurn.ch/de/akt...&info_id=54610
>>> "Gary S. Terhune" <none> wrote in message
>>> news:emtBqhU4HHA.600@TK2MSFTNGP05.phx.gbl...
>>>> What apps? Oddly enough, while it's easy to run an app using a VB
>>>> script, I find no method to easily exit an app. But here's one example
>>>> of a kludge that will work for some apps. Using calculator as an
>>>> example (calc needs to already be open):
>>>>
>>>> dim WshShell
>>>> set WshShell = WScript.CreateObject("WScript.Shell")
>>>> WshShell.AppActivate "calculator"
>>>> WshShell.SendKeys "%{f4}"
>>>> WScript.Quit
>>>>
>>>> Problem is, to identify the application and activate it requires the
>>>> name of the app as it appears in the title bar, or the Process ID. I'm
>>>> not sure how to obtain a Process ID, but that's what you'd want. Using
>>>> the title of the app is not useful in many cases, because it varies.
>>>> For example, while the title bar for Calculator is always the same,
>>>> apps like Word and IE list the open document's name, followed by the
>>>> app's name, like this: "My Test Document - Microsoft Word".
>>>>
>>>> I'm curious: Why it's important that the apps be closed in the first
>>>> place.
>>>>
>>>> --
>>>> Gary S. Terhune
>>>> MS-MVP Shell/User
>>>> www.grystmill.com
>>>>
>>>> "116" <116@discussions.microsoft.com> wrote in message
>>>> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>>>>>I am looking for some assistance in locating who to or perhaps some
>>>>>sample
>>>>> script for closing a running program. I am having difficulty with
>>>>> people
>>>>> shutting down app's when they go home for the evening. Perhaps
>>>>> something
>>>>> that I can Task Schedule to run every evening.
>>>>>
>>>>> Thanks
>>>>> David
>>>>
>>>>
>>>
>>>

>>
>>

>
>



Reply With Quote
  #9  
Old 08-18-2007, 10:43 PM
Paul Randall
 
Posts: n/a
Default Re: Closing a program with script...

The command line reference a-z supplied with WXP tells you about
tasklist.exe. On my computer it resides in my system32 folder.

-Paul Randall

"Gary S. Terhune" <none> wrote in message
news:O2jEiwc4HHA.4676@TK2MSFTNGP05.phx.gbl...
> After fixing the line return problems in the script, engendered by NG
> transfer, I can't make it work. I get a command window flashing by, then
> nothing. I'm using Calculator as a test, rather than Firefox, which I
> don't have installed. Tried it in a command window, also, with no return.
> Tried with Calc open and with it closed.
>
> Using the command line in a command window, I get "'Tasklist'" is not a
> recognized internal or external command, operable program or batch file."
>
> --
> Gary S. Terhune
> MS-MVP Shell/User
> www.grystmill.com
>
> "Pegasus (MVP)" <I.can@fly.com> wrote in message
> news:OjM25fb4HHA.1184@TK2MSFTNGP04.phx.gbl...
>> You can obtain the process ID of an active task, e.g. for
>> Firefox, with this command:
>> for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a
>>
>> Here is the script equivalent:
>> Option Explicit
>> Const App = "FIREFOX"
>> Dim ObjWshShell, ObjExec
>> Dim ComSpec, SystemRoot, line
>>
>> Set ObjWshShell = WScript.CreateObject("WScript.Shell")
>> ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")
>>
>> Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")
>>
>> line = ObjExec.StdOut.ReadLine
>> line = ObjExec.StdOut.ReadLine
>> While Len(line) > 0
>> If InStr(UCase(line), App) > 0 Then
>> line=LTrim(Right(line, Len(line) - InStr(line," ")))
>> WScript.Echo("Process ID for """ & App & """ is " &
>> Left(line,InStr(line," ")))
>> End If
>> line = ObjExec.StdOut.ReadLine
>> Wend
>>
>>
>> http://www.stadt-solothurn.ch/de/akt...&info_id=54610
>> "Gary S. Terhune" <none> wrote in message
>> news:emtBqhU4HHA.600@TK2MSFTNGP05.phx.gbl...
>>> What apps? Oddly enough, while it's easy to run an app using a VB
>>> script, I find no method to easily exit an app. But here's one example
>>> of a kludge that will work for some apps. Using calculator as an example
>>> (calc needs to already be open):
>>>
>>> dim WshShell
>>> set WshShell = WScript.CreateObject("WScript.Shell")
>>> WshShell.AppActivate "calculator"
>>> WshShell.SendKeys "%{f4}"
>>> WScript.Quit
>>>
>>> Problem is, to identify the application and activate it requires the
>>> name of the app as it appears in the title bar, or the Process ID. I'm
>>> not sure how to obtain a Process ID, but that's what you'd want. Using
>>> the title of the app is not useful in many cases, because it varies. For
>>> example, while the title bar for Calculator is always the same, apps
>>> like Word and IE list the open document's name, followed by the app's
>>> name, like this: "My Test Document - Microsoft Word".
>>>
>>> I'm curious: Why it's important that the apps be closed in the first
>>> place.
>>>
>>> --
>>> Gary S. Terhune
>>> MS-MVP Shell/User
>>> www.grystmill.com
>>>
>>> "116" <116@discussions.microsoft.com> wrote in message
>>> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>>>>I am looking for some assistance in locating who to or perhaps some
>>>>sample
>>>> script for closing a running program. I am having difficulty with
>>>> people
>>>> shutting down app's when they go home for the evening. Perhaps
>>>> something
>>>> that I can Task Schedule to run every evening.
>>>>
>>>> Thanks
>>>> David
>>>
>>>

>>
>>

>
>



Reply With Quote
  #10  
Old 08-18-2007, 11:52 PM
Gary S. Terhune
 
Posts: n/a
Default Re: Closing a program with script...

Like I said, tasklist doesn't exist on this system. Turns out it's Home
Edition. I'd forgotten about that. SysInternals' Process Explorer gives the
info, but the PID varies for any one app. Assuming Tasklist.exe on the OP's
system, he would have to use your script to return the PID and then use my
SendKeys example to terminate it (or maybe a better method exists.)

Even then, while it works with calc, my experimentation using WinWord for
some reason fails. The app activates, but the SendKeys doesn't work...Odd...
There's also the issue of dealing with any possible prompts for things like
unsaved files...

--
Gary S. Terhune
MS-MVP Shell/User
www.grystmill.com

"Paul Randall" <paulr901@cableone.net> wrote in message
news:uv551Ce4HHA.4400@TK2MSFTNGP06.phx.gbl...
> The command line reference a-z supplied with WXP tells you about
> tasklist.exe. On my computer it resides in my system32 folder.
>
> -Paul Randall
>
> "Gary S. Terhune" <none> wrote in message
> news:O2jEiwc4HHA.4676@TK2MSFTNGP05.phx.gbl...
>> After fixing the line return problems in the script, engendered by NG
>> transfer, I can't make it work. I get a command window flashing by, then
>> nothing. I'm using Calculator as a test, rather than Firefox, which I
>> don't have installed. Tried it in a command window, also, with no return.
>> Tried with Calc open and with it closed.
>>
>> Using the command line in a command window, I get "'Tasklist'" is not a
>> recognized internal or external command, operable program or batch file."
>>
>> --
>> Gary S. Terhune
>> MS-MVP Shell/User
>> www.grystmill.com
>>
>> "Pegasus (MVP)" <I.can@fly.com> wrote in message
>> news:OjM25fb4HHA.1184@TK2MSFTNGP04.phx.gbl...
>>> You can obtain the process ID of an active task, e.g. for
>>> Firefox, with this command:
>>> for /f "tokens=2" %a in ('tasklist ^| find /i "Firefox"') do echo %a
>>>
>>> Here is the script equivalent:
>>> Option Explicit
>>> Const App = "FIREFOX"
>>> Dim ObjWshShell, ObjExec
>>> Dim ComSpec, SystemRoot, line
>>>
>>> Set ObjWshShell = WScript.CreateObject("WScript.Shell")
>>> ComSpec = ObjWshShell.Environment("PROCESS")("ComSpec")
>>>
>>> Set ObjExec = ObjWshShell.Exec(ComSpec & " /c tasklist.exe")
>>>
>>> line = ObjExec.StdOut.ReadLine
>>> line = ObjExec.StdOut.ReadLine
>>> While Len(line) > 0
>>> If InStr(UCase(line), App) > 0 Then
>>> line=LTrim(Right(line, Len(line) - InStr(line," ")))
>>> WScript.Echo("Process ID for """ & App & """ is " &
>>> Left(line,InStr(line," ")))
>>> End If
>>> line = ObjExec.StdOut.ReadLine
>>> Wend
>>>
>>>
>>> http://www.stadt-solothurn.ch/de/akt...&info_id=54610
>>> "Gary S. Terhune" <none> wrote in message
>>> news:emtBqhU4HHA.600@TK2MSFTNGP05.phx.gbl...
>>>> What apps? Oddly enough, while it's easy to run an app using a VB
>>>> script, I find no method to easily exit an app. But here's one example
>>>> of a kludge that will work for some apps. Using calculator as an
>>>> example (calc needs to already be open):
>>>>
>>>> dim WshShell
>>>> set WshShell = WScript.CreateObject("WScript.Shell")
>>>> WshShell.AppActivate "calculator"
>>>> WshShell.SendKeys "%{f4}"
>>>> WScript.Quit
>>>>
>>>> Problem is, to identify the application and activate it requires the
>>>> name of the app as it appears in the title bar, or the Process ID. I'm
>>>> not sure how to obtain a Process ID, but that's what you'd want. Using
>>>> the title of the app is not useful in many cases, because it varies.
>>>> For example, while the title bar for Calculator is always the same,
>>>> apps like Word and IE list the open document's name, followed by the
>>>> app's name, like this: "My Test Document - Microsoft Word".
>>>>
>>>> I'm curious: Why it's important that the apps be closed in the first
>>>> place.
>>>>
>>>> --
>>>> Gary S. Terhune
>>>> MS-MVP Shell/User
>>>> www.grystmill.com
>>>>
>>>> "116" <116@discussions.microsoft.com> wrote in message
>>>> news:4B36897E-3D5E-4FED-8E20-E1ABD840DF51@microsoft.com...
>>>>>I am looking for some assistance in locating who to or perhaps some
>>>>>sample
>>>>> script for closing a running program. I am having difficulty with
>>>>> people
>>>>> shutting down app's when they go home for the evening. Perhaps
>>>>> something
>>>>> that I can Task Schedule to run every evening.
>>>>>
>>>>> Thanks
>>>>> David
>>>>
>>>>
>>>
>>>

>>
>>

>
>



Reply With Quote
Sponsored Links
Fix your Windows Problems - FAST.
FREE Safe Scan Registry Check. Locate & Fix Errors in Minutes!
Reply


Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to stop a running program? DH Windows XP 6 06-08-2007 03:58 PM
Preventing DEP from closing an app/program No Way Windows XP 2 04-25-2007 06:39 PM
Closing a single tab Sololower Windows XP 1 04-19-2007 03:15 PM
Closing a single tab Sololower Windows XP 5 04-19-2007 07:06 AM
Inadvertently closing a program MikieSlats Windows XP 1 04-17-2007 06:38 AM


All times are GMT. The time now is 09:19 AM.


Powered by vBulletin® Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004 - 2007 Web-S-Sense Pty. Ltd. Usenet and forums posts © their respective authors.
Ad Management by RedTyger