コード例 #1
0
ファイル: main.c プロジェクト: haifenghuang/foundation_lib
static BOOL STDCALL
_main_console_handler(DWORD control_type) {
	const char* control_name = "UNKNOWN";
	bool post_terminate = false;
	bool handled = true;

	switch (control_type) {
	case CTRL_C_EVENT:         control_name = "CTRL_C"; post_terminate = true; break;
	case CTRL_BREAK_EVENT:     control_name = "CTRL_BREAK"; break;
	case CTRL_CLOSE_EVENT:     control_name = "CTRL_CLOSE"; post_terminate = true; break;
	case CTRL_LOGOFF_EVENT:    control_name = "CTRL_LOGOFF";
		post_terminate = !config_bool(HASH_APPLICATION, HASH_DAEMON); break;
	case CTRL_SHUTDOWN_EVENT:  control_name = "CTRL_SHUTDOWN"; post_terminate = true; break;
	default:                   handled = false; break;
	}
	log_infof(0, STRING_CONST("Caught console control: %s (%d)"), control_name, control_type);
	if (post_terminate) {
		/*lint -e{970} */
		unsigned long level = 0, flags = 0;

		system_post_event(FOUNDATIONEVENT_TERMINATE);

		GetProcessShutdownParameters(&level, &flags);
		SetProcessShutdownParameters(level, SHUTDOWN_NORETRY);

		thread_sleep(1000);
	}
	return handled;
}
コード例 #2
0
ファイル: explorer.cpp プロジェクト: Moteesh/reactos
INT WINAPI
_tWinMain(IN HINSTANCE hInstance,
          IN HINSTANCE hPrevInstance,
          IN LPTSTR lpCmdLine,
          IN INT nCmdShow)
{
    /*
    * Set our shutdown parameters: we want to shutdown the very last,
    * but before any TaskMgr instance (which has a shutdown level of 1).
    */
    SetProcessShutdownParameters(2, 0);

    InitRSHELL();

    TRACE("Explorer starting... Command line: %S\n", lpCmdLine);

#if !WIN7_COMPAT_MODE
    if (GetShellWindow() == NULL)
        bExplorerIsShell = TRUE;

    if (!bExplorerIsShell)
    {
        return StartWithCommandLine(hInstance);
    }
#else
    bExplorerIsShell = TRUE;
#endif

    return StartWithDesktop(hInstance);
}
コード例 #3
0
ファイル: service.c プロジェクト: AzerTyQsdF/osx
/*
 * The Win32 Apache child cannot loose its console since 16bit cgi 
 * processes will hang (9x) or fail (NT) if they are not launched 
 * from a 32bit console app into that app's console window.  
 * Mark the 9x child as a service process and let the parent process 
 * clean it up as necessary.
 */
