⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		#define ntmemlockdriver "\\Drivers\\PGPmemlock.sys"

		LPSTR lpBuffer;
		LPSTR lpBufferb;
		LPSTR PathtoFile;
		BOOL bIsNT = FALSE;

		//delete the start menu folder, installshield can leave this behind
		lpBuffer = (char*)malloc (_MAX_PATH);
		lpBufferb = (char*)malloc (_MAX_PATH);
		GetWindowsDirectory(lpBuffer, _MAX_PATH);
		strcat (lpBuffer, "\\Profiles\\All Users\\Start Menu\\Programs\\PGP Certificate Server");
		strcpy (lpBufferb, lpBuffer);
		strcat (lpBufferb, "\\Documentation");
		RemoveDirectory(lpBufferb);
		RemoveDirectory(lpBuffer);
		free(lpBuffer);
		free(lpBufferb);
		RefreshStartMenu ();

		//If memlock was removed, delete reg. entries, otherwise start it.
		PathtoFile = (char*)malloc (MAX_PATH);
		GetSystemDirectory(PathtoFile, MAX_PATH);
		strcat (PathtoFile, ntmemlockdriver);

		if (_access(PathtoFile, 00) != 0)
		{
			//Memlock doesnt exist, remove keys.	
			RegDeleteKey(
						HKEY_LOCAL_MACHINE,         
						"SYSTEM\\CurrentControlSet\\Services\\PGPmemlock\\Enum"
						);
			RegDeleteKey(
						HKEY_LOCAL_MACHINE,         
						"SYSTEM\\CurrentControlSet\\Services\\PGPmemlock"
						);
		}
		else
		{
			//Memlock driver exists, start it.
			PGPclStartMemLockDriver ();
		}

		free(PathtoFile);
	}
#else
	//STUBS
	//________________________________________
	//
	//		custom DLL functions, used during 
	//		uninstallation,
	//	
	int		UninstInitialize	(HWND hwndDlg, HANDLE HInstance, LONG lReserved)
	{
		return 0;
	}

	void	UninstUnInitialize	(HWND hwndDlg, HANDLE HInstance, LONG lReserved)
	{	
	}
#endif

/*_____________________________________________________________________________
 * 	CreateAndWait
 */
BOOL CreateAndWait (char* CommandLine, LPSTR CmdExe, LPSTR ERRORSTRING)
{
	PROCESS_INFORMATION pi;
	STARTUPINFO			si;
	int					error;
	

	memset(&si, 0, sizeof(STARTUPINFO));
	memset(&pi, 0, sizeof(PROCESS_INFORMATION));

	si.cb = sizeof(STARTUPINFO);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_SHOWNORMAL;

	strcat(CommandLine, CmdExe);

	GetShortPathName(CommandLine, CommandLine, strlen(CommandLine) + 1);

	#if PGPDEBUG	
		MessageBox (GetFocus(), CommandLine, "DEBUGMODE", 0 | MB_ICONHAND);
	#endif

	error = CreateProcess(NULL, CommandLine, NULL, NULL,
						FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

	if (error == 0)
	{
		MessageBox (GetFocus(), ERRORSTRING, "ERROR", 0 | MB_ICONERROR);
		return FALSE;		
	}/*if*/

	/* wait at this line until launched program ends */
	WaitForSingleObject(pi.hProcess, INFINITE);

	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);
	return TRUE;
}/*end*/

//________________________________________
//
//		Code to stop a running service so it		
//		can be removed
//

INT StopService (LPSTR ServiceName)
{
SERVICE_STATUS STATUS;
SC_HANDLE hSCManager;
SC_HANDLE hService;
int iReturn;

hSCManager = NULL;
hService = NULL;
iReturn = false;

hSCManager = OpenSCManager	(// pointer to machine name string
							NULL,
							// pointer to database name string
							NULL,  
							// type of access	
							SC_MANAGER_ALL_ACCESS   
							);


hService = OpenService	(// handle to service control manager db
						hSCManager,
						// pointer to name of service to start
						ServiceName, 
						SERVICE_ALL_ACCESS  // type of access to service
						);

iReturn = ControlService(// handle to service
						hService,
						// control code  LPSERVICE_STATUS lpServiceStatus
						SERVICE_CONTROL_STOP, 
						// pointer to service status structure		
						&STATUS				
						);


CloseServiceHandle (hService);
CloseServiceHandle (hSCManager);

return iReturn;
}

//________________________________________
//
//		Code to refresh the startmenu so 		 
//		changes are reflected
//

void RefreshStartMenu ()
{
	IMalloc *pMalloc;

	if(SUCCEEDED(SHGetMalloc(&pMalloc)))
	{
		LPITEMIDLIST pidl;

		if(SUCCEEDED(SHGetSpecialFolderLocation((HWND)NULL, CSIDL_STARTMENU, &pidl)))
		{
			SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, pidl, NULL);
			pMalloc -> Free(pidl);
		}
		pMalloc -> Release();
	}
}

