예제 #1
0
/*
	メインダイアログ用 WM_COMMAND 処理ルーチン
*/
BOOL TInstDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl)
{
	switch (wID) {
	case IDOK:
		propertySheet->GetData();
		if (cfg.mode == UNINSTALL_MODE)
			UnInstall();
		else
			Install();
		return	TRUE;

	case IDCANCEL:
		::PostQuitMessage(0);
		return	TRUE;

	case FILE_BUTTON:
		BrowseDirDlg(this, FILE_EDIT, "Select Install Directory");
		return	TRUE;

	case SETUP_RADIO:
	case UNINSTALL_RADIO:
		if (wNotifyCode == BN_CLICKED)
			ChangeMode();
		return	TRUE;
	}
	return	FALSE;
}
예제 #2
0
파일: HelixSvc.cpp 프로젝트: smc314/helix
VOID ServiceMainProc()
{
	::InitializeCriticalSection(&myCS);
	// initialize variables for .exe and .log file names
	char pModuleFile[nBufferSize+1];
	DWORD dwSize = GetModuleFileName(NULL, pModuleFile, nBufferSize);
	pModuleFile[dwSize] = 0;
	if(dwSize>4 && pModuleFile[dwSize-4] == '.')
	{
		sprintf_s(pExeFile,"%s",pModuleFile);
		pModuleFile[dwSize-4] = 0;
		sprintf_s(pLogFile,"%s.log",pModuleFile);

		sprintf_s(pWorkDir,"%s",pModuleFile);
		PathRemoveFileSpec(pWorkDir);
	}

	strcpy_s(pServiceName,"Helix");

	if(_stricmp("-i",lpCmdLineData) == 0 || _stricmp("-I",lpCmdLineData) == 0)
		Install(pExeFile, pServiceName);
	else if(_stricmp("-k",lpCmdLineData) == 0 || _stricmp("-K",lpCmdLineData) == 0)
		KillService(pServiceName);
	else if(_stricmp("-u",lpCmdLineData) == 0 || _stricmp("-U",lpCmdLineData) == 0)
		UnInstall(pServiceName);
	else if(_stricmp("-s",lpCmdLineData) == 0 || _stricmp("-S",lpCmdLineData) == 0)
		RunService(pServiceName);
	else
		ExecuteSubProcess();
}
예제 #3
0
파일: uninst.cpp 프로젝트: nianhuaxpj/ipmsg
/*
	メインダイアログ用 WM_COMMAND 処理ルーチン
*/
BOOL TUninstDlg::EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl)
{
	switch (wID)
	{
	case IDOK:
		UnInstall();
		return	TRUE;

	case IDCANCEL:
		::PostQuitMessage(0);
		return	TRUE;
	}
	return	FALSE;
}
예제 #4
0
파일: Service.cpp 프로젝트: airhigh/wdrbd
int _tmain(int argc, _TCHAR* argv[])
{
    TCHAR szPath[MAX_PATH] = { 0, };
    DWORD dwSize = GetModuleFileName(NULL, szPath, MAX_PATH);
    TCHAR * pdest = _tcsrchr(szPath, '\\');
    _tcsncpy_s(gServicePath, sizeof(gServicePath) / sizeof(TCHAR), szPath, (size_t)(pdest - szPath));

    if (argc < 2)
    {
        ExecuteSubProcess();
        return 0;
    }
    
    if (_tcsicmp(L"/i", argv[1]) == 0)
        return Install(szPath, ServiceName);
    else if (_tcsicmp(L"/k", argv[1]) == 0)
        return KillService(ServiceName);
    else if (_tcsicmp(L"/u", argv[1]) == 0)
        return UnInstall(ServiceName);
    else if (_tcsicmp(L"/s", argv[1]) == 0)
        return RunService(ServiceName);
    else if (_tcsicmp(L"/t", argv[1]) == 0)
    {
        DWORD dwPID;
        WCHAR *szServicePath;
        WCHAR *cmd = L"drbdadm.exe initial-split-brain minor-6";
        WCHAR fullName[MAX_PATH] = {0};

        size_t len;
        errno_t err = _wdupenv_s(&szServicePath, &len, L"DRBD_PATH");
        if (err)
        {
            // default
            szServicePath = L"C:\\Program Files\\drbd\\bin";
        }
        if ((wcslen(szServicePath) + wcslen(cmd) + 4) > MAX_PATH)
        {
            printf("szServicePath: too big!!\n");
        }
        wcsncpy_s(fullName, szServicePath, wcslen(szServicePath));
        wcscat_s(fullName, L"\\");
        wcsncat_s(fullName, cmd, wcslen(cmd)); //wnsprintf
        printf("fullName: %ws\n", fullName);

        // test!
        DWORD ret = RunProcess(EXEC_MODE_WIN, SW_NORMAL, NULL, cmd, szServicePath, dwPID, 0, NULL, NULL);
        free(szServicePath);
        return ERROR_SUCCESS;
    }
#if 1 // _WIN32_HANDLER_TIMEOUT: test by a separate application, not daemon. remove later
	else if (_tcsicmp(L"/n", argv[1]) == 0) 
	{
		// internal test only: no-daemon test

		unsigned short servPort = DRBD_DAEMON_TCP_PORT;
		DWORD threadID;

		if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SockListener, &servPort, 0, (LPDWORD) &threadID) == NULL)
		{
			WriteLog(L"pthread_create() failed\n");
			return 0;
		}

		int i = 0;
		while (1)
		{
			printf("test main loop(%d)...\n", i++);
			Sleep(10000);
		}
	}
