PC Review


Reply
Thread Tools Rate Thread

Closing a program

 
 
=?Utf-8?B?TWFya1M=?=
Guest
Posts: n/a
 
      17th Mar 2007
Hi,
I've never done this or seen anything on it, but i works it's simple
1. Test if program is runing
2. If not start program
3. at end of job shut program down

I can start the program using this
Shell ("C:\Program Files\Reuters\kobra\Program\kobra.exe")
But if its already running it start a second instantance and I don't know
how to get it to shut down

Thanks
 
Reply With Quote
 
 
 
 
Steve Yandl
Guest
Posts: n/a
 
      17th Mar 2007
The two subroutines below are examples of one approach. These will not work
on Win95/98 systems unless they've added WMI but they should work fine with
WinXP or Win2K.

The subroutine "RunOneNotepad" checks the list of running processes and
determines if any are named notepad.exe (I don't have kobra.exe so I tested
with notepad.exe which I do have). If none are found, it launches a new
process and documents the process ID ("PID") in cell A1 of Sheet1.

The subroutine "KillSpecificPID" extracts the PID from cell A1 (if there is
one there) and kills the process with that ID if it is still running.

___________________________________

Sub RunOneNotepad()
Dim runningNotepad As Boolean

runningNotepad = False

Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMI.ExecQuery _
("Select * from Win32_Process")

For Each objProcess In colProcess
If objProcess.Name = "NOTEPAD.EXE" Then
runningNotepad = True
End If
Next

If runningNotepad = False Then
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2:Win32_Process")
objWMI.Create "notepad.exe", Null, Null, intProcessID
Sheets(1).Cells(1, 1).Value = intProcessID
End If

runningNotepad = False
Set objWMI = Nothing

End Sub



Sub KillSpecificPID()

intPID = Sheets(1).Cells(1, 1).Value

Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcess = objWMI.ExecQuery _
("Select * from Win32_Process Where ProcessID = " & intPID & "")
For Each objProcess In colProcess
objProcess.Terminate
Next
End Sub



Steve




"MarkS" <(E-Mail Removed)> wrote in message
news:403157B7-5B28-44DC-9CD9-(E-Mail Removed)...
> Hi,
> I've never done this or seen anything on it, but i works it's simple
> 1. Test if program is runing
> 2. If not start program
> 3. at end of job shut program down
>
> I can start the program using this
> Shell ("C:\Program Files\Reuters\kobra\Program\kobra.exe")
> But if its already running it start a second instantance and I don't know
> how to get it to shut down
>
> Thanks



 
Reply With Quote
 
=?Utf-8?B?TWFya1M=?=
Guest
Posts: n/a
 
      19th Mar 2007
Hi,
this works fine, with a couple of obvious changes. A question that occured
to me what are the two null's for in objWMI.Create


"Steve Yandl" wrote:

> The two subroutines below are examples of one approach. These will not work
> on Win95/98 systems unless they've added WMI but they should work fine with
> WinXP or Win2K.
>
> The subroutine "RunOneNotepad" checks the list of running processes and
> determines if any are named notepad.exe (I don't have kobra.exe so I tested
> with notepad.exe which I do have). If none are found, it launches a new
> process and documents the process ID ("PID") in cell A1 of Sheet1.
>
> The subroutine "KillSpecificPID" extracts the PID from cell A1 (if there is
> one there) and kills the process with that ID if it is still running.
>
> ___________________________________
>
> Sub RunOneNotepad()
> Dim runningNotepad As Boolean
>
> runningNotepad = False
>
> Set objWMI = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
> Set colProcess = objWMI.ExecQuery _
> ("Select * from Win32_Process")
>
> For Each objProcess In colProcess
> If objProcess.Name = "NOTEPAD.EXE" Then
> runningNotepad = True
> End If
> Next
>
> If runningNotepad = False Then
> Set objWMI = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\.\root\cimv2:Win32_Process")
> objWMI.Create "notepad.exe", Null, Null, intProcessID
> Sheets(1).Cells(1, 1).Value = intProcessID
> End If
>
> runningNotepad = False
> Set objWMI = Nothing
>
> End Sub
>
>
>
> Sub KillSpecificPID()
>
> intPID = Sheets(1).Cells(1, 1).Value
>
> Set objWMI = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
> Set colProcess = objWMI.ExecQuery _
> ("Select * from Win32_Process Where ProcessID = " & intPID & "")
> For Each objProcess In colProcess
> objProcess.Terminate
> Next
> End Sub
>
>
>
> Steve
>
>
>
>
> "MarkS" <(E-Mail Removed)> wrote in message
> news:403157B7-5B28-44DC-9CD9-(E-Mail Removed)...
> > Hi,
> > I've never done this or seen anything on it, but i works it's simple
> > 1. Test if program is runing
> > 2. If not start program
> > 3. at end of job shut program down
> >
> > I can start the program using this
> > Shell ("C:\Program Files\Reuters\kobra\Program\kobra.exe")
> > But if its already running it start a second instantance and I don't know
> > how to get it to shut down
> >
> > Thanks

