As far as I know, the only way to get to this information is through P/Invoke calls to NtQuerySystemIn formation. Most of the API required to perform this task is only loosely documented, so good luck!
There is an excellent discussion here that may help you achieve what you want.
However, killing off a process that has an open file handle is obviously not a recommended practice. Depending on what is being done with the file at the time your possibly risking corruption. If there is any other way to achieve what you want, I'd probably do that instead.
I have a word to text file conversion program that uses an instance of word and there might be other instances running as well. My app needs to recreate the process if someone cancels it or cancel the one its using (and none others) on exit. My solution was to get 2 lists of the word instances that are running, 1 before I create the new instance and 1 after. I then compare the 2 lists to get the new process id and store it in a global so i know which one to kill it later. If someone knows a cleaner way please tell.
I was trying ctype(oword,app lication).exit( ) and it didn't work.
private WordProcessID as int32
private oWord As object
....
private sub CreateWordProce ss()
Dim preExistingProc ess As Boolean
If Me.WordProcessI D > 0 Then
Try
Dim pr As Process = Process.GetProc essById(WordPro cessID)
If pr.Responding = False Then
pr.Kill()
oWord = Nothing
End If
Catch ex As Exception
oWord = Nothing
End Try
End If
If oWord Is Nothing Then
Dim plist1 As Process() = Process.GetProc essesByName("WI NWORD")
oWord = CreateObject("W ord.Application ")
Dim plist2 As Process() = Process.GetProc essesByName("WI NWORD")
For Each p2 As Process In plist2
preExistingProc ess = False
For Each p1 As Process In plist1
If p1.Id = p2.Id Then
preExistingProc ess = True
Exit For
End If
Next
If preExistingProc ess = False Then
Me.WordProcessI D = p2.Id
Exit For
End If
Next p2
End
end sub
Private Sub KillWordProcess ()
If WordProcessID > 0 Then
oWord = Nothing
Process.GetProc essById(WordPro cessID).Kill()
End If
End Sub
I would break it up then, not sure on vb syntax
[code=vb.net]
declare myword as Word._Applicati on
myword= CType(oWord, Word._Applicati on)
[/code]
Actually I guess you could set a breakpoint and see what the object type of oWord is.
Then cast it to its correct type, then perform some actions on that type like Quit() or something else?
Comment