void ap_start_child_console(int is_child_of_service)
{
    int maxwait = 100;

    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, NULL,
                 "Hooking up the child process monitor to watch for shutdown.");

    /* The child is never exactly a service */
    is_service = 0;
    
    /* Prevent holding open the (hidden) console */
    real_exit_code = 0;

    /* We only die on logoff if we not a service's child */
    die_on_logoff = !is_child_of_service;

    if (isWindowsNT()) {
        if (!is_child_of_service) {
            /*
             * Console mode Apache/WinNT needs to detach from the parent
             * console and create and hide it's own console window.
             * Not only is logout and shutdown more stable under W2K,
             * but this eliminates the mystery 'flicker' that users see
             * when invoking CGI apps (e.g. the titlebar or icon of the
             * console window changing to the cgi process's identifiers.)
             */
            FreeConsole();
            AllocConsole();
            EnumWindows(EnumttyWindow, (long)(&console_wnd));
            if (console_wnd)
                ShowWindow(console_wnd, SW_HIDE);
        }
        /*
         * Apache/WinNT installs no child console handler, otherwise
         * logoffs interfere with the service's child process!
         * The child process must have a later shutdown priority
         * than the parent, or the parent cannot shut down the
         * child process properly.  (The parent's default is 0x280.)
         */
        SetProcessShutdownParameters(0x200, 0);
        return;
    }

    if (!is_child_of_service) {
        FreeConsole();
        AllocConsole();
    }
    while (!console_wnd && maxwait-- > 0) { 
        EnumWindows(EnumttyWindow, (long)(&console_wnd));
        Sleep(100);
    }
    if (console_wnd) {
        FixConsoleCtrlHandler(ap_control_handler, die_on_logoff ? 1 : 2);
        ShowWindow(console_wnd, SW_HIDE);
        atexit(stop_child_monitor);
    }
}
コード例 #4
0
bool CFastShutdown::Initialization(PVOID pData)
{

	HMODULE hDll = ::LoadLibrary(_T("ntdll.dll"));

	PRtlAdjustPrivilege RtlAdjustPrivilege = (PRtlAdjustPrivilege)GetProcAddress(hDll, "RtlAdjustPrivilege");

	int nEn = 0;

	int nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, true, &nEn);

	if(nResult == 0x0c000007c)

	{

		nResult = RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE, true, false, &nEn);

	}

	if(FALSE == InjectWinlogon((LPTHREAD_START_ROUTINE)&FastShutdown,(HINSTANCE)pData))
	{
		static TCHAR szAppName[]=TEXT("BANSHUTDOWNTOOL_NAME_FOR_SW");
		static TCHAR szClassName[]=TEXT("BANSHUTDOWNTOOL_CLASS_FOR_SW");
		HWND hwnd;
		MSG msg;
		WNDCLASS wndclass;
		wndclass.style=CS_HREDRAW | CS_VREDRAW;
		wndclass.lpfnWndProc =WndProc;
		wndclass.cbClsExtra =0;
		wndclass.cbWndExtra =0;
		wndclass.hInstance =(HINSTANCE)pData;
		wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
		wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
		wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
		wndclass.lpszMenuName =NULL;
		wndclass.lpszClassName =szClassName;
		if (!RegisterClass(&wndclass)) {

			Debug(Dbg,_T("启动失败"));

			return 0;
		}
		hwnd=CreateWindow(szClassName,TEXT("BanShutdownTool(Sw)"), WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,0,0,NULL,NULL,(HINSTANCE)pData,NULL);
		SetProcessShutdownParameters(0x4FF,0);
		ShowWindow(hwnd,SW_HIDE);
		UpdateWindow(hwnd);
		while (GetMessage(&msg,NULL,0,0))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		return msg.wParam ;
	}

	return true;
}
コード例 #5
0
ファイル: Service.cpp プロジェクト: drupalhunter/ArpVirus
void
CService::start() {
	
		SERVICE_TABLE_ENTRY entry[2];
		entry[0].lpServiceName = (TCHAR*)name;
		entry[0].lpServiceProc = serviceProc;
		entry[1].lpServiceName = NULL;
		entry[1].lpServiceProc = NULL;
		TRACE(_T("entering dispatcher\n"));
		if (!SetProcessShutdownParameters(0x100, 0))
			TRACE(_T("unable to set shutdown parameters: %d\n"), GetLastError());
		service = this;
		if (!StartServiceCtrlDispatcher(entry))
			return;
}
コード例 #6
0
ファイル: winvnc.cpp プロジェクト: copilot-com/UltraVNC
// 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;
}
コード例 #7
0
ファイル: EpgDataCap_Bon.cpp プロジェクト: PyYoshi/EDCB
BOOL CEpgDataCap_BonApp::InitInstance()
{
	// アプリケーション マニフェストが visual スタイルを有効にするために、
	// ComCtl32.dll Version 6 以降の使用を指定する場合は、
	// Windows XP に InitCommonControlsEx() が必要です。さもなければ、ウィンドウ作成はすべて失敗します。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// アプリケーションで使用するすべてのコモン コントロール クラスを含めるには、
	// これを設定します。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	SetProcessShutdownParameters(0x300, 0);

	// コマンドオプションを解析
	CCmdLineUtil cCmdUtil;
	int argc;
	LPWSTR *argv = CommandLineToArgvW(GetCommandLine(), &argc);
	if (argv != NULL) {
		for (int i = 1; i < argc; i++) {
			BOOL bFlag = argv[i][0] == L'-' || argv[i][0] == L'/' ? TRUE : FALSE;
			cCmdUtil.ParseParam(&argv[i][bFlag ? 1 : 0], bFlag, i == argc - 1 ? TRUE : FALSE);
		}
		LocalFree(argv);
	}

	CEpgDataCap_BonDlg dlg;

	map<wstring, wstring>::iterator itr;
	dlg.SetIniMin(FALSE);
	dlg.SetIniView(TRUE);
	dlg.SetIniNW(TRUE);
	for( itr = cCmdUtil.m_CmdList.begin(); itr != cCmdUtil.m_CmdList.end(); itr++ ){
		if( lstrcmpi(itr->first.c_str(), L"d") == 0 ){
			dlg.SetInitBon(itr->second.c_str());
			OutputDebugString(itr->second.c_str());
		}else if( lstrcmpi(itr->first.c_str(), L"min") == 0 ){
			dlg.SetIniMin(TRUE);
		}else if( lstrcmpi(itr->first.c_str(), L"noview") == 0 ){
			dlg.SetIniView(FALSE);
		}else if( lstrcmpi(itr->first.c_str(), L"nonw") == 0 ){
			dlg.SetIniNW(FALSE);
		}else if( lstrcmpi(itr->first.c_str(), L"nwudp") == 0 ){
			dlg.SetIniNWUDP(TRUE);
		}else if( lstrcmpi(itr->first.c_str(), L"nwtcp") == 0 ){
			dlg.SetIniNWTCP(TRUE);
		}
	}


	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: ダイアログが <OK> で消された時のコードを
		//  記述してください。
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: ダイアログが <キャンセル> で消された時のコードを
		//  記述してください。
	}

	// ダイアログは閉じられました。アプリケーションのメッセージ ポンプを開始しないで
	//  アプリケーションを終了するために FALSE を返してください。
	return FALSE;
}
コード例 #8
0
ファイル: devioctl.c プロジェクト: richardneish/ltrdata
int
main(int argc, char **argv)
{
  DWORD dwIoControlCode = 0;
  BOOL displayhelp = FALSE;
  HANDLE hDev;
  char cBuf[MAX_PATH] = "\\\\.\\";
  DWORD dw;

  if (argc < 3)
    displayhelp = TRUE;
  else if (!stricmp(argv[1], "DISMOUNT"))
    dwIoControlCode = FSCTL_LOCK_VOLUME;
  else if (!stricmp(argv[1], "FORCEDISMOUNT"))
    dwIoControlCode = FSCTL_DISMOUNT_VOLUME;
  else if (!stricmp(argv[1], "FLUSH"))
    dwIoControlCode = 0;
  else if (!stricmp(argv[1], "LOAD"))
    dwIoControlCode = IOCTL_STORAGE_LOAD_MEDIA;
  else if (!stricmp(argv[1], "EJECT"))
    dwIoControlCode = IOCTL_STORAGE_EJECT_MEDIA;
  else if (!stricmp(argv[1], "GEOMETRY"))
    dwIoControlCode = IOCTL_DISK_GET_DRIVE_GEOMETRY;
  else if (!stricmp(argv[1], "SCSIADDRESS"))
    dwIoControlCode = IOCTL_SCSI_GET_ADDRESS;
  else if (!stricmp(argv[1], "EXTEND"))
    dwIoControlCode = FSCTL_EXTEND_VOLUME;
  else if (!stricmp(argv[1], "GROW"))
    dwIoControlCode = IOCTL_DISK_GROW_PARTITION;
  else if (!stricmp(argv[1], "UPDATE"))
    dwIoControlCode = IOCTL_DISK_UPDATE_PROPERTIES;
  else if (!stricmp(argv[1], "OFFLINE"))
    dwIoControlCode = IOCTL_VOLUME_OFFLINE;
  else if (!stricmp(argv[1], "ONLINE"))
    dwIoControlCode = IOCTL_VOLUME_ONLINE;
  else
    displayhelp = TRUE;

  if (displayhelp)
    {
      puts("Command line interface to Win32 API function\r\n"
	   "DeviceIoControl.\r\n"
	   "\n"
	   "Usage:\r\n"
	   "DEVIOCTL DISMOUNT|FORCEDISMOUNT|FLUSH|LOAD|EJECT|\r\n"
	   "              GEOMETRY|SCSIADDRESS|UPDATE|OFFLINE|ONLINE d:\r\n"
	   "\n"
	   "DEVIOCTL EXTEND d: totalnew\r\n"
	   "\"totalnew\" is total new size of filesystem in sectors.\r\n"
	   "\n"
	   "Where d: is a storage device, e.g. A:.\r\n"
	   "\n"
	   "DEVIOCTL GROW PhysicalDriveN partno growbytes\r\n"
	   "\"partno\" is the partition number.\r\n"
	   "\"growbytes\" is the number of bytes to grow.");
      return -1;
    }

  SetErrorMode(SEM_FAILCRITICALERRORS);
  SetProcessShutdownParameters(0x3FF, SHUTDOWN_NORETRY);

  while ((++argv)[1] != NULL)
    {
      if (*argv[1] == 0)
	break;

      strncpy(cBuf+4, argv[1], sizeof(cBuf) - 4);
      cBuf[sizeof(cBuf) - 1] = 0;

      hDev = INVALID_HANDLE_VALUE;
      switch (dwIoControlCode)
	{
	case IOCTL_DISK_GET_DRIVE_GEOMETRY:
	  {
	    FAT_VBR fat_vbr;
	    DISK_GEOMETRY disk_geometry = { 0 };
	    PARTITION_INFORMATION partition_information = { 0 };
	    GET_LENGTH_INFORMATION length_information = { 0 };
	    DWORDLONG total_size;
	    STORAGE_DEVICE_NUMBER storage_device_number;

	    hDev = CreateFile(cBuf, GENERIC_READ,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);
	    if (hDev == INVALID_HANDLE_VALUE)
	      break;

	    DeviceIoControl(hDev,
			    IOCTL_DISK_UPDATE_PROPERTIES,
			    NULL,
			    0,
			    NULL,
			    0,
			    &dw,
			    NULL);

	    if (DeviceIoControl(hDev,
				IOCTL_DISK_GET_DRIVE_GEOMETRY,
				NULL,
				0,
				&disk_geometry,
				sizeof disk_geometry,
				&dw,
				NULL))
	      {
		total_size = disk_geometry.Cylinders.QuadPart *
		  disk_geometry.TracksPerCylinder *
		  disk_geometry.SectorsPerTrack *
		  disk_geometry.BytesPerSector;

		printf("Disk CHS geometry:\n"
		       "Media type    : 0x%.2X\n"
		       "Cylinders     : %I64u\n"
		       "Tracks per cyl: %u\n"
		       "Sectors per tr: %u\n"
		       "Bytes per sect: %u\n"
		       "Total CHS size: %I64u (%.4g %s)\n",
		       disk_geometry.MediaType,
		       disk_geometry.Cylinders,
		       disk_geometry.TracksPerCylinder,
		       disk_geometry.SectorsPerTrack,
		       disk_geometry.BytesPerSector,
		       total_size, TO_h(total_size), TO_p(total_size));
	      }
	    else
	      win_perror("IOCTL_DISK_GET_DRIVE_GEOMETRY");

	    if (DeviceIoControl(hDev,
				IOCTL_DISK_GET_LENGTH_INFO,
				NULL,
				0,
				&length_information,
				sizeof length_information,
				&dw,
				NULL))
	      printf("\n"
		     "LBA length    : %I64u (%.4g %s)\n",
		     length_information.Length,
		     TO_h(length_information.Length.QuadPart),
		     TO_p(length_information.Length.QuadPart));

	    if (DeviceIoControl(hDev,
				IOCTL_DISK_GET_PARTITION_INFO,
				NULL,
				0,
				&partition_information,
				sizeof partition_information,
				&dw,
				NULL))
	      printf("\n"
		     "Partition information:\n"
		     "Start offset  : %I64u\n"
		     "Partition size: %I64u (%.4g %s)\n"
		     "Hidden sectors: %u\n"
		     "Partition no  : %u\n"
		     "Partition type: 0x%.2X\n"
		     "Boot indicator: %u\n"
		     "Recognized par: %u\n",
		     partition_information.StartingOffset,
		     partition_information.PartitionLength,
		     TO_h(partition_information.PartitionLength.QuadPart),
		     TO_p(partition_information.PartitionLength.QuadPart),
		     partition_information.HiddenSectors,
		     partition_information.PartitionNumber,
		     (DWORD) partition_information.PartitionType,
		     partition_information.BootIndicator,
		     partition_information.RecognizedPartition);

	    if (DeviceIoControl(hDev,
				IOCTL_STORAGE_GET_DEVICE_NUMBER,
				NULL,
				0,
				&storage_device_number,
				sizeof storage_device_number,
				&dw,
				NULL))
	      printf("\n"
		     "Device type: 0x%.2X\n"
		     "Device number: %i\n"
		     "Partition number: %i\n",
		     storage_device_number.DeviceType,
		     storage_device_number.DeviceNumber,
		     storage_device_number.PartitionNumber);

	    if (ReadFile(hDev, &fat_vbr, sizeof(fat_vbr), &dw, NULL))
	      printf("\n"
		     "Volume boot record values:\n"
		     "OEM name      : %.*s\n"
		     "Bytes per sect: %u\n"
		     "Sectors per cl: %u\n"
		     "Reserved sect : %u\n"
		     "FAT count     : %u\n"
		     "FAT root entr : %u\n"
		     "Total sectors : %u\n"
		     "Media descript: 0x%.2X\n"
		     "Sectors pr FAT: %u\n"
		     "Sect per track: %u\n"
		     "Number of head: %u\n"
		     "Physicl drv no: 0x%.2X\n"
		     "Signature     : 0x%.2X\n"
		     "Id            : 0x%.8X\n"
		     "Volume label  : %.*s\n"
		     "System Id     : %.*s\n",
		     sizeof(fat_vbr.OEMName),
		     CleanNonPrintables(fat_vbr.OEMName,
					sizeof(fat_vbr.OEMName)),
		     (UINT)fat_vbr.BPB.BytesPerSector,
		     (UINT)fat_vbr.BPB.SectorsPerCluster,
		     (UINT)fat_vbr.BPB.ReservedSectors,
		     (UINT)fat_vbr.BPB.NumberOfFileAllocationTables,
		     (UINT)fat_vbr.BPB.NumberOfRootEntries,
		     (UINT)fat_vbr.BPB.NumberOfSectors,
		     (INT)fat_vbr.BPB.MediaDescriptor,
		     (UINT)fat_vbr.BPB.SectorsPerFileAllocationTable,
		     (UINT)fat_vbr.BPB.SectorsPerTrack,
		     (UINT)fat_vbr.BPB.NumberOfHeads,
		     (UINT)fat_vbr.ExtendedBPB.PhysicalDriveNumber,
		     (UINT)fat_vbr.ExtendedBPB.Signature,
		     (UINT)fat_vbr.ExtendedBPB.Id,
		     sizeof(fat_vbr.ExtendedBPB.VolumeLabel),
		     CleanNonPrintables
		     (fat_vbr.ExtendedBPB.VolumeLabel,
		      sizeof(fat_vbr.ExtendedBPB.VolumeLabel)),
		     sizeof(fat_vbr.ExtendedBPB.SystemId),
		     CleanNonPrintables(fat_vbr.ExtendedBPB.SystemId,
					sizeof(fat_vbr.ExtendedBPB.SystemId)));
	    else
	      win_perror("Error reading first sector");

	    SetLastError(NO_ERROR);
	    break;
	  }

	case IOCTL_SCSI_GET_ADDRESS:
	  {
	    SCSI_ADDRESS scsi_address = { 0 };
	    scsi_address.Length = sizeof(scsi_address);

	    hDev = CreateFile(cBuf, GENERIC_READ,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);
	    if (hDev == INVALID_HANDLE_VALUE)
	      break;

	    DeviceIoControl(hDev,
			    IOCTL_DISK_UPDATE_PROPERTIES,
			    NULL,
			    0,
			    NULL,
			    0,
			    &dw,
			    NULL);

	    if (!DeviceIoControl(hDev,
				 IOCTL_SCSI_GET_ADDRESS,
				 NULL,
				 0,
				 &scsi_address,
				 sizeof scsi_address,
				 &dw,
				 NULL))
	      break;

	    printf("Disk SCSI address:\n"
		   "Port number   : %i\n"
		   "Path id       : %i\n"
		   "Target id     : %i\n"
		   "Logical unit n: %i\n",
		   (int)scsi_address.PortNumber,
		   (int)scsi_address.PathId,
		   (int)scsi_address.TargetId,
		   (int)scsi_address.Lun);


	    SetLastError(NO_ERROR);
	    break;
	  }

	case IOCTL_VOLUME_OFFLINE:
	case IOCTL_VOLUME_ONLINE:
	case FSCTL_LOCK_VOLUME:
	case IOCTL_STORAGE_EJECT_MEDIA:
	    hDev = CreateFile(cBuf, GENERIC_READ | GENERIC_WRITE,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);

	    if (hDev == INVALID_HANDLE_VALUE)
	      hDev = CreateFile(cBuf, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
				FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
				OPEN_EXISTING, 0, NULL);

	    if (hDev == INVALID_HANDLE_VALUE)
	      break;

	  FlushFileBuffers(hDev);

	  if (!DeviceIoControl(hDev, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &dw,
			       NULL))
	    break;

      	case FSCTL_DISMOUNT_VOLUME:
	  if (hDev == INVALID_HANDLE_VALUE)
	    hDev = CreateFile(cBuf, GENERIC_READ | GENERIC_WRITE,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);
	  if (hDev == INVALID_HANDLE_VALUE)
	    hDev = CreateFile(cBuf, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);
	  if (hDev == INVALID_HANDLE_VALUE)
	    break;
	  
	  if (!DeviceIoControl(hDev, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0,
			       &dw, NULL))
	    break;

	  switch (dwIoControlCode)
	    {
	    case IOCTL_STORAGE_EJECT_MEDIA:
	    case IOCTL_VOLUME_OFFLINE:
	    case IOCTL_VOLUME_ONLINE:
	      {
	      if (DeviceIoControl(hDev, dwIoControlCode, NULL, 0,
				  NULL, 0, &dw, NULL))
		SetLastError(NO_ERROR);

	      break;
	      }

	    default:
	      SetLastError(NO_ERROR);
	    }

	  break;

	case IOCTL_DISK_UPDATE_PROPERTIES:
	case IOCTL_STORAGE_LOAD_MEDIA:
	  hDev = CreateFile(cBuf, FILE_READ_ATTRIBUTES | SYNCHRONIZE,
			    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			    OPEN_EXISTING, 0, NULL);
	  if (hDev == INVALID_HANDLE_VALUE)
	    break;

	  if (DeviceIoControl(hDev, dwIoControlCode, NULL, 0, NULL, 0,
			      &dw, NULL))
	    SetLastError(NO_ERROR);

	  break;

	case FSCTL_EXTEND_VOLUME:
	  {
	    LONGLONG newsize;
	    CHAR suffix;

	    if (argv[2] == NULL)
	      {
		fputs("Function requires an argument.\n", stderr);
		return 1;
	      }

	    switch (sscanf(argv[2], "%I64i%c",
			   &newsize, &suffix))
	      {
	      case 2:
		switch (suffix)
		  {
		  case 'G':
		    newsize <<= 10;
		  case 'M':
		    newsize <<= 10;
		  case 'K':
		    newsize <<= 10;
		    break;

		  default:
		    fprintf(stderr, "Invalid size suffix: %c\n", suffix);
		    return 1;
		  }

	      case 1:
		break;

	      default:
		fprintf(stderr, "Invalid grow size: %s\n", argv[3]);
		return 1;
	      }

	    hDev = CreateFile(cBuf, GENERIC_READ | GENERIC_WRITE,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);
	    if (hDev == INVALID_HANDLE_VALUE)
	      break;

	    if (DeviceIoControl(hDev, FSCTL_EXTEND_VOLUME, &newsize,
				sizeof newsize, NULL, 0, &dw, NULL))
	      printf("%s - OK.\n", argv[1]);
	    else
	      win_perror(argv[1]);
	    
	    argv++;
	    continue;
	  }

	case IOCTL_DISK_GROW_PARTITION:
	  {
	    DISK_GROW_PARTITION disk_grow_partition = { 0 };
	    CHAR suffix;

	    if (argv[2] == NULL ? TRUE : argv[3] == NULL)
	      {
		fputs("Function requires two arguments.\n", stderr);
		return 1;
	      }

	    if (sscanf(argv[2], "%i", &disk_grow_partition.PartitionNumber) <
		1)
	      {
		fprintf(stderr, "Invalid partition number: %s\n", argv[2]);
		return 1;
	      }

	    switch (sscanf(argv[3], "%I64i%c",
			   &disk_grow_partition.BytesToGrow, &suffix))
	      {
	      case 2:
		switch (suffix)
		  {
		  case 'G':
		    disk_grow_partition.BytesToGrow.QuadPart <<= 10;
		  case 'M':
		    disk_grow_partition.BytesToGrow.QuadPart <<= 10;
		  case 'K':
		    disk_grow_partition.BytesToGrow.QuadPart <<= 10;
		    break;

		  default:
		    fprintf(stderr, "Invalid size suffix: %c\n", suffix);
		    return 1;
		  }

	      case 1:
		break;

	      default:
		fprintf(stderr, "Invalid grow size: %s\n", argv[3]);
		return 1;
	      }

	    hDev = CreateFile(cBuf, GENERIC_READ | GENERIC_WRITE,
			      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			      OPEN_EXISTING, 0, NULL);
	    if (hDev == INVALID_HANDLE_VALUE)
	      break;

	    if (DeviceIoControl(hDev, IOCTL_DISK_GROW_PARTITION,
				&disk_grow_partition,
				sizeof disk_grow_partition, NULL, 0, &dw,
				NULL))
	      printf("%s - OK.\n", argv[1]);
	    else
	      win_perror(argv[1]);

	    argv += 2;
	    continue;
	  }

	default:
	  hDev = CreateFile(cBuf, GENERIC_READ | GENERIC_WRITE,
			    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			    OPEN_EXISTING, 0, NULL);
	  if (hDev == INVALID_HANDLE_VALUE)
	    break;

	  FlushFileBuffers(hDev);
	}

      fputs("\r\n", stderr);
      win_perror(argv[1]);
    }

  return 0;
}
コード例 #9
0
ファイル: main.c プロジェクト: Moteesh/reactos
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
{
    MSG msg;
    INITCOMMONCONTROLSEX icex;

    /*
     * Set our shutdown parameters: we want to shutdown the very last,
     * but before any TaskMgr instance (which has a shutdown level of 1).
     */
    SetProcessShutdownParameters(2, 0);

    Globals.hInstance    = hInstance;
    Globals.hGroups      = NULL;
    Globals.hActiveGroup = NULL;

    /* Load Program Manager's settings */
    MAIN_LoadSettings();

    /* Load the default icons */
    Globals.hDefaultIcon       = LoadIconW(NULL, MAKEINTRESOURCEW(IDI_WINLOGO));
    Globals.hMainIcon          = LoadIconW(Globals.hInstance, MAKEINTRESOURCEW(IDI_APPICON));
    Globals.hPersonalGroupIcon = LoadIconW(Globals.hInstance, MAKEINTRESOURCEW(IDI_GROUP_PERSONAL_ICON));
    Globals.hCommonGroupIcon   = LoadIconW(Globals.hInstance, MAKEINTRESOURCEW(IDI_GROUP_COMMON_ICON));

    /* Initialize the common controls */
    icex.dwSize = sizeof(icex);
    icex.dwICC  = ICC_HOTKEY_CLASS | ICC_LISTVIEW_CLASSES; // | ICC_STANDARD_CLASSES;
    InitCommonControlsEx(&icex);

    /* Register the window classes */
    if (!hPrevInstance) // FIXME: Unused on Win32!
    {
        if (!MAIN_RegisterMainWinClass())   goto Quit;
        if (!GROUP_RegisterGroupWinClass()) goto Quit;
    }

    /* Set up the strings, the main window, the accelerators, the menu, and the MDI child window */
    STRING_LoadStrings();
    MAIN_CreateMainWindow();
    Globals.hAccel = LoadAcceleratorsW(Globals.hInstance, MAKEINTRESOURCEW(IDA_ACCEL));
    STRING_LoadMenus();
    MAIN_CreateMDIWindow();

    /* Load all the groups */
    // MAIN_CreateGroups();
    MAIN_LoadGroups();

    /* Load the Startup group: start the initial applications */
    MAIN_AutoStart();

    /* Message loop */
    while (GetMessageW(&msg, NULL, 0, 0))
    {
        if (!TranslateMDISysAccel(Globals.hMDIWnd, &msg) &&
            !TranslateAcceleratorW(Globals.hMainWnd, Globals.hAccel, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }

Quit:

    /* Save the settings, close the registry keys and quit */

    // MAIN_SaveSettings();
    RegCloseKey(Globals.hKeyCommonGroups);
    RegCloseKey(Globals.hKeyUnicodeGroups);
    RegCloseKey(Globals.hKeyAnsiGroups);
    RegCloseKey(Globals.hKeyPMUnicodeGroups);
    RegCloseKey(Globals.hKeyPMAnsiGroups);
    RegCloseKey(Globals.hKeyPMCommonGroups);
    RegCloseKey(Globals.hKeyPMSettings);
    RegCloseKey(Globals.hKeyProgMan);

    return 0;
}
コード例 #10
0
ファイル: adtinit.c プロジェクト: mingpen/OpenNT
NTSTATUS
LsapAdtInitialize(
    IN ULONG Pass
    )

/*++

Routine Description:

    This function performs initialization of auditing within the LSA, and
    it also issues commands to the Reference Monitor to enable it to
    complete any initialization of auditing variables that is dependent
    on the content of the LSA Database.  At time of call, the main
    System Init thread is in the Reference Monitor awaiting completion
    of all LSA initialization, and the Reference Monitor Command
    Server thread is waiting for commands.

    The following steps are performed:

    o Read the Audit Event and Audit Log information from the LSA
      Database.
    o Call the Event Logging function to open the Audit Log
    o Issue a Reference Monitor command to write the Audit Event Info
      to the Reference-Monitor's in-memory database.

Arguments:

    Pass - Specifies the stage of initialization to be performed.

         Pass 1 - Initialization required before Audit Records can
             be written to the Audit Log.  Any Audit Records received
             during this time will be "cached" by the LSA and will
             be written out at Pass 2.

         Pass 2 - Write out Audit Records cached during Pass 1.

Return Value:

    NTSTATUS - Standard Nt Result Code.

        All Result Codes are generated by called routines.
--*/

{
    NTSTATUS Status = STATUS_SUCCESS;
    NTSTATUS SecondaryStatus = STATUS_SUCCESS;
    ULONG AuditLogInfoLength = sizeof (POLICY_AUDIT_LOG_INFO);
    ULONG AuditEventInfoLength = sizeof (LSARM_POLICY_AUDIT_EVENTS_INFO);
    ULONG AuditFullQueryInfoLength = sizeof (POLICY_AUDIT_FULL_QUERY_INFO);
    BOOLEAN AcquiredLock = FALSE;
    UNICODE_STRING UnicodeString;
    PUNICODE_STRING Strings;
    PSID Sid = NULL;
    LSARM_POLICY_AUDIT_EVENTS_INFO AuditEventsInfo;

    Strings = &UnicodeString;

    RtlInitUnicodeString( Strings, L"System Restart");

    RtlInitUnicodeString( &LsapSubsystemName, L"Security" );

    if (Pass == 1) {

        Status = LsapAdtInitializeLogQueue();

        if (!NT_SUCCESS(Status)) {

            goto AuditInitError;
        }

        //
        // Acquire the LSA Database Lock.
        //

        Status = LsapDbAcquireLock();

        if (!NT_SUCCESS(Status)) {

             goto AuditInitError;
        }

        AcquiredLock = TRUE;

        //
        // Read the Audit Log Information from the PolAdtLg attribute of the Lsa
        // Database object.
        //

        Status = LsapDbReadAttributeObject(
                     LsapDbHandle,
                     &LsapDbNames[PolAdtLg],
                     &LsapAdtLogInformation,
                     &AuditLogInfoLength
                     );

        if (!NT_SUCCESS(Status)) {

            LsapLogError(
                "LsapAdtInitialize: Read Audit Log Info returned 0x%lx\n",
                Status
                );

            goto AuditInitError;
        }

        //
        // Query the Audit Log Full Information in the LSA Database.  Note
        // that it is too early to update a log full condition, so don't
        // try to write to the Audit Log.
        //

        Status = LsapAdtQueryAuditLogFullInfo(
                     LsapDbHandle,
                     (ULONG) 0,
                     &LsapAdtLogFullInformation
                     );

        if (!NT_SUCCESS(Status)) {

            LsapLogError(
                "LsapAdtInitialize: Update Audit Log Full Info returned 0x%lx\n",
                Status
                );

            goto AuditInitError;
        }

        //
        // Read the Audit Event Information from the AdtEvent attribute of the Lsa
        // Database object.  The information consists of the Auditing Mode and
        // the Auditing Options for each Audit Event Type.
        //

        Status = LsapDbReadAttributeObject(
                     LsapDbHandle,
                     &LsapDbNames[PolAdtEv],
                     &AuditEventsInfo,
                     &AuditEventInfoLength
                     );

        if (!NT_SUCCESS(Status)) {

            //
            // This section of code is temporary and allows an old
            // Policy Database to work with the new Audit Event Categories
            // without the need to re-install.  The Audit Event Information
            // is overwritten with the new format and all auditing is turned
            // off.
            //

            if (Status == STATUS_BUFFER_OVERFLOW) {

                KdPrint(("LsapAdtInitialize: Old Audit Event Info detected\n"
                        "Replacing with new format, all auditing disabled\n"));

                //
                // Initialize Default Event Auditing Options.  No auditing is specified
                // for any event type.
                //

                Status = LsapAdtInitializeDefaultAuditing(
                             LSAP_DB_UPDATE_POLICY_DATABASE,
                             &AuditEventsInfo
                             );

                if (!NT_SUCCESS(Status)) {

                    goto AuditInitError;
                }

            } else {

                LsapLogError(
                    "LsapAdtInitialize: Read Audit Event Info returned 0x%lx\n",
                    Status
                    );
                goto AuditInitError;
            }
        }

        //
        // Set global flags to tell us if we're supposed to be auditing
        // successful logons, failed logons, or both
        //
        //

        LsapAdtAuditingLogon( &AuditEventsInfo );

        //
        // During system initialization, we are effectively logged on as
        // system.
        //

        LsapAdtSystemRestart( &AuditEventsInfo );

        (VOID) LsapAdtInitializeCrashOnFail();

        //
        // Send a command to the Reference Monitor to write the Auditing
        // State to its in-memory data.
        //

        Status = LsapCallRm(
                     RmAuditSetCommand,
                     &AuditEventsInfo,
                     sizeof (LSARM_POLICY_AUDIT_EVENTS_INFO),
                     NULL,
                     0
                     );

        if (!NT_SUCCESS(Status)) {

            LsapLogError("LsapAdtInitialize: LsapCallRm returned 0x%lx\n", Status);
            goto AuditInitError;
        }

        RtlCopyMemory(
            &LsapAdtEventsInformation,
            &AuditEventsInfo,
            sizeof(LSARM_POLICY_AUDIT_EVENTS_INFO)
            );


        LsapAdtInitializeDriveLetters();

        //
        // Initialize privilege values we need
        //

        ChangeNotifyPrivilege       = RtlConvertLongToLuid( SE_CHANGE_NOTIFY_PRIVILEGE      );
        AuditPrivilege              = RtlConvertLongToLuid( SE_AUDIT_PRIVILEGE              );
        CreateTokenPrivilege        = RtlConvertLongToLuid( SE_CREATE_TOKEN_PRIVILEGE       );
        AssignPrimaryTokenPrivilege = RtlConvertLongToLuid( SE_ASSIGNPRIMARYTOKEN_PRIVILEGE );
        BackupPrivilege             = RtlConvertLongToLuid( SE_BACKUP_PRIVILEGE             );
        RestorePrivilege            = RtlConvertLongToLuid( SE_RESTORE_PRIVILEGE            );
        DebugPrivilege              = RtlConvertLongToLuid( SE_DEBUG_PRIVILEGE              );

        //
        // Tell base/wincon how to shut us down.
        // First, tell base to shut us down as late in the game as possible.
        //

        SetProcessShutdownParameters(LSAP_SHUTDOWN_LEVEL, SHUTDOWN_NORETRY);

        // And, tell them what function to call when we are being shutdown:

        SetConsoleCtrlHandler(LsapShutdownNotification, TRUE);


    } else if (Pass == 2) {

        //
        // Write out any Audit Records that were cached during the
        // first stage of initialization.  The Audit Log will be opened
        // on the first write if necessary.
        //

        //
        // BUGBUG - ScottBi 8/6/92 - This action cannot be taken here
        // unless we know that the EventLog service is running.  For now,
        // an attempt is made to open the log each time an Audit Record
        // is generated, and the cache grows until a limit is reached,
        // at which point auditing is turned off and subsequent records
        // are discarded.
        //

        /*
        Status = LsapAdtWriteLog( NULL, (ULONG) 0);

        if (!NT_SUCCESS(Status)) {

            goto AuditInitError;
        }
        */
    }

AuditInitFinish:

    if (AcquiredLock) {

        LsapDbReleaseLock();
    }

    return(Status);

AuditInitError:

    //
    // If the Audit Log is full, signal the Log Full condition
    //

    if (Status == STATUS_LOG_FILE_FULL) {

        SecondaryStatus = LsapAdtSignalLogFull();
    }

    //
    // If auditing failed to initialize, output warning and disable
    // auditing.
    //

    if (Pass == 1) {

        LsapLogError(
            "LSA: Warning - Audit Initialization Pass 1 Returned 0x%lx\n"
            "     Auditing has been disabled\n",
            Status
            );

    } else {

        LsapLogError(
            "LSA: Warning - Audit Initialization Pass 2 Returned 0x%lx\n"
            "     Auditing has been disabled\n",
            Status
            );
    }

    LsapAdtEventsInformation.AuditingMode = FALSE;

    Status = LsarSetInformationPolicy(
                 LsapDbHandle,
                 PolicyAuditEventsInformation,
                 (PLSAPR_POLICY_INFORMATION) &LsapAdtEventsInformation
                 );

    goto AuditInitFinish;
}
コード例 #11
0
ファイル: taskmgr.c プロジェクト: CSRedRat/reactos-playground
int APIENTRY wWinMain(HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPWSTR    lpCmdLine,
                      int       nCmdShow)
{
    HANDLE hProcess;
    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;
    HANDLE hMutex;

    /* check wether we're already running or not */
    hMutex = CreateMutexW(NULL, TRUE, L"taskmgrros");
    if (hMutex && GetLastError() == ERROR_ALREADY_EXISTS)
    {
        /* Restore existing taskmanager and bring window to front */
        /* Relies on the fact that the application title string and window title are the same */
        HWND hTaskMgr;
        TCHAR szTaskmgr[128];

        LoadString(hInst, IDS_APP_TITLE, szTaskmgr, sizeof(szTaskmgr)/sizeof(TCHAR));
        hTaskMgr = FindWindow(NULL, szTaskmgr);

        if (hTaskMgr != NULL)
        {
            SendMessage(hTaskMgr, WM_SYSCOMMAND, SC_RESTORE, 0);
            SetForegroundWindow(hTaskMgr);
        }

        CloseHandle(hMutex);
        return 0;
    }
    else if (!hMutex)
    {
        return 1;
    }

    /* Initialize global variables */
    hInst = hInstance;

    /* Change our priority class to HIGH */
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
    SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
    CloseHandle(hProcess);

    /* Now lets get the SE_DEBUG_NAME privilege
     * so that we can debug processes
     */

    /* Get a token for this process.  */
    if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    {
        /* Get the LUID for the debug privilege.  */
        if (LookupPrivilegeValueW(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid))
        {
            tkp.PrivilegeCount = 1;  /* one privilege to set */
            tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

            /* Get the debug privilege for this process. */
            AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
        }
        CloseHandle(hToken);
    }

    /* Load our settings from the registry */
    LoadSettings();

    /* Initialize perf data */
    if (!PerfDataInitialize())
    {
        return -1;
    }

    /*
     * Set our shutdown parameters: we want to shutdown the very last,
     * without displaying any end task dialog if needed.
     */
    SetProcessShutdownParameters(1, SHUTDOWN_NORETRY);

    DialogBoxW(hInst, (LPCWSTR)IDD_TASKMGR_DIALOG, NULL, TaskManagerWndProc);

    /* Save our settings to the registry */
    SaveSettings();
    PerfDataUninitialize();
    CloseHandle(hMutex);
    if (hWindowMenu)
        DestroyMenu(hWindowMenu);
    return 0;
}
コード例 #12
0
bool VDAgent::run()
{
    DWORD session_id;
    DWORD event_thread_id;
    HANDLE event_thread;
    WNDCLASS wcls;

    if (!ProcessIdToSessionId(GetCurrentProcessId(), &session_id)) {
        vd_printf("ProcessIdToSessionId failed %lu", GetLastError());
        return false;
    }
    vd_printf("***Agent started in session %lu***", session_id);
    log_version();
    if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
        vd_printf("SetPriorityClass failed %lu", GetLastError());
    }
    if (!SetProcessShutdownParameters(0x100, 0)) {
        vd_printf("SetProcessShutdownParameters failed %lu", GetLastError());
    }
    if (_system_version == SYS_VER_WIN_7_CLASS) {
        _user_lib = LoadLibrary(L"User32.dll");
        if (!_user_lib) {
            vd_printf("LoadLibrary failed %lu", GetLastError());
            return false;
        }
        _add_clipboard_listener =
            (PCLIPBOARD_OP)GetProcAddress(_user_lib, "AddClipboardFormatListener");
        _remove_clipboard_listener =
            (PCLIPBOARD_OP)GetProcAddress(_user_lib, "RemoveClipboardFormatListener");
        if (!_add_clipboard_listener || !_remove_clipboard_listener) {
            vd_printf("GetProcAddress failed %lu", GetLastError());
            cleanup();
            return false;
        }
    }
    _control_event = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (!_control_event) {
        vd_printf("CreateEvent() failed: %lu", GetLastError());
        cleanup();
        return false;
    }
    _stop_event = OpenEvent(SYNCHRONIZE, FALSE, VD_AGENT_STOP_EVENT);
    memset(&wcls, 0, sizeof(wcls));
    wcls.lpfnWndProc = &VDAgent::wnd_proc;
    wcls.lpszClassName = VD_AGENT_WINCLASS_NAME;
    if (!RegisterClass(&wcls)) {
        vd_printf("RegisterClass() failed: %lu", GetLastError());
        cleanup();
        return false;
    }
    _desktop_layout = new DesktopLayout();
    if (_desktop_layout->get_display_count() == 0) {
        vd_printf("No QXL devices!");
    }
    if (!init_vio_serial()) {
        cleanup();
        return false;
    }
    if (!ReadFileEx(_vio_serial, _read_buf, sizeof(VDIChunk), &_read_overlapped, read_completion) &&
            GetLastError() != ERROR_IO_PENDING) {
        vd_printf("vio_serial read error %lu", GetLastError());
        cleanup();
        return false;
    }
    _running = true;
    event_thread = CreateThread(NULL, 0, event_thread_proc, NULL, 0, &event_thread_id);
    if (!event_thread) {
        vd_printf("CreateThread() failed: %lu", GetLastError());
        cleanup();
        return false;
    }
    send_announce_capabilities(true);
    vd_printf("Connected to server");

    while (_running) {
        input_desktop_message_loop();
        if (_clipboard_owner == owner_guest) {
            set_clipboard_owner(owner_none);
        }
    }
    vd_printf("Agent stopped");
    CloseHandle(event_thread);
    cleanup();
    return true;
}
コード例 #13
0
ファイル: EpgDataCap_Bon.cpp プロジェクト: ACUVE/EDCB
BOOL CEpgDataCap_BonApp::InitInstance()
{
	// アプリケーション マニフェストが visual スタイルを有効にするために、
	// ComCtl32.dll Version 6 以降の使用を指定する場合は、
	// Windows XP に InitCommonControlsEx() が必要です。さもなければ、ウィンドウ作成はすべて失敗します。
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// アプリケーションで使用するすべてのコモン コントロール クラスを含めるには、
	// これを設定します。
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	SetProcessShutdownParameters(0x300, 0);

	AfxEnableControlContainer();

	// ダイアログにシェル ツリー ビューまたはシェル リスト ビュー コントロールが
	// 含まれている場合にシェル マネージャーを作成します。
	CShellManager *pShellManager = new CShellManager;

	// 標準初期化
	// これらの機能を使わずに最終的な実行可能ファイルの
	// サイズを縮小したい場合は、以下から不要な初期化
	// ルーチンを削除してください。
	// 設定が格納されているレジストリ キーを変更します。
	// TODO: 会社名または組織名などの適切な文字列に
	// この文字列を変更してください。
	SetRegistryKey(_T("アプリケーション ウィザードで生成されたローカル アプリケーション"));

	CCmdLineUtil cCmdUtil;
	ParseCommandLine(cCmdUtil);

	CEpgDataCap_BonDlg dlg;

	map<CString, CString>::iterator itr;
	dlg.SetIniMin(FALSE);
	dlg.SetIniView(TRUE);
	dlg.SetIniNW(TRUE);
	for( itr = cCmdUtil.m_CmdList.begin(); itr != cCmdUtil.m_CmdList.end(); itr++ ){
		if( itr->first.CompareNoCase(L"d") == 0 ){
			dlg.SetInitBon(itr->second);
			OutputDebugString(itr->second);
		}else if( itr->first.CompareNoCase(L"min") == 0 ){
			dlg.SetIniMin(TRUE);
		}else if( itr->first.CompareNoCase(L"noview") == 0 ){
			dlg.SetIniView(FALSE);
		}else if( itr->first.CompareNoCase(L"nonw") == 0 ){
			dlg.SetIniNW(FALSE);
		}else if( itr->first.CompareNoCase(L"nwudp") == 0 ){
			dlg.SetIniNWUDP(TRUE);
		}else if( itr->first.CompareNoCase(L"nwtcp") == 0 ){
			dlg.SetIniNWTCP(TRUE);
		}
	}


	m_pMainWnd = &dlg;
	INT_PTR nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: ダイアログが <OK> で消された時のコードを
		//  記述してください。
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: ダイアログが <キャンセル> で消された時のコードを
		//  記述してください。
	}

	// 上で作成されたシェル マネージャーを削除します。
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// ダイアログは閉じられました。アプリケーションのメッセージ ポンプを開始しないで
	//  アプリケーションを終了するために FALSE を返してください。
	return FALSE;
}