mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-24 19:42:24 +03:00
Merge branch 'caramis-master'
This commit is contained in:
commit
4d3fd14ada
@ -21,7 +21,6 @@
|
||||
#include "synergy/XSynergy.h"
|
||||
#include "base/Log.h"
|
||||
|
||||
#include <Tlhelp32.h>
|
||||
#include <Wtsapi32.h>
|
||||
|
||||
CMSWindowsSession::CMSWindowsSession() :
|
||||
@ -69,34 +68,29 @@ CMSWindowsSession::isProcessInSession(const char* name, PHANDLE process = NULL)
|
||||
entry.th32ProcessID, &processSessionId);
|
||||
|
||||
if (!pidToSidRet) {
|
||||
// if we can not acquire session associated with a specified process,
|
||||
// simply ignore it
|
||||
LOG((CLOG_ERR "could not get session id for process id %i", entry.th32ProcessID));
|
||||
throw XArch(new XArchEvalWindows());
|
||||
gotEntry = nextProcessEntry(snapshot, &entry);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// only pay attention to processes in the active session
|
||||
if (processSessionId == m_activeSessionId) {
|
||||
|
||||
// only pay attention to processes in the active session
|
||||
if (processSessionId == m_activeSessionId) {
|
||||
// store the names so we can record them for debug
|
||||
nameList.push_back(entry.szExeFile);
|
||||
|
||||
// store the names so we can record them for debug
|
||||
nameList.push_back(entry.szExeFile);
|
||||
|
||||
if (_stricmp(entry.szExeFile, name) == 0) {
|
||||
pid = entry.th32ProcessID;
|
||||
if (_stricmp(entry.szExeFile, name) == 0) {
|
||||
pid = entry.th32ProcessID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// now move on to the next entry (if we're not at the end)
|
||||
gotEntry = Process32Next(snapshot, &entry);
|
||||
if (!gotEntry) {
|
||||
|
||||
DWORD err = GetLastError();
|
||||
if (err != ERROR_NO_MORE_FILES) {
|
||||
|
||||
// only worry about error if it's not the end of the snapshot
|
||||
LOG((CLOG_ERR "could not get next process entry"));
|
||||
throw XArch(new XArchEvalWindows());
|
||||
}
|
||||
}
|
||||
gotEntry = nextProcessEntry(snapshot, &entry);
|
||||
}
|
||||
|
||||
std::string nameListJoin;
|
||||
@ -158,3 +152,22 @@ CMSWindowsSession::updateActiveSession()
|
||||
{
|
||||
m_activeSessionId = WTSGetActiveConsoleSessionId();
|
||||
}
|
||||
|
||||
|
||||
BOOL
|
||||
CMSWindowsSession::nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry)
|
||||
{
|
||||
BOOL gotEntry = Process32Next(snapshot, entry);
|
||||
if (!gotEntry) {
|
||||
|
||||
DWORD err = GetLastError();
|
||||
if (err != ERROR_NO_MORE_FILES) {
|
||||
|
||||
// only worry about error if it's not the end of the snapshot
|
||||
LOG((CLOG_ERR "could not get next process entry"));
|
||||
throw XArch(new XArchEvalWindows());
|
||||
}
|
||||
}
|
||||
|
||||
return gotEntry;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <Tlhelp32.h>
|
||||
|
||||
class CMSWindowsSession {
|
||||
public:
|
||||
@ -39,6 +40,9 @@ public:
|
||||
|
||||
void updateActiveSession();
|
||||
|
||||
private:
|
||||
BOOL nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry);
|
||||
|
||||
private:
|
||||
DWORD m_activeSessionId;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user