bool uninstall_kernelkit() { char szInstallPath[MAX_PATH], szSysDir[MAX_PATH]; GetSystemDirectory(szSysDir, sizeof(szSysDir)); sprintf(szInstallPath, "%s\\%s", szSysDir, driverfilename); if (!uninstall_service((char *)drivername)) return FALSE; if (!delete_file(szInstallPath)) return FALSE; return TRUE; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { char exe_file_name[MAX_PATH], dir[MAX_PATH], *ptr; static struct WSAData wsa_state; ghInst=hInstance; GetModuleFileName(0, exe_file_name, MAX_PATH); /* set current directory */ strcpy(dir, exe_file_name); ptr=strrchr(dir, '\\'); /* last backslash */ if(ptr) ptr[1]='\0'; /* truncate program name */ if(!SetCurrentDirectory(dir)) { MessageBox(hwnd, "Cannot set current directory", options.win32_name, MB_ICONERROR); return 1; } /* setup service_path for CreateService() */ strcpy(service_path, "\""); strcat(service_path, exe_file_name); strcat(service_path, "\" -service"); /* strcat(service_path, lpszCmdLine); */ if(WSAStartup(0x0101, &wsa_state)) { win_log("Failed to initialize winsock"); error_mode=1; } if(!strcmpi(lpszCmdLine, "-service")) { if(!setjmp(jump_buf)) main_initialize(NULL, NULL); return start_service(); /* Always start service with -service option */ } if(!error_mode && !setjmp(jump_buf)) { /* TRY */ if(!strcmpi(lpszCmdLine, "-install")) { main_initialize(NULL, NULL); return install_service(); } else if(!strcmpi(lpszCmdLine, "-uninstall")) { main_initialize(NULL, NULL); return uninstall_service(); } else { /* not -service, -install or -uninstall */ main_initialize(lpszCmdLine[0] ? lpszCmdLine : NULL, NULL); } } /* CATCH */ return win_main(hInstance, hPrevInstance, lpszCmdLine, nCmdShow); }
/** * @brief * @param * @see * @remarks * @code * @endcode * @return */ scm_context::~scm_context() { if(INVALID_HANDLE_VALUE != _driver_handle) { CloseHandle(_driver_handle); _driver_handle = INVALID_HANDLE_VALUE; } if (true == _uninstall_service_on_free) { stop_service(); uninstall_service(); } }
int _tmain( int argc, TCHAR *argv[] ) { // LPCTSTR service_name = _T("hindsight"); TCHAR *service_name = _T("hindsight"); if ( argc == 1 ) return run_service( service_name ); if ( lstrcmpi(argv[1], TEXT("install")) == 0 ) { return install_service( service_name ); } if ( lstrcmpi(argv[1], TEXT("start")) == 0 ) { return start_service( service_name ); } if ( lstrcmpi(argv[1], TEXT("stop")) == 0 ) { return stop_service( service_name ); } if ( lstrcmpi(argv[1], TEXT("uninstall")) == 0 ) { return uninstall_service( service_name ); } return -1; }
// WinMain parses the command line and either calls the main App // routine or, under NT, the main service routine. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { if (VNCOS.OS_NOTSUPPORTED==true) { MessageBoxSecure(NULL, "Error OS not supported","Unsupported OS", MB_ICONERROR); return true; } // make vnc last service to stop SetProcessShutdownParameters(0x100,false); // handle dpi on aero /*HMODULE hUser32 = LoadLibrary(_T("user32.dll")); typedef BOOL (*SetProcessDPIAwareFunc)(); SetProcessDPIAwareFunc setDPIAware=NULL; if (hUser32) setDPIAware = (SetProcessDPIAwareFunc)GetProcAddress(hUser32, "SetProcessDPIAware"); if (setDPIAware) setDPIAware(); if (hUser32) FreeLibrary(hUser32);*/ #ifdef IPP InitIpp(); #endif #ifdef CRASHRPT CR_INSTALL_INFO info; memset(&info, 0, sizeof(CR_INSTALL_INFO)); info.cb = sizeof(CR_INSTALL_INFO); info.pszAppName = _T("UVNC"); info.pszAppVersion = _T("1.2.0.9"); info.pszEmailSubject = _T("UVNC server 1.2.0.9 Error Report"); info.pszEmailTo = _T("*****@*****.**"); info.uPriorities[CR_SMAPI] = 1; // Third try send report over Simple MAPI // Install all available exception handlers info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Restart the app on crash info.dwFlags |= CR_INST_APP_RESTART; info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS; info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; info.pszRestartCmdLine = _T("/restart"); // Define the Privacy Policy URL // Install crash reporting int nResult = crInstall(&info); if (nResult != 0) { // Something goes wrong. Get error message. TCHAR szErrorMsg[512] = _T(""); crGetLastErrorMsg(szErrorMsg, 512); _tprintf_s(_T("%s\n"), szErrorMsg); return 1; } #endif bool Injected_autoreconnect=false; SPECIAL_SC_EXIT=false; SPECIAL_SC_PROMPT=false; setbuf(stderr, 0); // [v1.0.2-jp1 fix] Load resouce from dll hInstResDLL = NULL; //limit the vnclang.dll searchpath to avoid char szCurrentDir[MAX_PATH]; char szCurrentDir_vnclangdll[MAX_PATH]; if (GetModuleFileName(NULL, szCurrentDir, MAX_PATH)) { char* p = strrchr(szCurrentDir, '\\'); *p = '\0'; } strcpy (szCurrentDir_vnclangdll,szCurrentDir); strcat (szCurrentDir_vnclangdll,"\\"); strcat (szCurrentDir_vnclangdll,"vnclang_server.dll"); hInstResDLL = LoadLibrary(szCurrentDir_vnclangdll); if (hInstResDLL == NULL) { hInstResDLL = hInstance; } // RegisterLinkLabel(hInstResDLL); //Load all messages from ressource file Load_Localization(hInstResDLL) ; char WORKDIR[MAX_PATH]; if (GetModuleFileName(NULL, WORKDIR, MAX_PATH)) { char* p = strrchr(WORKDIR, '\\'); if (p == NULL) return 0; *p = '\0'; } char progname[MAX_PATH]; strncpy(progname, WORKDIR, sizeof progname); progname[MAX_PATH - 1] = 0; //strcat(WORKDIR,"\\"); //strcat(WORKDIR,"WinVNC.log"); vnclog.SetFile(); //vnclog.SetMode(4); //vnclog.SetLevel(10); #ifdef _DEBUG { // Get current flag int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); // Turn on leak-checking bit tmpFlag |= _CRTDBG_LEAK_CHECK_DF; // Set flag to the new value _CrtSetDbgFlag( tmpFlag ); } #endif // Save the application instance and main thread id hAppInstance = hInstance; mainthreadId = GetCurrentThreadId(); // Initialise the VSocket system VSocketSystem socksys; if (!socksys.Initialised()) { MessageBoxSecure(NULL, sz_ID_FAILED_INIT, szAppName, MB_OK); #ifdef CRASHRPT crUninstall(); #endif return 0; } // look up the current service name in the registry. GetServiceName(progname, service_name); // Make the command-line lowercase and parse it size_t i; for (i = 0; i < strlen(szCmdLine); i++) { szCmdLine[i] = tolower(szCmdLine[i]); } BOOL argfound = FALSE; for (i = 0; i < strlen(szCmdLine); i++) { if (szCmdLine[i] <= ' ') continue; argfound = TRUE; if (strncmp(&szCmdLine[i], winvncSettingshelper, strlen(winvncSettingshelper)) == 0) { Sleep(3000); char mycommand[MAX_PATH]; i+=strlen(winvncSettingshelper); strcpy( mycommand, &(szCmdLine[i+1])); Set_settings_as_admin(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStopserviceHelper, strlen(winvncStopserviceHelper)) == 0) { Sleep(3000); Set_stop_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncKill, strlen(winvncKill)) == 0) { static HANDLE hShutdownEventTmp; hShutdownEventTmp = OpenEvent(EVENT_ALL_ACCESS, FALSE, "Global\\SessionEventUltra"); SetEvent(hShutdownEventTmp); CloseHandle(hShutdownEventTmp); //adzm 2010-02-10 - Finds the appropriate VNC window for any process. Sends this message to all of them! // do removed, loops forever with cpu 100 HWND hservwnd = NULL; hservwnd = FindWinVNCWindow(false); if (hservwnd!=NULL) { PostMessage(hservwnd, WM_COMMAND, 40002, 0); PostMessage(hservwnd, WM_CLOSE, 0, 0); } #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncopenhomepage, strlen(winvncopenhomepage)) == 0) { Open_homepage(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncopenforum, strlen(winvncopenforum)) == 0) { Open_forum(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStartserviceHelper, strlen(winvncStartserviceHelper)) == 0) { Sleep(3000); Set_start_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncInstallServiceHelper, strlen(winvncInstallServiceHelper)) == 0) { //Sleeps are realy needed, else runas fails... Sleep(3000); Set_install_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncUnInstallServiceHelper, strlen(winvncUnInstallServiceHelper)) == 0) { Sleep(3000); Set_uninstall_service_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSoftwarecadHelper, strlen(winvncSoftwarecadHelper)) == 0) { Sleep(3000); Enable_softwareCAD_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncdelSoftwarecadHelper, strlen(winvncdelSoftwarecadHelper)) == 0) { Sleep(3000); delete_softwareCAD_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootSafeHelper, strlen(winvncRebootSafeHelper)) == 0) { Sleep(3000); Reboot_in_safemode_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootForceHelper, strlen(winvncRebootForceHelper)) == 0) { Sleep(3000); Reboot_with_force_reboot_elevated(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSecurityEditorHelper, strlen(winvncSecurityEditorHelper)) == 0) { Sleep(3000); winvncSecurityEditorHelper_as_admin(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSecurityEditor, strlen(winvncSecurityEditor)) == 0) { typedef void (*vncEditSecurityFn) (HWND hwnd, HINSTANCE hInstance); vncEditSecurityFn vncEditSecurity = 0; char szCurrentDirl[MAX_PATH]; if (GetModuleFileName(NULL, szCurrentDirl, MAX_PATH)) { char* p = strrchr(szCurrentDirl, '\\'); *p = '\0'; strcat (szCurrentDirl,"\\authSSP.dll"); } HMODULE hModule = LoadLibrary(szCurrentDirl); if (hModule) { vncEditSecurity = (vncEditSecurityFn) GetProcAddress(hModule, "vncEditSecurity"); HRESULT hr = CoInitialize(NULL); vncEditSecurity(NULL, hAppInstance); CoUninitialize(); FreeLibrary(hModule); } #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSettings, strlen(winvncSettings)) == 0) { char mycommand[MAX_PATH]; i+=strlen(winvncSettings); strcpy( mycommand, &(szCmdLine[i+1])); Real_settings(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], dsmpluginhelper, strlen(dsmpluginhelper)) == 0) { char mycommand[MAX_PATH]; i += strlen(dsmpluginhelper); strcpy(mycommand, &(szCmdLine[i + 1])); Secure_Plugin_elevated(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], dsmplugininstance, strlen(dsmplugininstance)) == 0) { char mycommand[MAX_PATH]; i += strlen(dsmplugininstance); strcpy(mycommand, &(szCmdLine[i + 1])); Secure_Plugin(mycommand); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncSoftwarecad, strlen(winvncSoftwarecad)) == 0) { Enable_softwareCAD(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncdelSoftwarecad, strlen(winvncdelSoftwarecad)) == 0) { delete_softwareCAD(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootSafe, strlen(winvncRebootSafe)) == 0) { Reboot_in_safemode(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRebootForce, strlen(winvncRebootForce)) == 0) { Reboot_with_force_reboot(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStopservice, strlen(winvncStopservice)) == 0) { Real_stop_service(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncStartservice, strlen(winvncStartservice)) == 0) { Real_start_service(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncInstallService, strlen(winvncInstallService)) == 0) { // rest of command line service name, if provided. char *pServiceName = &szCmdLine[i]; // skip over command switch, find next whitepace while (*pServiceName && !isspace(*(unsigned char*)pServiceName)) ++pServiceName; // skip past whitespace to service name while (*pServiceName && isspace(*(unsigned char*)pServiceName)) ++pServiceName; // strip off any quotes if (*pServiceName && *pServiceName == '\"') ++pServiceName; if (*pServiceName) { // look for trailing quote, if found, terminate the string there. char *pQuote = pServiceName; pQuote = strrchr(pServiceName, '\"'); if (pQuote) *pQuote = 0; } // if a service name is supplied, and it differs except in case from // the default, use the supplied service name instead if (*pServiceName && (_strcmpi(pServiceName, service_name) != 0)) { strncpy(service_name, pServiceName, 256); service_name[255] = 0; } install_service(); Sleep(2000); char command[MAX_PATH + 32]; // 29 January 2008 jdp _snprintf(command, sizeof command, "net start \"%s\"", service_name); WinExec(command,SW_HIDE); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncUnInstallService, strlen(winvncUnInstallService)) == 0) { char command[MAX_PATH + 32]; // 29 January 2008 jdp // rest of command line service name, if provided. char *pServiceName = &szCmdLine[i]; // skip over command switch, find next whitepace while (*pServiceName && !isspace(*(unsigned char*)pServiceName)) ++pServiceName; // skip past whitespace to service name while (*pServiceName && isspace(*(unsigned char*)pServiceName)) ++pServiceName; // strip off any quotes if (*pServiceName && *pServiceName == '\"') ++pServiceName; if (*pServiceName) { // look for trailing quote, if found, terminate the string there. char *pQuote = pServiceName; pQuote = strrchr(pServiceName, '\"'); if (pQuote) *pQuote = 0; } if (*pServiceName && (_strcmpi(pServiceName, service_name) != 0)) { strncpy(service_name, pServiceName, 256); service_name[255] = 0; } _snprintf(command, sizeof command, "net stop \"%s\"", service_name); WinExec(command,SW_HIDE); uninstall_service(); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRunService, strlen(winvncRunService)) == 0) { //Run as service if (!Myinit(hInstance)) return 0; fRunningFromExternalService = true; vncService::RunningFromExternalService(true); int returnvalue = WinVNCAppMain(); #ifdef CRASHRPT crUninstall(); #endif return returnvalue; } if (strncmp(&szCmdLine[i], winvncStartService, strlen(winvncStartService)) == 0) { start_service(szCmdLine); #ifdef CRASHRPT crUninstall(); #endif return 0; } if (strncmp(&szCmdLine[i], winvncRunAsUserApp, strlen(winvncRunAsUserApp)) == 0) { // WinVNC is being run as a user-level program if (!Myinit(hInstance)) return 0; int returnvalue = WinVNCAppMain(); #ifdef CRASHRPT crUninstall(); #endif return returnvalue; } if (strncmp(&szCmdLine[i], winvncSCexit, strlen(winvncSCexit)) == 0) { SPECIAL_SC_EXIT=true; i+=strlen(winvncSCexit); continue; } if (strncmp(&szCmdLine[i], winvncSCprompt, strlen(winvncSCprompt)) == 0) { SPECIAL_SC_PROMPT=true; i+=strlen(winvncSCprompt); continue; } if (strncmp(&szCmdLine[i], winvncmulti, strlen(winvncmulti)) == 0) { multi=true; i+=strlen(winvncmulti); continue; } if (strncmp(&szCmdLine[i], winvnchttp, strlen(winvnchttp)) == 0) { G_HTTP=true; i+=strlen(winvnchttp); continue; } if (strncmp(&szCmdLine[i], winvncStopReconnect, strlen(winvncStopReconnect)) == 0) { i+=strlen(winvncStopReconnect); vncService::PostAddStopConnectClientAll(); continue; } if (strncmp(&szCmdLine[i], winvncAutoReconnect, strlen(winvncAutoReconnect)) == 0) { // Note that this "autoreconnect" param MUST be BEFORE the "connect" one // on the command line ! // wa@2005 -- added support for the AutoReconnectId i+=strlen(winvncAutoReconnect); Injected_autoreconnect=true; int start, end; char* pszId = NULL; start = i; // skip any spaces and grab the parameter while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++; if ( strncmp( &szCmdLine[start], winvncAutoReconnectId, strlen(winvncAutoReconnectId) ) == 0 ) { end = start; while (szCmdLine[end] > ' ') end++; if (end - start > 0) { pszId = new char[end - start + 1]; strncpy(pszId, &(szCmdLine[start]), end - start); pszId[end - start] = 0; pszId = _strupr(pszId); } //multiple spaces between autoreconnect and id i = end; }// end of condition we found the ID: parameter // NOTE: id must be NULL or the ID:???? (pointer will get deleted when message is processed) // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started if (!vncService::PostAddAutoConnectClient( pszId )) { PostAddAutoConnectClient_bool=true; if (pszId==NULL) { PostAddAutoConnectClient_bool_null=true; PostAddAutoConnectClient_bool=false; } else { strcpy(pszId_char,pszId); //memory leak fix delete[] pszId; pszId = NULL; } } if (pszId != NULL) delete[] pszId; pszId = NULL; continue; } if ( strncmp( &szCmdLine[i], winvncReconnectId, strlen(winvncReconnectId) ) == 0 ) { i+=strlen("-"); int start, end; char* pszId = NULL; start = i; end = start; while (szCmdLine[end] > ' ') end++; if (end - start > 0) { pszId = new char[end - start + 1]; if (pszId != 0) { strncpy(pszId, &(szCmdLine[start]), end - start); pszId[end - start] = 0; pszId = _strupr(pszId); } } i = end; if (!vncService::PostAddConnectClient( pszId )) { PostAddConnectClient_bool=true; if (pszId==NULL) { PostAddConnectClient_bool_null=true; PostAddConnectClient_bool=false; } else { strcpy(pszId_char,pszId); //memory leak fix delete[] pszId; pszId = NULL; } } if (pszId != NULL) delete[] pszId; pszId = NULL; continue; } if (strncmp(&szCmdLine[i], winvncConnect, strlen(winvncConnect)) == 0) { if (!Injected_autoreconnect) { vncService::PostAddStopConnectClient(); } // Add a new client to an existing copy of winvnc i+=strlen(winvncConnect); // First, we have to parse the command line to get the filename to use int start, end; start=i; while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++; end = start; while (szCmdLine[end] > ' ') end++; // Was there a hostname (and optionally a port number) given? if (end-start > 0) { char *name = new char[end-start+1]; if (name != 0) { strncpy(name, &(szCmdLine[start]), end-start); name[end-start] = 0; int port = INCOMING_PORT_OFFSET; char *portp = strchr(name, ':'); if (portp) { *portp++ = '\0'; if (*portp == ':') { port = atoi(++portp); // Port number after "::" } else { port = atoi(portp); // Display number after ":" } } vnclog.Print(LL_STATE, VNCLOG("test... %s %d\n"),name,port); strcpy_s(dnsname,name); VCard32 address = VSocket::Resolve(name); delete [] name; if (address != 0) { // Post the IP address to the server // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient III \n")); if (!vncService::PostAddNewClientInit(address, port)) { PostAddNewClient_bool=true; port_int=port; address_vcard=address; } } else { //ask for host,port PostAddNewClient_bool=true; port_int=0; address_vcard=0; Sleep(2000); //Beep(200,1000); return 0; } } i=end; continue; } else { // Tell the server to show the Add New Client dialog // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIII\n")); if (!vncService::PostAddNewClient(0, 0)) { PostAddNewClient_bool=true; port_int=0; address_vcard=0; } } continue; } //adzm 2009-06-20 if (strncmp(&szCmdLine[i], winvncRepeater, strlen(winvncRepeater)) == 0) { // set the default repeater host i+=strlen(winvncRepeater); // First, we have to parse the command line to get the host to use int start, end; start=i; while (szCmdLine[start] <= ' ' && szCmdLine[start] != 0) start++; end = start; while (szCmdLine[end] > ' ') end++; // Was there a hostname (and optionally a port number) given? if (end-start > 0) { if (g_szRepeaterHost) { delete[] g_szRepeaterHost; g_szRepeaterHost = NULL; } g_szRepeaterHost = new char[end-start+1]; if (g_szRepeaterHost != 0) { strncpy(g_szRepeaterHost, &(szCmdLine[start]), end-start); g_szRepeaterHost[end-start] = 0; // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewRepeaterClient I\n")); if (!vncService::PostAddNewRepeaterClient()) { PostAddNewRepeaterClient_bool=true; port_int=0; address_vcard=0; } } i=end; continue; } else { /* // Tell the server to show the Add New Client dialog // We can not contact a runnning service, permissions, so we must store the settings // and process until the vncmenu has been started vnclog.Print(LL_INTERR, VNCLOG("PostAddNewClient IIII\n")); if (!vncService::PostAddNewClient(0, 0)) { PostAddNewClient_bool=true; port_int=0; address_vcard=0; } */ } continue; } // Either the user gave the -help option or there is something odd on the cmd-line! // Show the usage dialog MessageBoxSecure(NULL, winvncUsageText, sz_ID_WINVNC_USAGE, MB_OK | MB_ICONINFORMATION); break; }; // If no arguments were given then just run if (!argfound) { if (!Myinit(hInstance)) { #ifdef CRASHRPT crUninstall(); #endif return 0; } int returnvalue= WinVNCAppMain(); #ifdef CRASHRPT crUninstall(); #endif return returnvalue; } #ifdef CRASHRPT crUninstall(); #endif return 0; }
int uninstall_service(void) { SC_HANDLE scm, service; SERVICE_STATUS serviceStatus; scm=OpenSCManager(0, 0, SC_MANAGER_CONNECT); if(!scm) { MessageBoxSecure(NULL, "Failed to open service control manager", app_name, MB_ICONERROR); return 1; } service=OpenService(scm, service_name, SERVICE_QUERY_STATUS | DELETE); if(!service) { DWORD myerror=GetLastError(); if (myerror==ERROR_ACCESS_DENIED) { MessageBoxSecure(NULL, "Failed: Permission denied", app_name, MB_ICONERROR); CloseServiceHandle(scm); return 1; } if (myerror==ERROR_SERVICE_DOES_NOT_EXIST) { #if 0 MessageBoxSecure(NULL, "Failed: Service is not installed", app_name, MB_ICONERROR); #endif CloseServiceHandle(scm); return 1; } MessageBoxSecure(NULL, "Failed to open the service", app_name, MB_ICONERROR); CloseServiceHandle(scm); return 1; } if(!QueryServiceStatus(service, &serviceStatus)) { MessageBoxSecure(NULL, "Failed to query service status", app_name, MB_ICONERROR); CloseServiceHandle(service); CloseServiceHandle(scm); return 1; } if(serviceStatus.dwCurrentState!=SERVICE_STOPPED) { //MessageBoxSecure(NULL, "The service is still running, disable it first", // "UltraVnc", MB_ICONERROR); CloseServiceHandle(service); CloseServiceHandle(scm); Sleep(2500);uninstall_service(); return 1; } if(!DeleteService(service)) { MessageBoxSecure(NULL, "Failed to delete the service", app_name, MB_ICONERROR); CloseServiceHandle(service); CloseServiceHandle(scm); return 1; } CloseServiceHandle(service); CloseServiceHandle(scm); return 0; }
int main(int argc, char **argv) { _gc = new GlobalConfig; #ifdef WIN32 _verbase = false; if (argc == 2 && strcmp(argv[1], "/install") == 0) { return install_service(argv[0]); } if (argc == 2 && strcmp(argv[1], "/uninstall") == 0) { return uninstall_service(argv[0]); } if (argc == 2 && strcmp(argv[1], "/debug") == 0) { _verbase = true; } // if (argc == 1) // _verbase = true; #if LICENSE int lcs_chk = el_init("zonekey_mcu.lcs"); if (lcs_chk == -1) { fprintf(stderr, "ERR: license check error\n"); return -1; } else if (lcs_chk == -2) { fprintf(stderr, "ERR: license timeout\n"); return -2; } const char *feathers = el_getfeatures(); KVS fs = parse_feathers(feathers); // TODO: 检查是否限制同时启动的数目 ... KVS::const_iterator itf = fs.find("cap_max"); if (itf != fs.end()) { _gc->cap_max = atoi(itf->second.c_str()); if (_gc->cap_max == 0) _gc->cap_max = 1; } #endif // HANDLE env = OpenEvent(EVENT_MODIFY_STATE, 0, GLOBAL_NAME); if (env) { fprintf(stderr, "zonekey_mcu: only one instance running\n"); CloseHandle(env); return -1; } else { env = CreateEvent(0, 0, 0, GLOBAL_NAME); _global_obj = env; if (!_verbase) { SERVICE_TABLE_ENTRY ServiceTable[] = { { SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)mainp }, { 0, 0 }, }; // 启动服务的控制分派机线程,这个将直到服务结束后,返回 StartServiceCtrlDispatcher(ServiceTable); return 0; } else { mainp(argc, argv); return 0; } } #else // // linux mainp(argc, argv); return 0; #endif // }