#endif
    else
    {
        TCHAR msg[256];
        _stprintf_s(msg, _T("Usage: drbdService.exe [/i|/k|/u|/s]\n"));
        WriteLog(msg);
        return ERROR_INVALID_PARAMETER;
    }

    return ERROR_SUCCESS;
}
예제 #5
0
BOOLEAN ScmDrvCtrl::Install(const TCHAR* lpszServiceName, const TCHAR* lpszDriverPath, const TCHAR* lpszAltitude, const TCHAR* lpszLink_name)
{
	SC_HANDLE hServiceMgr = NULL;
	SC_HANDLE hService = NULL;
	int i = 0;
	_tcscpy_s(m_link_name, MAX_PATH, lpszLink_name);
	if (NULL == lpszServiceName || NULL == lpszDriverPath || NULL == lpszAltitude)
	{
		return FALSE;
	}
	UnInstall(lpszServiceName);
	WIN32_FIND_DATA FindFileData;
	if (FindFirstFileW(lpszDriverPath, &FindFileData) == INVALID_HANDLE_VALUE)
	{
		return FALSE;
	}

again:
	hServiceMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if (hServiceMgr == NULL)
	{
		return FALSE;
	}
	hService = CreateService(hServiceMgr,
		lpszServiceName,				// 驱动程序的在注册表中的名字
		lpszServiceName,				// 注册表驱动程序的DisplayName 值
		SERVICE_ALL_ACCESS,				// 加载驱动程序的访问权限
		SERVICE_FILE_SYSTEM_DRIVER,		// 表示加载的服务是文件系统驱动程序
		SERVICE_DEMAND_START,			// 注册表驱动程序的Start 值
		SERVICE_ERROR_IGNORE,			// 注册表驱动程序的ErrorControl 值
		lpszDriverPath,					// 注册表驱动程序的ImagePath 值
		_T("FSFilter Activity Monitor"),// 注册表驱动程序的Group 值
		NULL,
		_T("FltMgr"),                   // 注册表驱动程序的DependOnService 值
		NULL,
		NULL);

	if (hService == NULL)
	{
		CloseServiceHandle(hServiceMgr);
		if (i > 100000)
		{
			return FALSE;
		}
		i++;
	//	printf("%d\n", i);
		goto again;
	}
	
	CloseServiceHandle(hService);       // 服务句柄
	CloseServiceHandle(hServiceMgr);    // SCM句柄

	TCHAR		szTempStr[MAX_PATH];
	HKEY		hKey = NULL;
	DWORD		dwData = 0;

	_tcscpy_s(szTempStr, MAX_PATH, _T("SYSTEM\\CurrentControlSet\\Services\\"));
	_tcscat_s(szTempStr, MAX_PATH, lpszServiceName);

	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szTempStr, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, (LPDWORD)&dwData) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	_tcscpy_s(szTempStr, MAX_PATH, lpszServiceName);
	if (RegSetValueEx(hKey, _T("service_name"), 0, REG_SZ, (CONST BYTE*)szTempStr, (DWORD)_tcslen(szTempStr)*sizeof(TCHAR)) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	//GetWindowsDirectory(szTempStr,MAX_PATH);
	//if (RegSetValueEx(hKey, _T("system_dir"), 0, REG_SZ, (CONST BYTE*)szTempStr, (DWORD)_tcslen(szTempStr)*sizeof(TCHAR)) != ERROR_SUCCESS)
	//{
	//	return FALSE;
	//}

	RegFlushKey(hKey);
	RegCloseKey(hKey);

	_tcscpy_s(szTempStr, MAX_PATH, _T("SYSTEM\\CurrentControlSet\\Services\\"));
	_tcscat_s(szTempStr, MAX_PATH, lpszServiceName);
	_tcscat_s(szTempStr, MAX_PATH, _T("\\Instances"));

	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szTempStr, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, (LPDWORD)&dwData) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	_tcscpy_s(szTempStr, MAX_PATH, lpszServiceName);
	_tcscat_s(szTempStr, MAX_PATH, _T(" Instance"));
	if (RegSetValueEx(hKey, _T("DefaultInstance"), 0, REG_SZ, (CONST BYTE*)szTempStr, (DWORD)_tcslen(szTempStr)*sizeof(TCHAR)) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	RegFlushKey(hKey);
	RegCloseKey(hKey);

	_tcscpy_s(szTempStr, MAX_PATH, _T("SYSTEM\\CurrentControlSet\\Services\\"));
	_tcscat_s(szTempStr, MAX_PATH, lpszServiceName);
	_tcscat_s(szTempStr, MAX_PATH, _T("\\Instances\\"));
	_tcscat_s(szTempStr, MAX_PATH, lpszServiceName);
	_tcscat_s(szTempStr, MAX_PATH, _T(" Instance"));
	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szTempStr, 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, (LPDWORD)&dwData) != ERROR_SUCCESS)
	{
		return FALSE;
	}

	_tcscpy_s(szTempStr, lpszAltitude);
	if (RegSetValueEx(hKey, _T("Altitude"), 0, REG_SZ, (CONST BYTE*)szTempStr, (DWORD)_tcslen(szTempStr)*sizeof(TCHAR)) != ERROR_SUCCESS)
	{
		return FALSE;
	}

	dwData = 0x0;
	if (RegSetValueEx(hKey, _T("Flags"), 0, REG_DWORD, (CONST BYTE*)&dwData, sizeof(DWORD)) != ERROR_SUCCESS)
	{
		return FALSE;
	}
	RegFlushKey(hKey);
	RegCloseKey(hKey);
	return TRUE;
}
예제 #6
0
//////////////////////////////////////////////////////////////////////
//
// Standard C Main
//
int main(int argc, char *argv[] )
{
    // initialize global critical section
    ::InitializeCriticalSection(&myCS);
    // initialize variables for .exe, .ini, and .log file names
    char pModuleFile[nBufferSize+1];
    DWORD dwSize = GetModuleFileName(NULL,pModuleFile,nBufferSize);
    pModuleFile[dwSize] = 0;
    if(dwSize>4&&pModuleFile[dwSize-4]=='.')
    {
        sprintf(pExeFile,"%s",pModuleFile);
        pModuleFile[dwSize-4] = 0;
        sprintf(pInitFile,"%s.ini",pModuleFile);
        sprintf(pLogFile,"%s.log",pModuleFile);
    }
    else
    {
        printf("Invalid module file name: %s\r\n", pModuleFile);
        return 1;
    }
    WriteLog(pExeFile);
    WriteLog(pInitFile);
    WriteLog(pLogFile);
    // read service name from .ini file
    GetPrivateProfileString("Settings","ServiceName","XYNTService",pServiceName,nBufferSize,pInitFile);
    WriteLog(pServiceName);
    // uninstall service if switch is "-u"
    if(argc==2&&_stricmp("-u",argv[1])==0)
    {
        UnInstall(pServiceName);
    }
    // install service if switch is "-i"
    else if(argc==2&&_stricmp("-i",argv[1])==0)
    {
        Install(pExeFile, pServiceName);
    }
    // bounce service if switch is "-b"
    else if(argc==2&&_stricmp("-b",argv[1])==0)
    {
        KillService(pServiceName);
        RunService(pServiceName,0,NULL);
    }
    // bounce a specifc program if the index is supplied
    else if(argc==3&&_stricmp("-b",argv[1])==0)
    {
        int nIndex = atoi(argv[2]);
        if(BounceProcess(pServiceName, nIndex))
        {
            char pTemp[121];
            sprintf(pTemp, "Bounced process %d", nIndex);
            WriteLog(pTemp);
        }
        else
        {
            char pTemp[121];
            sprintf(pTemp, "Failed to bounce process %d", nIndex);
            WriteLog(pTemp);
        }
    }
    // kill a service with given name
    else if(argc==3&&_stricmp("-k",argv[1])==0)
    {
        if(KillService(argv[2]))
        {
            char pTemp[121];
            sprintf(pTemp, "Killed service %s", argv[2]);
            WriteLog(pTemp);
        }
        else
        {
            char pTemp[121];
            sprintf(pTemp, "Failed to kill service %s", argv[2]);
            WriteLog(pTemp);
        }
    }
    // run a service with given name
    else if(argc>=3&&_stricmp("-r",argv[1])==0)
    {
        if(RunService(argv[2], argc>3?(argc-3):0,argc>3?(&(argv[3])):NULL))
        {
            char pTemp[121];
            sprintf(pTemp, "Ran service %s", argv[2]);
            WriteLog(pTemp);
        }
        else
        {
            char pTemp[121];
            sprintf(pTemp, "Failed to run service %s", argv[2]);
            WriteLog(pTemp);
        }
    }
    // assume user is starting this service
    else
    {
        // start a worker thread to check for dead programs (and restart if necessary)
        if(_beginthread(WorkerProc, 0, NULL)==-1)
        {
            long nError = GetLastError();
            char pTemp[121];
            sprintf(pTemp, "_beginthread failed, error code = %d", nError);
            WriteLog(pTemp);
        }
        // pass dispatch table to service controller
        if(!StartServiceCtrlDispatcher(DispatchTable))
        {
            long nError = GetLastError();
            char pTemp[121];
            sprintf(pTemp, "StartServiceCtrlDispatcher failed, error code = %d", nError);
            WriteLog(pTemp);
        }
        // you don't get here unless the service is shutdown
    }
    ::DeleteCriticalSection(&myCS);

    return 0;
}
예제 #7
0
void main(int argc, char* argv[])
{
    // error message
    wchar_t pTemp[121];
    unsigned int errStrSize = 120;

    // initialize global critical section
    ::InitializeCriticalSection(&gCS);

    // initialize variables for .exe, .ini, and .log file names
    wchar_t pModuleFile[nBufferSize + 1];
    DWORD dwSize = GetModuleFileName(nullptr, (LPTSTR)pModuleFile, nBufferSize);
    pModuleFile[dwSize] = 0;

    if (dwSize > 4 && pModuleFile[dwSize - 4] == '.')
    {
        swprintf(pExeFile, nBufferSize, L"%s", pModuleFile);
        pModuleFile[dwSize - 4] = 0;
        swprintf(pLogFile, nBufferSize, L"%s.log", pModuleFile);
    }
    else
    {
        printf("Invalid module file name: %ws\r\n", pModuleFile);
        return;
    }

    WriteLog(pExeFile);
    WriteLog(pLogFile);
    wcscpy_s(pServiceName, 500, L"CodeXLDriversLoadService");
    WriteLog(pServiceName);

    // uninstall service if switch is "-u"
    if (argc == 2 && _stricmp("-uninstall", argv[1]) == 0)
    {
        UnInstall(pServiceName);
    }
    // install service if switch is "-i"
    else if (argc == 2 && _stricmp("-install", argv[1]) == 0)
    {
        Install(pExeFile, pServiceName);
    }
    // stop a service with given name
    else if (argc == 2 && _stricmp("-stop", argv[1]) == 0)
    {
        if (StopService(pServiceName))
        {
            swprintf(pTemp, errStrSize, L"Stopped service %s", pServiceName);
            WriteLog(pTemp);
        }
        else
        {
            swprintf(pTemp, errStrSize, L"Failed to stop service %s", pServiceName);
            WriteLog(pTemp);
        }
    }
    // run a service with given name
    else if (argc == 2 && _stricmp("-start", argv[1]) == 0)
    {
        WriteLog(L"StartService");

        if (StartService(pServiceName, 0, nullptr))
        {
            swprintf(pTemp, errStrSize, L"Ran service %s", pServiceName);
            WriteLog(pTemp);
        }
        else
        {
            swprintf(pTemp, errStrSize, L"Failed to run service %s", pServiceName);
            WriteLog(pTemp);
        }
    }
    // assume user is starting this service
    else
    {
        // start a worker thread to load driver
        if (_beginthread(WorkerProc, 0, nullptr) == -1)
        {
            WriteErrorLog(L"_beginthread failed");
        }

        // pass dispatch table to service controller
        if (!StartServiceCtrlDispatcher(DispatchTable))
        {
            WriteErrorLog(L"StartServiceCtrlDispatcher failed");
        }

        // you don't get here unless the service is shutdown
    }

    ::DeleteCriticalSection(&gCS);
}
예제 #8
0
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		{
			HWND hwndOwner = GetDesktopWindow(); 
			RECT rc, rcDlg, rcOwner; 

			GetWindowRect(hwndOwner, &rcOwner); 
			GetWindowRect(hDlg, &rcDlg); 
			CopyRect(&rc, &rcOwner); 

			SetWindowTextA(GetDlgItem(hDlg,IDC_INSTRUCTIONS),"DropboxFilter is a program that hooks into dropbox and adds filter capabilities.\n\nThere is two ways to install it.\n\n1. AppInit Dll's\n\tThis method is a bit intrusive, anal virus scanners might detect this as a threat. But, it will not disappear when Dropbox is automatically updated.\n\n2. Piggyback start up launching.\n\tThis method will replace the dropbox system start with its own. When dropbox is automatically updated it might remove this and thereby disabling DropboxFilter without you noticing.\n\nAppInit method is recommended.");
			if(!IsElevated()) {
				Button_SetElevationRequiredState(GetDlgItem(hDlg,IDC_INSTALL_APPINIT),TRUE);
				Button_SetElevationRequiredState(GetDlgItem(hDlg,IDC_INSTALL_PIGGYBACK),TRUE);
				Button_SetElevationRequiredState(GetDlgItem(hDlg,IDC_UNINSTALL),TRUE);
			}
			// Offset the owner and dialog box rectangles so that right and bottom 
			// values represent the width and height, and then offset the owner again 
			// to discard space taken up by the dialog box. 

			OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 
			OffsetRect(&rc, -rc.left, -rc.top); 
			OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 

			// The new position is the sum of half the remaining space and the owner's 
			// original position. 

			SetWindowPos(hDlg, 
				HWND_TOP, 
				rcOwner.left + (rc.right / 2), 
				rcOwner.top + (rc.bottom / 2), 
				0, 0,          // Ignores size arguments. 
				SWP_NOSIZE);
			if(lParam) {
				if(IsElevated()) {
					PostMessage(hDlg,WM_COMMAND,lParam,0);
				} else {
					MessageBox(NULL,"Could not elevate process rights. Your user needs to have admin rights to install this program","Cant elevate",MB_OK);
				}
			}
		}
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case ID_CLOSE:
		case IDCANCEL:
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		case IDC_INSTALL_APPINIT:
			Elevate(hDlg,IDC_INSTALL_APPINIT);
			if(!Install()) {
				return TRUE;
			}
			if(!InstallAppInit()) {
				return TRUE;
			}
			MessageBoxA(NULL,"Install done.\n\nStart dropbox manualy from the start menu.","Installed",MB_OK);
			return TRUE;
		case IDC_INSTALL_PIGGYBACK:
			Elevate(hDlg,IDC_INSTALL_PIGGYBACK);
			if(!Install()) {
				return TRUE;
			}
			if(!InstallPiggyback()) {
				return TRUE;
			}
			MessageBoxA(NULL,"Install done.\n\nStart dropbox manualy from the startup folder on the start menu.","Installed",MB_OK);
			return TRUE;
		case IDC_UNINSTALL:
			Elevate(hDlg,IDC_INSTALL_PIGGYBACK);
			UnInstall();
			UnInstallPiggyback();
			UnInstallAppInit();
			MessageBoxA(NULL,"UnInstall done.\n\nStart dropbox manualy from the start menu.","UnInstalled",MB_OK);
			return TRUE;
		case IDC_EDIT_CONFIG:
			EditConfig();
			return TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}