>
>
>

 
Reply With Quote
 
Steve Yandl
Guest
Posts: n/a
 
      19th Mar 2007
To be honest, I don't know. They're startup parameters not needed for
anything I've ever done. You may find some info here:
http://msdn2.microsoft.com/en-us/library/aa394375.aspx
if you want to explore.

Steve




"MarkS" <(E-Mail Removed)> wrote in message
news3152B1E-92D1-4383-B708-(E-Mail Removed)...
> Hi,
> this works fine, with a couple of obvious changes. A question that occured
> to me what are the two null's for in objWMI.Create
>
>
> "Steve Yandl" wrote:
>
>> The two subroutines below are examples of one approach. These will not
>> work
>> on Win95/98 systems unless they've added WMI but they should work fine
>> with
>> WinXP or Win2K.
>>
>> The subroutine "RunOneNotepad" checks the list of running processes and
>> determines if any are named notepad.exe (I don't have kobra.exe so I
>> tested
>> with notepad.exe which I do have). If none are found, it launches a new
>> process and documents the process ID ("PID") in cell A1 of Sheet1.
>>
>> The subroutine "KillSpecificPID" extracts the PID from cell A1 (if there
>> is
>> one there) and kills the process with that ID if it is still running.
>>
>> ___________________________________
>>
>> Sub RunOneNotepad()
>> Dim runningNotepad As Boolean
>>
>> runningNotepad = False
>>
>> Set objWMI = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
>> Set colProcess = objWMI.ExecQuery _
>> ("Select * from Win32_Process")
>>
>> For Each objProcess In colProcess
>> If objProcess.Name = "NOTEPAD.EXE" Then
>> runningNotepad = True
>> End If
>> Next
>>
>> If runningNotepad = False Then
>> Set objWMI = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\.\root\cimv2:Win32_Process")
>> objWMI.Create "notepad.exe", Null, Null, intProcessID
>> Sheets(1).Cells(1, 1).Value = intProcessID
>> End If
>>
>> runningNotepad = False
>> Set objWMI = Nothing
>>
>> End Sub
>>
>>
>>
>> Sub KillSpecificPID()
>>
>> intPID = Sheets(1).Cells(1, 1).Value
>>
>> Set objWMI = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
>> Set colProcess = objWMI.ExecQuery _
>> ("Select * from Win32_Process Where ProcessID = " & intPID & "")
>> For Each objProcess In colProcess
>> objProcess.Terminate
>> Next
>> End Sub
>>
>>
>>
>> Steve
>>
>>
>>
>>
>> "MarkS" <(E-Mail Removed)> wrote in message
>> news:403157B7-5B28-44DC-9CD9-(E-Mail Removed)...
>> > Hi,
>> > I've never done this or seen anything on it, but i works it's simple
>> > 1. Test if program is runing
>> > 2. If not start program
>> > 3. at end of job shut program down
>> >
>> > I can start the program using this
>> > Shell ("C:\Program Files\Reuters\kobra\Program\kobra.exe")
>> > But if its already running it start a second instantance and I don't
>> > know
>> > how to get it to shut down
>> >
>> > Thanks

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program Control After Closing Another Program Steve Microsoft Excel Programming 8 9th Sep 2009 06:43 PM
Closing a Doc versus Closing the Program in Word 2007 =?Utf-8?B?RGVsbGE=?= Microsoft Word Document Management 4 6th Jun 2007 04:16 PM
closing down a program =?Utf-8?B?aGVsZW4=?= Windows XP Help 1 7th Aug 2006 09:27 PM
Program Error after closing program, cannot shutdown =?Utf-8?B?R2FyeQ==?= Microsoft Windows 2000 0 13th Sep 2004 10:01 AM
Re: Program Icon Remains on Toolbar After Closing Program Trev Windows XP Basics 0 22nd Sep 2003 08:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:48 AM.