Kill process (进程)//根据程序名,在系统中杀掉一个进程 KillProcess(_L("HelloWorld"));
void KillProcess(const TDesC& aProcessNameNotExtName)
{
TFullName name;
TFindProcess finder;
while(finder.Next(name) == KErrNone)
{
if(name.FindF(aProcessNameNotExtName) != KErrNotFound) // check if this is our process
{
RProcess process;
if(process.Open(finder, EOwnerProcess) == KErrNone) // Open process
{
process.Kill(KErrNone); // Kill process
process.Close();
}
}
}
}
转自:珍惜博客
1.TFindProcess::Next()参数中的进程名称的格式:<name>[<UID3>]<instance number>
<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
TFindProcess::Next() 可以发现全部进程, 而 TFindAppTask只能发现非隐藏窗口应用.
2.How to Launch an EXE and Pass Command Line Arguments
http://wiki.forum.nokia.com/index.php/How_to_Launch_an_EXE_and_Pass_Command_Line_Arguments
如何启动和停止exe
http://space.itpub.net/17096048/viewspace-590720
转自 http://blog.csdn.net/andyweike/archive/2009/08/16/4453123.aspx
如何启动和停止exe
启动一个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.libconstTUid 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 UID3TFullName result;
RProcess processHandle;while(processFinder.Next(result)== KErrNone){User::LeaveIfError(processHandle.Open(processFinder, EOwnerThread));
processHandle.Kill(KErrNone);
processHandle.Close();}
杀死进程不是好做法
因为进程及也许已打开资源的内部状态不可控制。推荐实现一种通讯机制能让你告诉你的守护进程(daemon)释放所保留的资源然后退出。
参见
[How to Launch an EXE and Pass Command Line Arguments ]
转自 http://space.itpub.net/17096048/viewspace-590720