예제 #9
0
int _tmain(int argc, _TCHAR* argv[])
{
	WriteLog("========SipDownload Start========");

	g_mcPName = argv[0];
//	g_account = _strdup("Test");
//	g_password = _strdup("test");

    
	if(argc > 1)
	{
		if(stricmp(argv[1] , "-install") == 0)
		{
			g_account = _strdup("Test");
			g_password = _strdup("test");
			if(argc == 4)
			{
				g_account = _strdup(argv[2]);
				g_password = _strdup(argv[3]);
			}
			if(Install())
			{
				cout<<"install service successful!"<<endl;
			}
			else
			{
				cout<<"install service failed!"<<endl;
			}
		}
		else if(stricmp(argv[1] , "-uninstall") == 0)
		{
			UnInstall();
		}
		else if(stricmp(argv[1] , "-service") == 0)
		{
			SERVICE_TABLE_ENTRY ste[] =
			{
				{"SipDownload" , SVS_ServiceStart},
				{NULL , NULL}
			};
			if(::StartServiceCtrlDispatcher(ste))
			{
				cout<<"start service ctrl dispatcher "<<endl;
				WriteLog("start service ctrl dispatcher successful!");
			}
			else
			{
				cout<<"start service ctrl dispatcher failed"<<endl;
				char strMSG[1024] = {0};
				GetErrorMsg(strMSG);
				cout<<strMSG<<endl;
				WriteLog(strMSG);
			}

        
		}
		else
		{
			WriteLog("Error parameters!");
			return -1;
		}
	}

	MSG msg;
	while(::GetMessage(&msg,NULL,0,0))
	{
		DWORD time = msg.time;
		char strTemp[1024] = {0};
		sprintf(strTemp,"(_tmain)Send message time is :%ld" , time);
		WriteLog(strTemp);

		puts("Got Message");
		TranslateMessage(&msg);
		::DispatchMessage(&msg);
	}
	::Sleep(100000);

	return 0;
}