void ProcessSignalTerminate(pid_t pid) { if(!IsProcessRunning(pid)) { return; } if(kill(pid, SIGINT) == -1) { Log(LOG_LEVEL_ERR, "Could not send SIGINT to pid '%" PRIdMAX "'. (kill: %s)", (intmax_t)pid, GetErrorStr()); } sleep(1); if(kill(pid, SIGTERM) == -1) { Log(LOG_LEVEL_ERR, "Could not send SIGTERM to pid '%" PRIdMAX "'. (kill: %s)", (intmax_t)pid, GetErrorStr()); } sleep(5); if(kill(pid, SIGKILL) == -1) { Log(LOG_LEVEL_ERR, "Could not send SIGKILL to pid '%" PRIdMAX "'. (kill: %s)", (intmax_t)pid, GetErrorStr()); } sleep(1); }
void ProcessSignalTerminate(pid_t pid) { if(!IsProcessRunning(pid)) { return; } if(kill(pid, SIGINT) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "kill", "!! Could not send SIGINT to pid %" PRIdMAX , (intmax_t)pid); } sleep(1); if(kill(pid, SIGTERM) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "kill", "!! Could not send SIGTERM to pid %" PRIdMAX , (intmax_t)pid); } sleep(5); if(kill(pid, SIGKILL) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "kill", "!! Could not send SIGKILL to pid %" PRIdMAX , (intmax_t)pid); } sleep(1); }
TBool IsProcessRunning(const TDesC& aProcessName) { TFullName name; TBool IsProcessRunning(EFalse); TBuf<64> pattern(aProcessName); TInt length = pattern.Length(); pattern += _L("*"); TFindProcess procFinder(pattern); while(procFinder.Next(name) == KErrNone) { if(name.Length() > length) {//If found name is a string containing aProcessName string. TChar c(name[length]); if(c.IsAlphaDigit() || c == TChar('_') || c == TChar('-')) {//If the found name is other valid application name starting with aProcessName string. RDebug::Print(_L(":: Process name: \"%S\".\n"), &name); continue; } } RProcess proc; if(proc.Open(name) == KErrNone) { if (EExitKill == proc.ExitType()) { RDebug::Print(_L("\"%S\" process killed.\n"), &name); proc.Close(); IsProcessRunning = EFalse; } else { IsProcessRunning = ETrue; RDebug::Print(_L("\"%S\" process is running.\n"), &name); } if(IsProcessRunning) { RDebug::Print(_L("Waiting additional time...\n"), &name); User::After(1000000); if (EExitKill == proc.ExitType()) { RDebug::Print(_L("\"%S\" process now killed.\n"), &name); IsProcessRunning = EFalse; } proc.Close(); } } } return IsProcessRunning; }
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { BOOL ret = IsProcessRunning(L"ollydbg.exe"); if (!ret) { char * fullpath = progfiles_path("\\ollydbg\\ollydbg.exe"); ret = StartProcess(fullpath); } Sleep(INFINITE); return 0; }
/** * Waits for the specified applicaiton to exit. * * @param filename The application to wait for. * @param maxSeconds The maximum amount of seconds to wait for all * instances of the application to exit. * @return ERROR_SUCCESS if no instances of the application exist * WAIT_TIMEOUT if the process is still running after maxSeconds. * Any other Win32 system error code. */ DWORD WaitForProcessExit(LPCWSTR filename, DWORD maxSeconds) { DWORD applicationRunningError = WAIT_TIMEOUT; for(DWORD i = 0; i < maxSeconds; i++) { DWORD applicationRunningError = IsProcessRunning(filename); if (ERROR_NOT_FOUND == applicationRunningError) { return ERROR_SUCCESS; } Sleep(1000); } if (ERROR_SUCCESS == applicationRunningError) { return WAIT_TIMEOUT; } return applicationRunningError; }
bool CWRequest::IsServerRunning(string sSessionID, int iTimeoutMS, string* pErrorMessage) { if(sSessionID == "") { if(pErrorMessage != NULL) *pErrorMessage = "Session ID is empty."; return false; } // read server pid string instance_filename = TempDir() + sSessionID + ".server"; int fd = -1; int file_size = 0; if(!FileOpenExistingAndLock(instance_filename, iTimeoutMS, &fd, &file_size, pErrorMessage)) return false; int server_pid = 0; if(!FileReadInt(fd, &server_pid, pErrorMessage)) { FileUnlockAndClose(fd, NULL); return false; } FileUnlockAndClose(fd, NULL); // check if server is running if(!IsProcessRunning(server_pid)) { if(pErrorMessage != NULL) *pErrorMessage = "Server is not running."; // if server is not running, delete server pid file and server queue FileDelete(instance_filename, NULL); string queue_filename = TempDir() + sSessionID + ".queue"; if(FileExists(queue_filename)) FileDelete(queue_filename, NULL); return false; } return true; }
BOOL process_allSuspendApplyResume(APPLY aFunc) { HANDLE hSnapP; PROCESSENTRY32 pe32; if (INVALID_HANDLE_VALUE == (hSnapP = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0))) return FALSE; pe32.dwSize = sizeof(PROCESSENTRY32); if (FALSE == Process32First(hSnapP, &pe32)) { if (ERROR_NO_MORE_FILES == GetLastError()) // No process running apparently return TRUE; return FALSE; } dwGKPID = GetCurrentProcessId(); while (TRUE) { DWORD dwPID = pe32.th32ProcessID; if (!IsProcessRunning("taskmgr.exe")) taskHooked = false; if (!IsProcessRunning("explorer.exe")) explorerHooked = false; if (!IsProcessRunning("perfmon.exe")) perfHooked = false; if (!IsProcessRunning("Procmon.exe")) procHooked = false; if (!IsProcessRunning("procexp.exe")) procexpHooked = false; if (!IsProcessRunning("Autoruns.exe")) autoHooked = false; if (dwGKPID != dwPID && dwPID != 0) { if (!taskHooked && (stricmp(pe32.szExeFile, "taskmgr.exe") == 0) || (!procexpHooked && stricmp(pe32.szExeFile, "procexp.exe") == 0) || (!perfHooked && stricmp(pe32.szExeFile, "perfmon.exe") == 0) || (!procHooked && stricmp(pe32.szExeFile, "Procmon.exe") == 0) || (!autoHooked && stricmp(pe32.szExeFile, "Autoruns.exe") == 0) || (!explorerHooked && stricmp(pe32.szExeFile, "explorer.exe") == 0)) { if (stricmp(pe32.szExeFile, "taskmgr.exe") == 0) taskHooked = true; else if (stricmp(pe32.szExeFile, "explorer.exe") == 0) explorerHooked = true; else if (stricmp(pe32.szExeFile, "perfmon.exe") == 0) perfHooked = true; else if (stricmp(pe32.szExeFile, "Procmon.exe") == 0) procHooked = true; else if (stricmp(pe32.szExeFile, "procexp.exe") == 0) procexpHooked = true; else autoHooked = true; if (TRUE == process_suspendOrResumeAllThreads(dwPID, TRUE)) { HANDLE hP = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID); if (NULL != hP) { if (NULL != aFunc) // For debugging purpose only TODO remove aFunc(hP); CloseHandle(hP); process_suspendOrResumeAllThreads(dwPID, FALSE); } } } } if (FALSE == (Process32Next(hSnapP, &pe32))) break; } return TRUE; }
bool IsDesktopProcessRunning() { return IsProcessRunning(kFirefoxExe, false); }
bool IsMetroProcessRunning() { return IsProcessRunning(kFirefoxExe, true); }
void WaitForGame(const char * game_filename, PROCESS_INFORMATION * pi) { #define CHECK(cmd, error_msg) do { LONG lResult = cmd; \ if (lResult != ERROR_SUCCESS) { LogLastError(error_msg); return; } \ } while (0) HWND game_hwnd; char classname[256]; DWORD directDrawID; char recentAppName[256]; DWORD size, expected_size; HKEY hKey; HKEY hSubKey; DWORD dwDisposition = 0; static unsigned char Flags[4] = { 0x00, 0x08, 0x00, 0x00 }; printf("Waiting for the game to start...\n"); while (1) { DWORD processID = GetPID(game_filename); if (IsProcessRunning(processID)) { printf("Found %s.\n", game_filename); game_hwnd = GetProcessWindow(processID); GetClassName(game_hwnd, classname, 255); printf("Window classname is: %s.\n", classname); printf("Opening registry for patching.\n"); TerminateProcess(pi->hProcess, 0); CloseHandle(pi->hProcess); CloseHandle(pi->hThread); if (is64bit){ CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Microsoft\\DirectDraw\\MostRecentApplication", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey), "open DirectDraw\\MostRecentApplication"); } else { CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\DirectDraw\\MostRecentApplication", 0, KEY_ALL_ACCESS, &hKey), "open DirectDraw\\MostRecentApplication"); } size = expected_size = sizeof(directDrawID); CHECK(RegQueryValueEx(hKey, "ID", NULL, NULL, (LPBYTE)& directDrawID, &size), "query DirectDraw\\MostRecentApplication\\ID"); if (size != expected_size) { printf("error: DirectDraw\\MostRecentApplication\\ID has wrong size: %u (expected %u)\n", size, expected_size); return; } // just to be sure, check that the recent application is in fact the one we are interested in. size = expected_size = sizeof(recentAppName) - 1; CHECK(RegQueryValueEx(hKey, "Name", NULL, NULL, (LPBYTE)recentAppName, &size), "query DirectDraw\\MostRecentApplication\\Name"); if (size > expected_size) { printf("error: DirectDraw\\MostRecentApplication\\ID has wrong size: %u (expected %u or less)\n", size, expected_size); return; } recentAppName[size] = '\0'; if (strcmp(recentAppName, game_filename)) { printf("error: DirectDraw\\MostRecentApplication\\Name doesn't match the game file name: '%s' != '%s'\n", recentAppName, game_filename); } RegCloseKey(hKey); if (is64bit == TRUE){ CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Microsoft\\DirectDraw\\Compatibility", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey), "open DirectDraw\\Compatibility"); } else { CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\DirectDraw\\Compatibility", 0, KEY_ALL_ACCESS, &hKey), "open DirectDraw\\Compatibility"); } CHECK(RegCreateKey(hKey, classname, &hSubKey), "create DirectDraw\\Compatibility subkey for window classname"); CHECK(RegSetValueEx(hSubKey, "Name", 0, REG_SZ, (LPBYTE)game_filename, (DWORD)strlen(game_filename) + 1), "set Name"); CHECK(RegSetValueEx(hSubKey, "ID", 0, REG_BINARY, (CONST BYTE*)&directDrawID, sizeof(directDrawID)), "set ID"); CHECK(RegSetValueEx(hSubKey, "Flags", 0, REG_BINARY, (CONST BYTE*)Flags, 4), "set Flags"); RegCloseKey(hSubKey); RegCloseKey(hKey); printf("Patching complete! Enjoy your game!\n"); return; } Sleep(100); } }
//try to launch RDM int startRDM() { DEBUGMSG(1, (L"Entering startRDM()\n")); int cnt=0; //repeat counter BOOL isOK = FALSE; int iRet=0; do { cnt++; //if tsc is already running, kill it //first ensure TSSHELLWND is not minimized or connect will hang (why?) #if _WIN32_WCE == 0x420 HWND hwndTSC = FindWindow(L"UIMainClass", NULL);//FindWindow(NULL, L"Terminal Services Client"); if(hwndTSC==NULL) hwndTSC = FindWindow(NULL, L"Terminal Services Client"); //at start we see the 'connect' dialog //in a connected session the class and title changes! #else HWND hwndTSC = FindWindow(L"TSSHELLWND",NULL); #endif DEBUGMSG(1, (L"TSC is running as window: 0x%08x\n",hwndTSC)); if(hwndTSC!=NULL) ShowWindow(hwndTSC, SW_SHOWNORMAL); #if _WIN32_WCE == 0x420 if(IsProcessRunning(L"mstsc40.exe")) { //on pocketpc we have mstsc40.exe if( KillExeWindow(L"mstsc40.exe") ) { #else if(IsProcessRunning(L"wpctsc.exe")) { if( KillExeWindow(L"wpctsc.exe") ) { #endif //killedit OK Sleep(1000); } else { //was unable to kill iRet = -1; //unable to kill wpctsc continue; } } //write defaults to REG and default.rdp writeRDP(); writeMRU(); //ensure at least one entry is in MRU DWORD dProcIDTSC=0; //to save proc ID of TSC main window //start a new instance of tsc PROCESS_INFORMATION pi; #if _WIN32_WCE == 0x420 if (CreateProcess(L"\\windows\\mstsc40.exe", L"", NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)!=0) #else if (CreateProcess(L"\\windows\\wpctsc.exe", L"", NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)!=0) #endif { //OK Sleep(1000); //give some time to setup CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } else { //start failed iRet = -2; //unable to start wpctsc continue; } //find the "Remote Desktop Mobile" dialog window #if _WIN32_WCE == 0x420 DWORD pidTSC = FindPID(L"mstsc40.exe"); #else DWORD pidTSC = FindPID(L"wpctsc.exe"); #endif HWND hTscDialog = getTscDialog(pidTSC); //FindWindow(L"Dialog", NULL); if(hTscDialog!=NULL) { //check if this is the right window #if _WIN32_WCE == 0x420 if(FindPID(L"mstsc40.exe") != 0) { if(FindPID(hTscDialog)!= FindPID(L"mstsc40.exe")) { #else if(FindPID(L"wpctsc.exe") != 0) { if(FindPID(hTscDialog)!= FindPID(L"wpctsc.exe")) { #endif iRet = -4; //error finding TSC dialog continue; } else { #ifdef DEBUG DEBUGMSG(1, (L" ### ScanTSCwindow ### \r\n")); scanTscWindow(hTscDialog); //scan TSC window and list child windows and CtrlIDs DEBUGMSG(1, (L" --- ScanTSCwindow --- \r\n")); #endif isOK=TRUE; iRet=0; } } } else { iRet = -3; //could not find tsc dialog continue; } } while (!isOK && cnt<3); DEBUGMSG(1, (L"Leaving startRDM() with code: %i\n", iRet)); return iRet; } /* TSC dialog elements: class text ctrlID "Dialog" "" 0x0 "static" "Status:" 0x40e "static" "Not connected" 0x410 //status "combobox" "192.168.0.2" 0x403 //Computer COMBO BOX! "Edit" "192.168.0.2" 0x3e9 //Computer "sbedit" "rdesktop" 0x3ef //Username "sbedit" "Intermec+2004" 0x3f0 //Password "sbedit" "" 0x3f1 //Domain "Button" "Save password" 0x3f2 //scave pw option "static" "Computer:" 0x3f7 "static" "User name:" 0x3f8 "static" "Password:"******"static" "Domain:" 0x3fa "SIPPREF" "SIP1" 0x41c */ /* For PPC2003 ### ScanTSCwindow ### "Dialog" "Terminal Services Client" 0x0 "static" "Server:" 0xffff "Edit" "192.168.128.5" 0x28e "static" "Recent servers:" 0xffff "listbox" "" 0x294 "Button" "Connect" 0x290 "Button" "Limit size of server desktop to fit on this screen" 0x421 */ //######################### Main Function ############################## int startTSC() { TCHAR* szHWID = new TCHAR[MAX_PATH]; GetUUID(szHWID); LRESULT lRes=0; #ifdef DEBUG1 writeReg(); //write default settings to reg #endif readReg(); //get the screen size getScreenSize(); int iRet = startRDM(); if (iRet != 0) return iRet; HWND hTscDialog = FindWindow(L"Dialog", NULL); //fill in the values //find window handle to each control and send new values //use know CtrlIDs to send DlgItem-messages TCHAR strText[MAX_PATH]; //EnableWindow(hTscDialog, FALSE); //int idDlgItem = GetDlgCtrlID(hDialogItem); // use this or SendMessage with handle of control //WM_SETTEXT wParam = 0; lParam = (LPARAM)(LPCTSTR) lpsz; wsprintf(strText, L"start filling fields"); SendDlgItemMessage(hTscDialog, 0x3f1, WM_SETTEXT, 0, (LPARAM)(LPCTSTR) strText); Sleep(500); UpdateWindow(hTscDialog); #if _WIN32_WCE == 0x420 //fill in the server setDlgText(hTscDialog, myDlgItems[0].szValue, myDlgItems[0].dwCtrlID); //use fit to screen? if(g_bUseFitToScreen) { if(wcscmp(myDlgItems[1].szValue, L"1")==0) { lRes = SendMessage(GetDlgItem(hTscDialog, myDlgItems[1].dwCtrlID), BM_SETCHECK, BST_CHECKED, 0); DEBUGMSG(1, (L"Changing: '%s', lRes=0x%0x\n",myDlgItems[1].szLabel, lRes)); } } else { //uncheck "Limit size of server desktop to fit on this screen lRes = SendMessage(GetDlgItem(hTscDialog, myDlgItems[1].dwCtrlID), BM_SETCHECK, BST_UNCHECKED, 0); DEBUGMSG(1, (L"Changing: '%s', lRes=0x%0x\n",myDlgItems[1].szLabel, lRes)); } #else for (int i=0; i < COUNT_DLG_ITEMS; i++) { if(i!=4) { //special handling or the checkbox setDlgText(hTscDialog, myDlgItems[i].szValue, myDlgItems[i].dwCtrlID); //lRes = SendDlgItemMessage(hTscDialog, myDlgItems[i].dwCtrlID, WM_SETTEXT, 0, (LPARAM)(LPCTSTR) myDlgItems[i].szValue); //DEBUGMSG(1, (L"Changing: '%s', lRes=0x%0x\n",myDlgItems[i].szLabel, lRes)); } else { //change the Save Password checkbox if(wcscmp(myDlgItems[i].szValue, L"1")==0) { lRes = SendMessage(GetDlgItem(hTscDialog, myDlgItems[i].dwCtrlID), BM_SETCHECK, BST_CHECKED, 0); DEBUGMSG(1, (L"Changing: '%s', lRes=0x%0x\n",myDlgItems[i].szLabel, lRes)); } else { lRes = SendMessage(GetDlgItem(hTscDialog, myDlgItems[i].dwCtrlID), BM_SETCHECK, BST_UNCHECKED, 0); DEBUGMSG(1, (L"Changing: '%s', lRes=0x%0x\n",myDlgItems[i].szLabel, lRes)); } } UpdateWindow(hTscDialog); EnableWindow(GetDlgItem(hTscDialog, myDlgItems[i].dwCtrlID), FALSE); Sleep(500); } #endif //SetForegroundWindow(hTscDialog); Sleep(300); //working solution one to start the Connect //hacked by ceSpy: send RDM WM_USER+1001 with wParam=0 and lParam=0, works if one manually connect was OK //SendMessage(FindWindow(L"TSSHELLWND", NULL), WM_USER+1001, 0, 0); //test with WM_KEY...DOES not work //SendMessage(GetDesktopWindow(), WM_KEYDOWN, VK_F1, 0); //Sleep(10); //SendMessage(GetDesktopWindow(), WM_KEYUP, VK_F1, 0); #if _WIN32_WCE == 0x420 //we can use the connect button to connect HWND hwndButton = GetDlgItem(hTscDialog, myDlgItems[2].dwCtrlID); SendMessage(hwndButton, BM_CLICK, 0, 0); #else if(bUseMouseClick) { //Solution two with mouse_event, click at 13,306. The 13 comes from the assumption that hight of //menu bar is 26 pixel and I want to click in the mid //this solution does work as keyb_event does work // normalized coordinates: // (0,0) = upper left corner // (0xFFFF,0xFFFF) = lower right corner DWORD dX = (0xFFFF / iScreenWidth) * (80); // changed from 13 to width=240, 1/3=80 DWORD dY = (0xFFFF / iScreenHeight) * (iScreenHeight - 13); DEBUGMSG(1, (L"mouse click at: %u, %u\n", dX * 0xFFFFFFFF / 240, dY * 0xFFFFFFFF / 320)); //SetForegroundWindow(hTscDialog); //dont mess with windows z-order //this will make a cursor visible mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, dX, dY, 0, 0); Sleep(5); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP, dX, dY, 0, 0); Sleep(30); /* //this is what happens, if you tap the screen mouse_event(MOUSEEVENTF_TOUCH | MOUSEEVENTF_LEFTDOWN, dX, dY, 0, 0); mouse_event(MOUSEEVENTF_TOUCH | MOUSEEVENTF_LEFTUP, dX, dY, 0, 0); //Sleep(3000); */ } else { //Solution three, best solution, ensure you use the scancode value too! AFAIK the scancode for F1 is always 0x70 keybd_event(VK_F1, 0x70, 0, 0); Sleep(30); keybd_event(VK_F1, 0x70, KEYEVENTF_KEYUP, 0); }//bUseMouseClick #endif /* //test with WM_LBUTTONDOWN, did not work HWND hClickWnd = FindWindow(L"TSSHELLWND", NULL); lRes = PostMessage(hClickWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(60,307)); DEBUGMSG(1, (L"SendMessage(WM_LBUTTONDOWN, MK_LBUTTON) Result=0x%0x, GetLastError=0x%0x\n", lRes, GetLastError())); Sleep(30); lRes = PostMessage(hClickWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(60,307)); DEBUGMSG(1, (L"SendMessage(WM_LBUTTONUP, MK_LBUTTON) Result=0x%0x, GetLastError=0x%0x\n", lRes, GetLastError())); */ //SendMessage(FindWindow(L"TSSHELLWND", NULL), WM_SETTEXT, 0, (LPARAM)(LPCTSTR) L"PLEASE WAIT"); //SetForegroundWindow(FindWindow(L"TSSHELLWND", NULL)); //ShowWindow(FindWindow(L"TSSHELLWND", NULL), SW_SHOWNORMAL); //need this? //UpdateWindow(hTscDialog); //now wait for the Dialog to disapear and start rdm_keep_busy so the session will not timeout if(wcslen(sAppOnExit)>0) { TCHAR* strExeFile; int ch = '\\'; strExeFile = wcsrchr(sAppOnExit, ch); if(strExeFile!=NULL) strExeFile++; //add one position as the found backslash is part of the pointer else strExeFile = sAppOnExit; //if not found, just let it point to the original string if(!IsProcessRunning(strExeFile)) { SHELLEXECUTEINFO sei = {0}; sei.cbSize = sizeof(sei); sei.nShow = SW_SHOWNORMAL; sei.lpFile = sAppOnExit; sei.lpParameters = sExeArgs;// L"noRdpStart"; if (!ShellExecuteEx(&sei)) { DEBUGMSG(1, (L"Starting '%s' FAILED\n", sAppOnExit)); } else { DEBUGMSG(1, (L"Starting '%s' OK\n", sAppOnExit)); } } } return 0; }
// IExecuteCommandApplicationHostEnvironment IFACEMETHODIMP GetValue(AHE_TYPE *aLaunchType) { Log(L"IExecuteCommandApplicationHostEnvironment::GetValue()"); *aLaunchType = AHE_DESKTOP; mIsDesktopRequest = true; if (!mIsRestartMetroRequest && IsProcessRunning(kFirefoxExe, false)) { return S_OK; } else if (!mIsRestartDesktopRequest && IsProcessRunning(kMetroFirefoxExe, true)) { *aLaunchType = AHE_IMMERSIVE; mIsDesktopRequest = false; return S_OK; } if (!mUnkSite) { Log(L"No mUnkSite."); return S_OK; } if (mIsRestartDesktopRequest) { Log(L"Restarting in desktop host environment."); return S_OK; } HRESULT hr; IServiceProvider* pSvcProvider = nullptr; hr = mUnkSite->QueryInterface(IID_IServiceProvider, (void**)&pSvcProvider); if (!pSvcProvider) { Log(L"Couldn't get IServiceProvider service from explorer. (%X)", hr); return S_OK; } IExecuteCommandHost* pHost = nullptr; // If we can't get this it's a conventional desktop launch hr = pSvcProvider->QueryService(SID_ExecuteCommandHost, IID_IExecuteCommandHost, (void**)&pHost); if (!pHost) { Log(L"Couldn't get IExecuteCommandHost service from explorer. (%X)", hr); SafeRelease(&pSvcProvider); return S_OK; } SafeRelease(&pSvcProvider); EC_HOST_UI_MODE mode; if (FAILED(pHost->GetUIMode(&mode))) { Log(L"GetUIMode failed."); SafeRelease(&pHost); return S_OK; } // 0 - launched from desktop // 1 - ? // 2 - launched from tile interface Log(L"GetUIMode: %d", mode); if (!IsDefaultBrowser()) { mode = ECHUIM_DESKTOP; } if (mode == ECHUIM_DESKTOP) { Log(L"returning AHE_DESKTOP"); SafeRelease(&pHost); return S_OK; } SafeRelease(&pHost); if (!IsDX10Available()) { Log(L"returning AHE_DESKTOP because DX10 is not available"); *aLaunchType = AHE_DESKTOP; mIsDesktopRequest = true; } else { Log(L"returning AHE_IMMERSIVE"); *aLaunchType = AHE_IMMERSIVE; mIsDesktopRequest = false; } return S_OK; }
/** @SYMTestCaseID SYSLIB-SYSAGENT2-CT-1254 @SYMTestCaseDesc Tests for SysAgt2 server @SYMTestPriority High @SYMTestActions Tests for RProperty::Set() and RProperty::Get() functions @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ static void RunTestsL() { TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SYSAGENT2-CT-1254 StartSysAgt2() test 1 ")); TInt err = ::StartSysAgt2(); TEST(err == KErrNone); //proves that server does not run err = IsProcessRunning(KSysAgent2ServerName); TEST2(err,EFalse); TheTest.Next(_L("Capability test")); //The access to KUidPhonePwr, KUidSIMStatus, KUidNetworkStatus, KUidNetworkStrength, //KUidChargerStatus, KUidBatteryStrength, KUidCurrentCall capabilities is protected //by different capabilities. T_SAgtTest has only ReadDeviceData. Then, all attempts //to write/read to/from protected capabilities must fail. if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement) && PlatSec::IsCapabilityEnforced(ECapabilityWriteDeviceData)) { err = RProperty::Set(KUidSystemCategory, KUidPhonePwr.iUid, 1); TEST2(err, KErrPermissionDenied); err = RProperty::Set(KUidSystemCategory, KUidSIMStatus.iUid, 1); TEST2(err, KErrPermissionDenied); err = RProperty::Set(KUidSystemCategory, KUidNetworkStatus.iUid, 1); TEST2(err, KErrPermissionDenied); err = RProperty::Set(KUidSystemCategory, KUidNetworkStrength.iUid, 1); TEST2(err, KErrPermissionDenied); err = RProperty::Set(KUidSystemCategory, KUidChargerStatus.iUid, 1); TEST2(err, KErrPermissionDenied); err = RProperty::Set(KUidSystemCategory, KUidBatteryStrength.iUid, 1); TEST2(err, KErrPermissionDenied); err = RProperty::Set(KUidSystemCategory, KUidCurrentCall.iUid, 1); TEST2(err, KErrPermissionDenied); } TheTest.Next(_L("Capability test 2")); //If all 48 predefined properties were registered successfully (by SysAgent server), //the test must be able to read their values. const TInt KPropertyCount = 48; TUid saUid = TUid::Uid(KUidPhonePwrValue); for(TInt i=0;i<KPropertyCount;++i) { TInt val = 0; err = RProperty::Get(KUidSystemCategory, saUid.iUid, val); TEST2(err, KErrNone); ++saUid.iUid; } TheTest.Next(_L("Other defined Properties test")); // This test checks that the other publish and subscribe properties // have been defined by SystemAgent2. These are properties which are used // in other subsystems, mainly defined by this component due to PlatSec // restrictions requiring WriteUserData to define a property. for (TInt i=0; i < sizeof(KSaExternalKeys) / sizeof(KSaExternalKeys[0]); ++i) { if(KSaExternalKeys[i].iIsInt) { TInt propertyValue=0; err = RProperty::Get(KSaExternalKeys[i].iCategory, KSaExternalKeys[i].iProperty, propertyValue); } else { TBuf8<512> propertyValue; err = RProperty::Get(KSaExternalKeys[i].iCategory, KSaExternalKeys[i].iProperty, propertyValue); } // We expect the property to be defined, but we cannot make any assumptions // about what value it will have since it could have been changed before // the test gets here. TEST(err==KErrNone); } }
int SetupHelperApp::OnRun() { #ifdef _WIN64 DBG("--- x64 SetupHelper"); #else DBG("--- x86 SetupHelper"); #endif if (__argc < 3) return -1; std::vector<ProcessInfo> processes; DBG("Get processes (1)"); if (!GetProcesses(processes)) return -1; DBG("Got processes (1):"); for (size_t i = 0; i < processes.size(); ++i) { DBG(i << ": " << processes[i].pid); } // Kill all Explorer and cvslock processes for (size_t i = 0; i < processes.size(); ++i) { if (!_tcsicmp(processes[i].image.c_str(), wxT("explorer.exe"))) { DBG("Killing Explorer"); // Show dialog wxProgressDialog* dlg = new wxProgressDialog(wxT("TortoiseCVS Setup"), wxText(__argv[1])); dlg->Show(); // Kill Explorer TerminateProcess(processes[i]); int i = 0; while (IsProcessRunning(processes[i].pid) && (i < 50)) { dlg->Update((i+1)*100/50); Sleep(50); } // Avoid the Active Desktop error message HKEY hKey; if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer", 0, KEY_WRITE, &hKey)) { DWORD data = 0; RegSetValueExA(hKey, "FaultKey", 0, REG_DWORD, reinterpret_cast<BYTE*>(&data), sizeof(DWORD)); } dlg->Destroy(); } else if (!_tcsicmp(processes[i].image.c_str(), wxT("cvslock.exe"))) { // Kill CVSNT lock service TerminateProcess(processes[i]); } } // Show dialog wxProgressDialog* dlg = new wxProgressDialog(wxT("TortoiseCVS Setup"), wxText(__argv[1])); dlg->Show(); // Wait for Explorer restart for (int i = 0; i < 50; ++i) { if (IsExplorerRunning()) break; dlg->Update((i+1)*100/50); Sleep(50); } if (!IsExplorerRunning()) { dlg->Update(0); STARTUPINFOA startupinfo; startupinfo.cb = sizeof(STARTUPINFOA); startupinfo.lpReserved = 0; startupinfo.lpDesktop = 0; startupinfo.lpTitle = 0; startupinfo.dwFlags = 0; startupinfo.cbReserved2 = 0; startupinfo.lpReserved2 = 0; PROCESS_INFORMATION processinfo; CreateProcessA(0, "explorer.exe", 0, 0, FALSE, 0, 0, 0, &startupinfo, &processinfo); CloseHandle(processinfo.hProcess); CloseHandle(processinfo.hThread); for (int i = 0; i < 10; ++i) { Sleep(50); dlg->Update((i+1)*100/10); } } dlg->Destroy(); DBG("Check remaining processes"); bool anyLeft = true; while (anyLeft) { processes.clear(); DBG("Get processes (2)"); if (!GetProcesses(processes)) return -1; DBG("Got processes (2):"); for (size_t i = 0; i < processes.size(); ++i) { DBG(i << ": " << processes[i].pid); } anyLeft = false; for (size_t i = 0; i < processes.size(); ++i) { if (_tcsicmp(processes[i].image.c_str(), wxT("explorer.exe"))) { anyLeft = true; // Ask user to close application wxString msg; msg << wxT("The application "); if (processes[i].title.empty()) { // No title found (may be minimized to tray etc.) msg << processes[i].image; } else msg << wxT("'") << processes[i].title << wxT("' (") << processes[i].image << wxT(")"); msg << wxT("\nneeds to be closed before TortoiseCVS setup can continue.\n") << wxT("Please close the application and click OK, or click Cancel to leave the process ") << wxT("running.\nIn the latter case, you will be required to reboot Windows after installation."); if (MessageBox(0, msg.c_str(), wxT("TortoiseCVS Setup"), MB_OKCANCEL | MB_ICONINFORMATION) == IDCANCEL) return 1; } } } DBG("Loop done"); if (__argv[2][0] == 'b') return 0; // Delete any renamed DLL's // TODO: Make this work even when installing to a different directory std::string rootDir(GetRootDir()); std::string src(rootDir); src += "TortoiseShell.dll_renamed"; DBG("Deleting " << src); DeleteFileA(src.c_str()); src = rootDir; src += "TortoiseShell64.dll_renamed"; DBG("Deleting " << src); DeleteFileA(src.c_str()); src = rootDir; src += "TortoiseAct.exe_renamed"; DBG("Deleting " << src); DeleteFileA(src.c_str()); DBG("Exit: 0"); return 0; }
void CLauncherDialog::OnBnClickedOk() { CString ipAddress; CString port; CString password; CString nick; GetDlgItemText(IDC_EDIT1, ipAddress); if(ipAddress.IsEmpty()) { MessageBox("No ip address entered."); return; } GetDlgItemText(IDC_EDIT2, port); if(port.IsEmpty()) { MessageBox("No port entered."); return; } GetDlgItemText(IDC_EDIT3, password); GetDlgItemText(IDC_EDIT4, nick); if(nick.IsEmpty()) { MessageBox("No nick entered."); return; } // Get the GTA IV install directory from the registry char szInstallDirectory[MAX_PATH]; bool bFoundCustomDirectory = false; if(!SharedUtility::ReadRegistryString(HKEY_LOCAL_MACHINE, "Software\\Rockstar Games\\Grand Theft Auto IV", "InstallFolder", NULL, szInstallDirectory, sizeof(szInstallDirectory)) || !SharedUtility::Exists(szInstallDirectory)) { if(!SharedUtility::ReadRegistryString(HKEY_CURRENT_USER, "Software\\NIV", "gtaivdir", NULL, szInstallDirectory, sizeof(szInstallDirectory)) || !SharedUtility::Exists(szInstallDirectory)) { if(ShowMessageBox("Failed to retrieve GTA IV install directory from registry. Specify your GTA IV path now?", (MB_ICONEXCLAMATION | MB_OKCANCEL)) == IDOK) { // Taken from http://vcfaq.mvps.org/sdk/20.htm BROWSEINFO browseInfo = { 0 }; browseInfo.lpszTitle = "Pick a Directory"; ITEMIDLIST * pItemIdList = SHBrowseForFolder(&browseInfo); if(pItemIdList != NULL) { // Get the name of the selected folder if(SHGetPathFromIDList(pItemIdList, szInstallDirectory)) bFoundCustomDirectory = true; // Free any memory used IMalloc * pIMalloc = 0; if(SUCCEEDED(SHGetMalloc(&pIMalloc))) { pIMalloc->Free(pItemIdList); pIMalloc->Release(); } } } if(!bFoundCustomDirectory) { ShowMessageBox("Failed to retrieve GTA IV install directory from registry. Cannot launch Networked: IV."); return; } } } // Get the full path to LaunchGTAIV.exe String strApplicationPath("%s\\LaunchGTAIV.exe", szInstallDirectory); // Check if LaunchGTAIV.exe exists if(!SharedUtility::Exists(strApplicationPath.Get())) { ShowMessageBox("Failed to find LaunchGTAIV.exe. Cannot launch Networked: IV."); return; } // If we have a custom directory save it if(bFoundCustomDirectory) SharedUtility::WriteRegistryString(HKEY_CURRENT_USER, "Software\\NIV", "gtaivdir", szInstallDirectory, strlen(szInstallDirectory)); // Format the command line params String strParams("\"%s\" -ip %s -port %s -nick %s", strApplicationPath.Get(), ipAddress, port, nick); // Do we have a password? if(!password.IsEmpty()) { // Append it to the command line params strParams += " -password"; strParams += password; } // Save the edit box values SaveInfo(); // Get the full path of the client core String strClientCore("%s" CLIENT_CORE_NAME DEBUG_SUFFIX ".dll", SharedUtility::GetAppPath()); // Check if the client core exists if(!SharedUtility::Exists(strClientCore.Get())) { ShowMessageBox("Failed to find " CLIENT_CORE_NAME DEBUG_SUFFIX ".dll. Cannot launch Networked: IV."); return; } // Get the full path of the launch helper String strLaunchHelper("%s" CLIENT_LAUNCH_HELPER_NAME DEBUG_SUFFIX ".dll", SharedUtility::GetAppPath()); // Check if the launch helper exists if(!SharedUtility::Exists(strLaunchHelper.Get())) { ShowMessageBox("Failed to find " CLIENT_LAUNCH_HELPER_NAME DEBUG_SUFFIX ".dll. Cannot launch Networked: IV."); return; } // Check if LaunchGTAIV.exe is already running if(IsProcessRunning("LaunchGTAIV.exe")) { ShowMessageBox("LaunchGTAIV.exe is already running. Cannot launch Networked: IV."); return; } // Check if GTAIV.exe is already running if(IsProcessRunning("GTAIV.exe")) { ShowMessageBox("GTAIV.exe is already running. Cannot launch Networked: IV."); return; } // Start LaunchGTAIV.exe STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if(!CreateProcess(strApplicationPath.Get(), strParams.GetData(), NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, SharedUtility::GetAppPath(), &siStartupInfo, &piProcessInfo)) { ShowMessageBox("Failed to start LaunchGTAIV.exe. Cannot launch Networked: IV."); return; } // Inject LauncherLibrary.dll into LaunchGTAIV.exe int iReturn = SharedUtility::InjectLibraryIntoProcess(piProcessInfo.hProcess, strLaunchHelper.Get()); // Did the injection fail? if(iReturn > 0) { // Terminate the process TerminateProcess(piProcessInfo.hProcess, 0); // Show the error message String strError("Unknown error. Cannot launch Networked: IV."); if(iReturn == 1) strError = "Failed to write library path into remote process. Cannot launch Networked: IV."; else if(iReturn == 2) strError = "Failed to create remote thread in remote process. Cannot launch Networked: IV."; else if(iReturn == 3) strError = "Failed to open the remote process, Cannot launch Networked: IV."; ShowMessageBox(strError.Get()); return; } // Resume the LaunchGTAIV.exe thread ResumeThread(piProcessInfo.hThread); }