Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

如何启动和停止exe

From Wiki
Jump to: navigation, search
Article Metadata

文章
dougcn 在 14 Jul 2008 创建
最后由 hamishwillee 在 30 May 2013 编辑

如何启动和停止exe

Contents

启动一个exe

Symbian 8及更早版本

#include <eikdll.h>
TInt err = EikDll::StartExeL(_L("c:\\system\\apps\\test.exe"));


Symbian 9, 服务或控制台应用

#include <apgcli.h> // link against apgrfx.lib
#include <apacmdln.h> // link against apparc.lib
 
TThreadId app_threadid;
CApaCommandLine* cmdLine;
cmdLine=CApaCommandLine::NewLC();
cmdLine->SetExecutableNameL(_L("test.exe"));
cmdLine->SetCommandL( EApaCommandRun );
RApaLsSession ls;
User::LeaveIfError(ls.Connect());
TInt err=ls.StartApp(*cmdLine,app_threadid);
ls.Close();
CleanupStack::PopAndDestroy(); // cmdLine


Symbian 9, 基于视图的应用

#include <apgcli.h> // link against apgrfx.lib
const TUid KAppUid={0x12345678};
_LIT(KDocName,"C:\\Data\\document.txt");
TThreadId app_threadid;
RApaLsSession ls;
User::LeaveIfError(ls.Connect());
TInt err=ls.StartDocument(KDocName, KAppUid, app_threadid);
ls.Close();


Symbian 9, RProcess

_LIT(KMyExeFile,"test.exe");
_LIT(KMyExeFileCmd,"first_argument second third");
 
RProcess proc;
User::LeaveIfError(proc.Create(KMyExeFile,KMyExeFileCmd));
// start the process running! Don't forget this.
proc.Resume();
proc.Close(); // Closes the handle, not the process.


停止exe

首先, 需要找到进程

在Symbian 9, 进程名按下面的格式:

<name>[<UID3>]<instance number>

这里: <name> - 可执行文件名 or 控制台名 - 因此需记住以便更改;

<UID3> - 可执行文件的UID3, 小写HEX, 8位, 总是相同的;

<instance number> - 实例编号, 4位, 从0001开始。 例如内核进程名为:

ekern.exe[100041af]0001


杀死

注意: 对于S60 3rd版开发,需要PowerMgmt能力来完成这个任务。

TFindProcess processFinder(_L("test.exe*")); // by name, case-sensitive
//or
//TFindProcess processFinder(_L("*[12345678]*")); // by UID3
TFullName result;
RProcess processHandle;
while ( processFinder.Next(result) == KErrNone)
{
User::LeaveIfError(processHandle.Open ( processFinder, EOwnerThread));
processHandle.Kill(KErrNone);
processHandle.Close();
}


杀死进程不是好做法

因为进程及也许已打开资源的内部状态不可控制。推荐实现一种通讯机制能让你告诉你的守护进程(daemon)释放所保留的资源然后退出。

参见

This page was last modified on 30 May 2013, at 04:37.
120 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×