把你的程序发给我,给改好给你!我的那个ProAssist有进程,线程的优先级设置方法。<br>贴子上我都说了,先AdjustTokenPrivileges提升进程权限,再windows.OpenProcess() 然后设置SetPriorityClass 才行<br>你还掉了一步 Windows.OpenProcess()<br>Windows.OpenProcess(Windows.PROCESS_SET_INFORMATION, False, PID) //这个PID就是你 FProcessEntry32.th32ProcessID<br>另外你下面的几外参数传递错误,不是传FSnapshotHandle, 是传OpenProcess的返回结果,就是打开进程的句柄。<br>打开后别忘关闭CloseHandle(OpenProcess的返回句柄,不然是非常耗资源的,特别是在线程中使用Open 一个句柄的情况下。<br><br>OK,应该没有问题了,但你的提升进程权限的参数好像不对,在网找找,挺多的。<br><br>如有问题,请加我MSN: jfyes@hotmail.com 或QQ:348677065<br><br><br><br><br><br>========================================================<br>----- Original Message ----- <br>From: "onyliu" <onyliu@126.com><br>To: "jf_yes" <jf_yes@126.com><br>Sent: Thursday, February 08, 2007 1:41 PM<br>Subject: 进程权限问题<br><br><br>> 获取关机权限没问题 如下:<br>> <br>> procedure ExitWindow;<br>> var<br>> st : SYSTEMTIME;<br>> hToken : THANDLE;<br>> tkp : TOKEN_PRIVILEGES;<br>> rr : Dword;<br>> begin<br>> OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken);<br>> LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);<br>> // 设定权限为1<br>> tkp.PrivilegeCount := 1;<br>> tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br>> // 得到权限<br><br>> AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,rr);<br>> // 重起计算机<br>> ExitWindowsEx(EWX_LOGOFF, 0)<br>> end;<br>> <br>> <br>> 但是获取进程权限就是不成功啊 帮我看看啊 (这个函数的功能就是给进程名和进程优先级 后调整优先级)<br>> function TForm1.SetPriority(ExeFileName: string;Flag : Integer): boolean;<br>> var<br>> ContinueLoop: BOOLean;<br>> FSnapshotHandle: THandle;<br>> FProcessEntry32: TProcessEntry32;<br>> tkp : TOKEN_PRIVILEGES;<br>> rr : Dword;<br>> begin<br>> Result := True;<br>> FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>> FProcessEntry32.dwSize := SizeOf(FProcessEntry32);<br>> ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);<br>> <br>> while Integer(ContinueLoop) <> 0 do<br>> begin<br>> if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) then<br>> begin<br>> OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,FSnapshotHandle);<br>> LookupPrivilegeValue(nil,'SeDebugprovilege',tkp.Privileges[0].Luid);<br>> // 设定权限为1<br>> tkp.PrivilegeCount := 1;<br>> tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br>> // 得到权限<br>> AdjustTokenPrivileges(FSnapshotHandle, FALSE, tkp, 0,nil,rr);<br>> case Flag of<br>> 0:Result :=SetPriorityClass(FSnapshotHandle,REALTIME_PRIORITY_CLASS); //实时<br>> 1:Result :=SetPriorityClass(FSnapshotHandle,HIGH_PRIORITY_CLASS); //高<br>> 2:Result :=SetPriorityClass(FSnapshotHandle,NORMAL_PRIORITY_CLASS); //正常<br>> 3:Result :=SetPriorityClass(FSnapshotHandle,IDLE_PRIORITY_CLASS); //空闲<br>> end;<br>> end;<br>> ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);<br>> end;<br>> CloseHandle(FSnapshotHandle);<br>> end;