×
Namespaces

Variants
Actions

如何启动和终止exe

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
文章
翻译:
huwell
最后由 hamishwillee 在 30 May 2013 编辑

Contents

启动一个exe

Symbian OS v8及之前版本

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


Symbian 9下Server或Console程序

#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.


如何终止

首先你需要找到进程

On Symbian 9, process name is in the following format:

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

where: <name> - the name of executable or the name of Console - so remember it can be changed;


<UID3> - UID3 of executable, in lowercase HEX, 8 digits, always the same;

<instance number> - instance number, 4 digits, starting from 0001. For example name of kernel process is:

ekern.exe[100041af]0001


然后杀死它

Warning.pngWarning: 

  • 杀掉一个进程是非常不好的习惯,因为进程的内部状态以及打开的资源可能无法控制。建议你先完成一个通信机制,这样可以告诉你的守护进程去释
  • 放这些已经分配的资源。

Note: 注意S60第三版中需要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();
}


 

相关链接:

This page was last modified on 30 May 2013, at 07:41.
61 page views in the last 30 days.