mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-25 00:33:09 +08:00
Fix: TestRun run as windows service can't unlock screen
This commit is contained in:
@@ -198,7 +198,7 @@ int main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetSelfStart(argv[0], REG_NAME)) {
|
if (!SetSelfStart(argv[0], REG_NAME, Logf)) {
|
||||||
Mprintf("设置开机自启动失败,请用管理员权限运行.\n");
|
Mprintf("设置开机自启动失败,请用管理员权限运行.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,11 +273,12 @@ private:
|
|||||||
BYTE* pData = (BYTE*)mapped.pData;
|
BYTE* pData = (BYTE*)mapped.pData;
|
||||||
int rowSize = m_ulFullWidth * 4; // ÿ<>е<EFBFBD><D0B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>RGBA<42><41>
|
int rowSize = m_ulFullWidth * 4; // ÿ<>е<EFBFBD><D0B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>RGBA<42><41>
|
||||||
|
|
||||||
|
BYTE* dest = buffer + reservedBytes + (m_ulFullHeight - 1) * rowSize;
|
||||||
|
BYTE* src = pData;
|
||||||
for (int y = 0; y < m_ulFullHeight; y++) {
|
for (int y = 0; y < m_ulFullHeight; y++) {
|
||||||
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD>껺<EFBFBD><EABBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3>ӵײ<D3B5><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
memcpy(dest, src, rowSize);
|
||||||
int destIndex = reservedBytes + (m_ulFullHeight - 1 - y) * rowSize;
|
dest -= rowSize;
|
||||||
int srcIndex = y * mapped.RowPitch; // Direct3D <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
|
src += mapped.RowPitch;
|
||||||
memcpy(buffer + destIndex, pData + srcIndex, rowSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. <20><><EFBFBD><EFBFBD>
|
// 7. <20><><EFBFBD><EFBFBD>
|
||||||
|
|||||||
@@ -276,6 +276,40 @@ void CScreenManager::InitScreenSpy()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL IsRunningAsSystem() {
|
||||||
|
HANDLE hToken;
|
||||||
|
PTOKEN_USER pTokenUser = NULL;
|
||||||
|
DWORD dwSize = 0;
|
||||||
|
BOOL isSystem = FALSE;
|
||||||
|
|
||||||
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
|
||||||
|
pTokenUser = (PTOKEN_USER)malloc(dwSize);
|
||||||
|
|
||||||
|
if (pTokenUser && GetTokenInformation(hToken, TokenUser, pTokenUser,
|
||||||
|
dwSize, &dwSize)) {
|
||||||
|
// 使用 WellKnownSid 创建 SYSTEM SID
|
||||||
|
BYTE systemSid[SECURITY_MAX_SID_SIZE];
|
||||||
|
DWORD sidSize = sizeof(systemSid);
|
||||||
|
|
||||||
|
if (CreateWellKnownSid(WinLocalSystemSid, NULL, systemSid, &sidSize)) {
|
||||||
|
isSystem = EqualSid(pTokenUser->User.Sid, systemSid);
|
||||||
|
if (isSystem){
|
||||||
|
Mprintf("当前进程以 SYSTEM 身份运行。\n");
|
||||||
|
} else {
|
||||||
|
Mprintf("当前进程未以 SYSTEM 身份运行。\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pTokenUser);
|
||||||
|
CloseHandle(hToken);
|
||||||
|
return isSystem;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL CScreenManager::OnReconnect()
|
BOOL CScreenManager::OnReconnect()
|
||||||
{
|
{
|
||||||
m_SendFirst = FALSE;
|
m_SendFirst = FALSE;
|
||||||
@@ -320,19 +354,16 @@ DWORD WINAPI CScreenManager::WorkThreadProc(LPVOID lParam)
|
|||||||
This->SendFirstScreen();
|
This->SendFirstScreen();
|
||||||
}
|
}
|
||||||
// 降低桌面检查频率,避免频繁的DC重置导致闪屏
|
// 降低桌面检查频率,避免频繁的DC重置导致闪屏
|
||||||
if (This->m_isGDI && This->IsRunAsService() && !This->m_virtual) {
|
if (This->IsRunAsService() && !This->m_virtual) {
|
||||||
auto now = clock();
|
auto now = clock();
|
||||||
if (now - last_check > 500) {
|
if (now - last_check > 500) {
|
||||||
last_check = now;
|
last_check = now;
|
||||||
|
|
||||||
// 使用公共函数检查并切换桌面(无需写权限)
|
// 使用公共函数检查并切换桌面(无需写权限)
|
||||||
if (SwitchToDesktopIfChanged(This->g_hDesk, 0)) {
|
if (SwitchToDesktopIfChanged(This->g_hDesk, 0) && This->m_isGDI) {
|
||||||
// 桌面变化时重置屏幕捕获的DC
|
// 桌面变化时重置屏幕捕获的DC
|
||||||
if (This->m_ScreenSpyObject) {
|
CScreenSpy* spy = (CScreenSpy*)(This->m_ScreenSpyObject);
|
||||||
CScreenSpy* spy = dynamic_cast<CScreenSpy*>(This->m_ScreenSpyObject);
|
if (spy) {
|
||||||
if (spy) {
|
spy->ResetDesktopDC();
|
||||||
spy->ResetDesktopDC();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -884,13 +915,7 @@ VOID CScreenManager::ProcessCommand(LPBYTE szBuffer, ULONG ulLength)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (IsRunAsService()) {
|
if (IsRunAsService()) {
|
||||||
// 获取当前活动桌面(带写权限,用于锁屏等安全桌面)
|
|
||||||
// 使用独立的静态变量避免与WorkThreadProc的g_hDesk并发冲突
|
|
||||||
static HDESK s_inputDesk = NULL;
|
|
||||||
static clock_t s_lastCheck = 0;
|
|
||||||
static DWORD s_lastThreadId = 0;
|
|
||||||
const int CHECK_INTERVAL = 100; // 桌面检测间隔(ms),快速响应锁屏/UAC切换
|
const int CHECK_INTERVAL = 100; // 桌面检测间隔(ms),快速响应锁屏/UAC切换
|
||||||
|
|
||||||
// 首次调用或定期检测桌面是否变化(降低频率,避免每次输入都检测)
|
// 首次调用或定期检测桌面是否变化(降低频率,避免每次输入都检测)
|
||||||
auto now = clock();
|
auto now = clock();
|
||||||
if (!s_inputDesk || now - s_lastCheck > CHECK_INTERVAL) {
|
if (!s_inputDesk || now - s_lastCheck > CHECK_INTERVAL) {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ bool LaunchApplication(TCHAR* pszApplicationFilePath, TCHAR* pszDesktopName);
|
|||||||
|
|
||||||
bool IsWindows8orHigher();
|
bool IsWindows8orHigher();
|
||||||
|
|
||||||
|
BOOL IsRunningAsSystem();
|
||||||
|
|
||||||
class IOCPClient;
|
class IOCPClient;
|
||||||
|
|
||||||
struct UserParam;
|
struct UserParam;
|
||||||
@@ -58,8 +60,17 @@ public:
|
|||||||
}
|
}
|
||||||
bool IsRunAsService() const
|
bool IsRunAsService() const
|
||||||
{
|
{
|
||||||
return m_conn ? m_conn->iStartup == Startup_GhostMsc : false;
|
if (m_conn && (m_conn->iStartup == Startup_GhostMsc || m_conn->iStartup == Startup_TestRunMsc))
|
||||||
|
return true;
|
||||||
|
static BOOL is_run_as_system = IsRunningAsSystem();
|
||||||
|
return is_run_as_system;
|
||||||
}
|
}
|
||||||
|
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><EFBFBD><EEB6AF><EFBFBD>棨<EFBFBD><E6A3A8>дȨ<D0B4>ޣ<EFBFBD><DEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȱ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>棩
|
||||||
|
// ʹ<>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>ľ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WorkThreadProc<6F><63>g_hDesk<73><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ
|
||||||
|
HDESK s_inputDesk = NULL;
|
||||||
|
clock_t s_lastCheck = 0;
|
||||||
|
DWORD s_lastThreadId = 0;
|
||||||
|
|
||||||
bool SwitchScreen();
|
bool SwitchScreen();
|
||||||
virtual BOOL OnReconnect();
|
virtual BOOL OnReconnect();
|
||||||
uint64_t m_DlgID = 0;
|
uint64_t m_DlgID = 0;
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ inline int DebugPrivilege()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef void (*StartupLogFunc)(const char* file, int line, const char* format, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* @brief <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
* @param[in] *sPath ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
* @param[in] *sPath ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||||
@@ -54,26 +56,42 @@ inline int DebugPrivilege()
|
|||||||
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
|
* HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
|
||||||
* @note <20>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>ԱȨ<D4B1><C8A8><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>д<EFBFBD>뿪<EFBFBD><EBBFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* @note <20>״<EFBFBD><D7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>ԱȨ<D4B1><C8A8><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>д<EFBFBD>뿪<EFBFBD><EBBFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
*/
|
*/
|
||||||
inline BOOL SetSelfStart(const char* sPath, const char* sNmae)
|
inline BOOL SetSelfStart(const char* sPath, const char* sNmae, StartupLogFunc Log)
|
||||||
{
|
{
|
||||||
DebugPrivilege();
|
#define _Mprintf(format, ...) if (Log) Log(__FILE__, __LINE__, format, __VA_ARGS__)
|
||||||
|
|
||||||
|
int n = DebugPrivilege();
|
||||||
|
if (n != 0) {
|
||||||
|
_Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%d\n", n);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
// д<><D0B4><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
// д<><D0B4><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
||||||
#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
|
#define REGEDIT_PATH "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
|
||||||
|
|
||||||
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
// <20><>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||||
HKEY hKey = NULL;
|
HKEY hKey = NULL;
|
||||||
LONG lRet = RegOpenKeyExA(HKEY_CURRENT_USER, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey);
|
LONG lRet = RegOpenKeyExA(HKEY_CURRENT_USER, REGEDIT_PATH, 0, KEY_ALL_ACCESS, &hKey);
|
||||||
|
|
||||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||||
if (lRet != ERROR_SUCCESS)
|
if (lRet != ERROR_SUCCESS) {
|
||||||
|
_Mprintf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%d\n", lRet);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1);
|
lRet = RegSetValueExA(hKey, sNmae, 0, REG_SZ, (const BYTE*)sPath, strlen(sPath) + 1);
|
||||||
|
|
||||||
|
if (lRet != ERROR_SUCCESS) {
|
||||||
|
_Mprintf("д<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺%d\n", lRet);
|
||||||
|
} else {
|
||||||
|
_Mprintf("д<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>%s -> %s\n", sNmae, sPath);
|
||||||
|
}
|
||||||
|
|
||||||
// <20>ر<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
// <20>ر<EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD>
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
|
#undef _Mprintf
|
||||||
|
|
||||||
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
// <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||||||
return lRet == ERROR_SUCCESS;
|
return lRet == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ int main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ok = SetSelfStart(argv[0], REG_NAME);
|
BOOL ok = SetSelfStart(argv[0], REG_NAME, Logf);
|
||||||
if(!ok) {
|
if(!ok) {
|
||||||
Mprintf("设置开机自启动失败,请用管理员权限运行.\n");
|
Mprintf("设置开机自启动失败,请用管理员权限运行.\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -239,7 +239,11 @@ BOOL LaunchAsAdmin(const char* szFilePath, const char* verb)
|
|||||||
|
|
||||||
BOOL CMy2015RemoteApp::InitInstance()
|
BOOL CMy2015RemoteApp::InitInstance()
|
||||||
{
|
{
|
||||||
|
#if _DEBUG
|
||||||
|
BOOL runNormal = TRUE;
|
||||||
|
#else
|
||||||
BOOL runNormal = THIS_CFG.GetInt("settings", "RunNormal", 0);
|
BOOL runNormal = THIS_CFG.GetInt("settings", "RunNormal", 0);
|
||||||
|
#endif
|
||||||
char curFile[MAX_PATH] = { 0 };
|
char curFile[MAX_PATH] = { 0 };
|
||||||
GetModuleFileNameA(NULL, curFile, MAX_PATH);
|
GetModuleFileNameA(NULL, curFile, MAX_PATH);
|
||||||
if (!runNormal && !IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas")) {
|
if (!runNormal && !IsRunningAsAdmin() && LaunchAsAdmin(curFile, "runas")) {
|
||||||
|
|||||||
@@ -142,6 +142,13 @@ void CPasswordDlg::OnCbnSelchangeComboBind()
|
|||||||
std::string hardwareID = CMy2015RemoteDlg::GetHardwareID(m_nBindType);
|
std::string hardwareID = CMy2015RemoteDlg::GetHardwareID(m_nBindType);
|
||||||
m_sDeviceID = getFixedLengthID(hashSHA256(hardwareID)).c_str();
|
m_sDeviceID = getFixedLengthID(hashSHA256(hardwareID)).c_str();
|
||||||
m_EditDeviceID.SetWindowTextA(m_sDeviceID);
|
m_EditDeviceID.SetWindowTextA(m_sDeviceID);
|
||||||
|
auto master = THIS_CFG.GetStr("settings", "master", "");
|
||||||
|
if (m_nBindType == 1) {
|
||||||
|
MessageBoxA("请确认是否正确设置公网地址(IP或域名)?\r\n"
|
||||||
|
"绑定IP后主控只能使用指定IP,绑定域名后\r\n"
|
||||||
|
"主控只能使用指定域名。当前公网地址: \r\n"
|
||||||
|
+ CString(master.empty() ? "未设置" : master.c_str()), "提示", MB_OK | MB_ICONWARNING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPasswordDlg::OnOK()
|
void CPasswordDlg::OnOK()
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ public:
|
|||||||
}
|
}
|
||||||
virtual bool IsEqual(context *ctx) const
|
virtual bool IsEqual(context *ctx) const
|
||||||
{
|
{
|
||||||
return this == ctx || (GetPeerName() == ctx->GetPeerName() && GetPort() == ctx->GetPort());
|
return this == ctx || this->GetPort() == ctx->GetPort();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user