Categories: Lang-CN | Symbian C++ | S60 | How To | Code Examples | Base/System
This page was last modified 00:21, 14 July 2008.
如何启动和停止exe
From Forum Nokia Wiki
如何启动和停止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)释放所保留的资源然后退出。
