用名称查找过程 [英] Find Process With The Name

查看:67
本文介绍了用名称查找过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码打开Word文档

I''m Opening Word Document With This Code

Dim missing As Object = System.Reflection.Missing.Value
Dim fileName As Object = "c:\a.doc"
Dim newTemplate As Object = False
Dim docType As Object = 0
Dim isVisible As Object = True
Dim WordApp As New Word.ApplicationClass()
Dim aDoc As Word.Document = WordApp.Documents.Add(fileName, newTemplate, docType, isVisible)
        
WordApp.Visible = False  <------*****
aDoc.Activate()
aDoc.PageSetup.TopMargin = 10
aDoc.PageSetup.BottomMargin = 40
WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
WordApp.Selection.Font.Bold = CInt(Word.WdConstants.wdToggle)




我想关闭一些文字处理.
当我使用此代码关闭Word的处理时,我遇到1个问题




I Want to Close Some Word Process .
When i Use This Code To Close Process Of Word I have 1 Problem

Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("WINWORD")
For Each p As Process In pProcess
    p.Kill()
Next



如果我手动打开Word文件
有了该代码,Word文档已关闭,但我只想关闭在运行时使用VbCode创建的Word进程.
请帮我我该怎么办?

[修改:首先,感谢您使用前置标签.但是,在粘贴代码时必须谨慎对待它们.有时,它会将其识别为代码,并在其中为您放置pre标签.因此,如果您已经将它们放入,然后粘贴代码,则会得到两个pre标签,它们会破坏格式.]

在工作结束时,我使用了此
WordApp.Close()或aDoc.Close()
但是我用WebBrowser打开了Word文件,想关闭一些Word程序,但是我不知道该怎么找到?

请注意
WordApp.Visible = False
而且我无法正常关闭它.
我必须使用Kill Process将其关闭.



If i Opened Word File Manualy
With That Code All Off Word Document Is Closed But I Want To Closed Only Word Process That Create With VbCode In RunTime.
Please Help Me That What Am i Must To Do?

[Modified: First, thank you for using pre tags. But, you have to be careful with them when you paste code in. Sometimes, it recognizes it as code and places the pre tags there for you. So, if you''ve already put them in, and then paste code, you get two pre tags, which screws up the formatting]

At End Of My Work I Used This
WordApp.Close() or aDoc.Close()
But I Open That Word File With WebBrowser And Want To Close Some Word Process But I Don''t Know How Can I Find ?

Please Attention To That
WordApp.Visible = False
And I Can''t To Close It Normaly.
I must Close It With Kill Process.

推荐答案

WordApp.Close()aDoc.Close()(我相信这是第一个,但您可以尝试两者).您不应该终止该过程.自创建应用程序以来,您还拥有处理程序,并且它具有自己的close方法.
WordApp.Close() or aDoc.Close() (I believe it''s the first one, but you could try both). You shouldn''t kill the process. Since you created the application, you also have the handler to it and it has its own close method.


我认为您需要用于.Net的Office SDK.我对此一无所知,但是有了它,您就可以关闭单个文档(如果这就是您的意思).

Google是您的朋友.
I think you need the Office SDK for .Net. I don''t know anything about it, but with it, you may be able to close single documents (if that''s what you meant).

Google is your friend.


当您的应用程序启动Word应用程序时,您可以获得流程ID吗?如果是这样,则可以按名称和ID查找该进程,以确保终止所需的进程.如果我有一点时间来模拟某些东西,我会发布一些代码.

找到了...
http://stackoverflow.com/questions/814936/get-pid-from-word-applicationclass [^ ]
When your application starts the Word application can you get the proccess Id? If so then you can look for the process by name and Id to ensure that you kill the process you want. I''ll post some code if I get a little time to mock something up.

Found this...
http://stackoverflow.com/questions/814936/get-pid-from-word-applicationclass[^]


这篇关于用名称查找过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