//________________________________________
//
//		Code to remove repd and certd		 
//		services
//
void DelSrv (int arg)
{
	#define	PGP_SERVICE_NAME "PGP Certificate Server"
	#define PGP_REPDSERVICE_NAME "PGP Replication Engine"

	SC_HANDLE service, scm;
	int	ok;
	SERVICE_STATUS stat;
	BOOL	doCertd = FALSE;
	BOOL	doRepd = FALSE;

		
	/* Initialize syslog/event error handling. */
//	ErrorLogInit("pgpcertd", g->eErrorLogLevel, g->iPort, 1);
	switch (arg) {
		case 0:	/* Run as a command line app. */
			doCertd = TRUE;
			break;
		case 1:	/* Run as a command line app. */
			doRepd = TRUE;	
			break;
		break;
	}

	if ( (doRepd == FALSE) && (doCertd == FALSE) )
	{
		MessageBox( NULL, "bad parm delsrv", "DelSrv",MB_OK | MB_ICONERROR); 
		return;
	}

	//fprintf(stdout, "Starting...\n");
	scm = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);
	//if (!scm)
	//	errorHandler ("Error in OpenScManager", GetLastError());

	/* Uninstall PGPcertd service
	 */
	if (doCertd == TRUE)
	{
		// Get the service handle
		service = OpenService(scm, PGP_SERVICE_NAME, SERVICE_ALL_ACCESS | DELETE);
		if (!service)
		{
		//	MessageBox( NULL, "Error opening Service Control Manager.",
		//			"",MB_OK | MB_ICONERROR);
		return;
		}
			
		// Stop the service
		ok = QueryServiceStatus (service, &stat);
		//if (!ok)
		//	errorHandler ("Error in QueryServiceStatus of PGPcertd", GetLastError());
			
		if (stat.dwCurrentState != SERVICE_STOPPED)
		{
			//sprintf(stdout, "Stopping Service...\n");
			ok = ControlService(service, SERVICE_CONTROL_STOP, &stat);
			//if (!ok)
			//	errorHandler ("Error in ControlService of PGPcertd", GetLastError());
			Sleep(500);	
		}

		ok = DeleteService( service);
		//if (!ok)
		//	errorHandler("Error in Delete Service of PGPcertd", GetLastError());
		//else
		//{
		//	Sleep(1);
		//}
			
		CloseServiceHandle (service);	
	}

	/* Uninstall PGPrepd service
	 */
	if (doRepd == TRUE)
	{
		// Get the service handle
		service = OpenService(scm, PGP_REPDSERVICE_NAME, SERVICE_ALL_ACCESS | DELETE);
		//if (!service)
		//	errorHandler ("Error in OpenService of PGPrepd", GetLastError());
			
		// Stop the service
		ok = QueryServiceStatus (service, &stat);
		//if (!ok)
		//	errorHandler ("Error in QueryServiceStatus of PGPrepd", GetLastError());
			
		if (stat.dwCurrentState != SERVICE_STOPPED)
		{
			//fprintf(stdout, "Stopping Service...\n");
			ok = ControlService(service, SERVICE_CONTROL_STOP, &stat);
			//if (!ok)
			//	errorHandler ("Error in ControlService of PGPrepd", GetLastError());
			Sleep(500);	
		}

		ok = DeleteService( service);
		if (!ok)
			Sleep(1);
		else
		{
			Sleep(1);
		}
			
		CloseServiceHandle (service);	
	}

	CloseServiceHandle (scm);
	return;
	//fprintf(stdout, "Ending...\n");
}

void AddSrv (int arg)
{
	#define PGP_REPDEXEC_NAME "PGPrepd.exe"
	#define PGP_CERTDEXEC_NAME "PGPcertd.exe"

	SC_HANDLE service, scm;
    BYTE Filename[512];	// pointer to buffer for module path 
	char *pChr;
	BOOL	doCertd = FALSE;
	BOOL	doRepd = FALSE;


	/* Initialize syslog/event error handling. */
//	ErrorLogInit("pgpcertd", g->eErrorLogLevel, g->iPort, 1);

	switch (arg) {
		case 0:	/* Run as a command line app. */
			doCertd = TRUE;	
			break;
		case 1:	/* Run as a command line app. */
			doRepd = TRUE;	
			break;
		break;
	}

	if ( (doRepd == FALSE) && (doCertd == FALSE) )
	{
		MessageBox( NULL, "bad parm addsrv", "AddSrv",MB_OK | MB_ICONERROR);
		return;
	}

	//fprintf(stdout, "Starting...\n");
	scm = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);
	if (!scm)
	{
		//MessageBox( NULL, "Error opening Service Control Manager.",
		//			"",MB_OK | MB_ICONERROR);
		return;
	}
		
 
	/* Install PGPcertd as a service
	 */
	if (doCertd == TRUE)
	{
		memset(Filename, 0, sizeof(Filename));
		GetModuleFileName(NULL,(char*)Filename,512);
  		if (pChr = strrchr((char*)Filename, '\\'))
			*pChr = '\0';
		strcat((char*)Filename, "\\");
		strcat((char*)Filename, PGP_CERTDEXEC_NAME);

		/* Enable the application's GUI, have the service start manually 
		 */
		service = CreateService( scm, PGP_SERVICE_NAME, PGP_SERVICE_NAME, SERVICE_ALL_ACCESS,
								SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
								SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, (char*)Filename,
								NULL, NULL, NULL, NULL, NULL);
		if (!service)
		{
			MessageBox( NULL, "Can't create Service.(It may already exist)",
						"",MB_OK | MB_ICONERROR);
			return;
		}
		CloseServiceHandle (service);
	}

	/* Install PGPrepd as a service
	 */
	if (doRepd == TRUE)
	{
		memset(Filename, 0, sizeof(Filename));
		GetModuleFileName(NULL, (char*)Filename,512);
   		if (pChr = strrchr((char*)Filename, '\\'))
			*pChr = '\0';
		strcat((char*)Filename, "\\");
		strcat((char*)Filename, PGP_REPDEXEC_NAME);

		/* Enable the application's GUI, have the service start manually 
		 */
		service = CreateService( scm, PGP_REPDSERVICE_NAME, PGP_REPDSERVICE_NAME, SERVICE_ALL_ACCESS,
								SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
								SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, (char*)Filename,
								NULL, NULL, NULL, NULL, NULL);
		if (!service)
			Sleep(1);
		else
		{
			Sleep(1);
		}
			
		CloseServiceHandle (service);
	}


	CloseServiceHandle (scm);
	return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -