|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Determining if MS Word is running through VB codeHi, I have an application that will run a method depending on whether
or not there is an instance of MS Word currently open. How do I determine whether or not an executable from another program is running? I am new to VB, but I suspect that this should definitely be 5 lines or less. njuneardave wrote:
> Hi, I have an application that will run a method depending on whether Well... One way with VB.NET would be to use the GetObject method.> or not there is an instance of MS Word currently open. > > How do I determine whether or not an executable from another program is > running? I am new to VB, but I suspect that this should definitely be > 5 lines or less. Word is an automation server - and if it's running GetObject will return a valid reference to it. If word isn't running then GetObject will throw an exception. So, you can actually do this in one line of code: Dim wordObject As Object = GetObject (Class:="Word.Application") -- Tom Shelton Cool, Tom. Thanks!!
I guess I should have used a little less abstraction in this case, though. Using MS Word was a prelim test. I actually want to test for the existence of an executable that I made myself called, "Spectrum.exe". I first opened the application using: System.Diagnostics.Process.Start("Spectrum.exe") Now, later in the code, I need to test if my Spectrum.exe is currently running. Sorry about the abstraction.... I didn't think that it would play a major role =P Anyway, any new tips? Thanks so much for the help! Tom Shelton wrote: Show quoteHide quote > njuneardave wrote: > > Hi, I have an application that will run a method depending on whether > > or not there is an instance of MS Word currently open. > > > > How do I determine whether or not an executable from another program is > > running? I am new to VB, but I suspect that this should definitely be > > 5 lines or less. > > Well... One way with VB.NET would be to use the GetObject method. > Word is an automation server - and if it's running GetObject will > return a valid reference to it. If word isn't running then GetObject > will throw an exception. So, you can actually do this in one line of > code: > > Dim wordObject As Object = GetObject (Class:="Word.Application") > > -- > Tom Shelton njuneardave wrote:
Show quoteHide quote > Cool, Tom. Thanks!! Sure, save the reference to the process that is returned by> > I guess I should have used a little less abstraction in this case, > though. Using MS Word was a prelim test. I actually want to test for > the existence of an executable that I made myself called, > "Spectrum.exe". I first opened the application using: > > System.Diagnostics.Process.Start("Spectrum.exe") > > > Now, later in the code, I need to test if my Spectrum.exe is currently > running. Sorry about the abstraction.... I didn't think that it would > play a major role =P Anyway, any new tips? > > > Thanks so much for the help! Process.Start. Then you can test and see if it is running at anytime... Look at the process classes HasExited property. It is also possible to hook an event handler to the process so that your application get's notified when the process exits. -- Tom Shelton Oh, I like that way better, Tom. Thanks for the advice! I appreciate
you. Tom Shelton wrote: Show quoteHide quote > njuneardave wrote: > > Cool, Tom. Thanks!! > > > > I guess I should have used a little less abstraction in this case, > > though. Using MS Word was a prelim test. I actually want to test for > > the existence of an executable that I made myself called, > > "Spectrum.exe". I first opened the application using: > > > > System.Diagnostics.Process.Start("Spectrum.exe") > > > > > > Now, later in the code, I need to test if my Spectrum.exe is currently > > running. Sorry about the abstraction.... I didn't think that it would > > play a major role =P Anyway, any new tips? > > > > > > Thanks so much for the help! > > Sure, save the reference to the process that is returned by > Process.Start. Then you can test and see if it is running at > anytime... Look at the process classes HasExited property. It is also > possible to hook an event handler to the process so that your > application get's notified when the process exits. > > -- > Tom Shelton
About IDisposable.Dispose()
Inherited Forms in VB.NET class code does not show 'inherits from...' Configuration in published program java developer wants to learn VB.NET Mnemonics for Buttons with symbols on Mail merge from word using sql server express and vb.net 2005 Referencing an Enum with Embedded Spaces Licensing with Plimus Treeview (Eric Moreau) Running and Controling another Application via VB.net Application |
|||||||||||||||||||||||