int MachineInstaller::PerformMachineInstallSetup()
{
	wchar_t packageName[512];

	if (!findPackageFromEmbeddedZip(packageName, sizeof(packageName))) {
		MessageBox(NULL, L"Corrupt installer", L"Cannot find package name for installer, is it created correctly?", MB_OK);
		return ERROR_INVALID_PARAMETER;
	}

	wchar_t machineInstallFolder[MAX_PATH];
	SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, machineInstallFolder);
	wcscat(machineInstallFolder, L"\\SquirrelMachineInstalls");

	// NB: This is the DACL for Program Files
	wchar_t sddl[512] = L"D:PAI(A;;FA;;;S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464)(A;CIIO;GA;;;S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464)(A;;0x1301bf;;;SY)(A;OICIIO;GA;;;SY)(A;;0x1301bf;;;BA)(A;OICIIO;GA;;;BA)(A;;0x1200a9;;;BU)(A;OICIIO;GXGR;;;BU)(A;OICIIO;GA;;;CO)";

	if (IsWindows8OrGreater()) {
		// Add ALL APPLICATION PACKAGES account (Only available on Windows 8 and greater)
		wcscat(sddl, L"(A;;0x1200a9;;;AC)(A;OICIIO;GXGR;;;AC)");
	}

	PSECURITY_DESCRIPTOR descriptor;
	ConvertStringSecurityDescriptorToSecurityDescriptor(
		sddl,
		SDDL_REVISION_1,
		&descriptor, NULL);

	SECURITY_ATTRIBUTES attrs;
	attrs.nLength = sizeof(SECURITY_ATTRIBUTES);
	attrs.bInheritHandle = false;
	attrs.lpSecurityDescriptor = descriptor;

	if (!CreateDirectory(machineInstallFolder, &attrs) && GetLastError() != ERROR_ALREADY_EXISTS) {
		LocalFree(descriptor);
		return GetLastError();
	}

	LocalFree(descriptor);

	wcscat(machineInstallFolder, L"\\");
	wcscat(machineInstallFolder, packageName);
	wcscat(machineInstallFolder, L".exe");

	wchar_t ourFile[MAX_PATH];
	HMODULE hMod = GetModuleHandle(NULL);
	GetModuleFileName(hMod, ourFile, _countof(ourFile));

	if (!CopyFile(ourFile, machineInstallFolder, false)) {
		return GetLastError();
	}

	HKEY runKey;
	DWORD dontcare;
	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &runKey, &dontcare) != ERROR_SUCCESS) {
		return GetLastError();
	}

	wcscat_s(machineInstallFolder, L" --checkInstall");

	if (RegSetValueEx(runKey, packageName, 0, REG_SZ, (BYTE*)machineInstallFolder, (wcsnlen(machineInstallFolder, sizeof(machineInstallFolder)) + 1) * sizeof(wchar_t)) != ERROR_SUCCESS) {
		return GetLastError();
	}

	RegCloseKey(runKey);
	return 0;
}
int smpd_set_smpd_data(const char *key, const char *value)
{
#ifdef HAVE_WINDOWS_H
    HKEY tkey;
    DWORD len, result;
    char err_msg[512];

    smpd_enter_fn(FCNAME);

    if (key == NULL || value == NULL)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCreateKeyEx(HKEY_LOCAL_MACHINE, SMPD_REGISTRY_KEY,
	0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &tkey, NULL);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to open the HKEY_LOCAL_MACHINE\\" SMPD_REGISTRY_KEY " registry key, error %d\n", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    len = (DWORD)(strlen(value)+1);
    result = RegSetValueEx(tkey, key, 0, REG_SZ, (const BYTE *)value, len);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to write the smpd registry value '%s:%s', error %d\n", key, value, result);
	smpd_err_printf("%s\n", err_msg);
	RegCloseKey(tkey);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCloseKey(tkey);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_LOCAL_MACHINE\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
#else
    int result;
    smpd_data_t *list = NULL, *node;
    int found = 0;
    FILE *fout;
    char *str;
    int maxlen;
    char buffer[1024];
    char name_str[SMPD_MAX_NAME_LENGTH];
    char value_str[SMPD_MAX_VALUE_LENGTH];

    smpd_enter_fn(FCNAME);

    smpd_dbg_printf("setting smpd data: %s=%s\n", key, value);

    list = smpd_parse_smpd_file();
    fout = smpd_open_smpd_file(SMPD_TRUE);
    if (fout == NULL)
    {
	smpd_err_printf("Unable to open the .smpd file\n");
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }
    while (list)
    {
	node = list;
	list = list->next;
	if (strcmp(key, node->name) == 0)
	{
	    strcpy(node->value, value);
	    found = 1;
	}
	if (fout)
	{
	    str = buffer;
	    maxlen = 1024;
	    if (MPIU_Str_add_string_arg(&str, &maxlen, node->name, node->value) == MPIU_STR_SUCCESS)
	    {
		buffer[strlen(buffer)-1] = '\0'; /* remove the trailing space */
		smpd_dbg_printf("writing '%s' to .smpd file\n", buffer);
		fprintf(fout, "%s\n", buffer);
	    }
	}
	MPIU_Free(node);
    }
    if (!found && fout)
    {
	str = buffer;
	maxlen = 1024;
	if (MPIU_Str_add_string_arg(&str, &maxlen, key, value) == MPIU_STR_SUCCESS)
	{
	    buffer[strlen(buffer)-1] = '\0'; /* remove the trailing space */
	    smpd_dbg_printf("writing '%s' to .smpd file\n", buffer);
	    fprintf(fout, "%s\n", buffer);
	}
	fclose(fout);
	smpd_exit_fn(FCNAME);
	return SMPD_SUCCESS;
    }
    if (fout != NULL)
    {
	fclose(fout);
	smpd_exit_fn(FCNAME);
	return SMPD_SUCCESS;
    }
    smpd_exit_fn(FCNAME);
    return SMPD_FAIL;
#endif
}
示例#3
0
Error
Win32Prefs::
Initialize()
{
    LONG    result;
	uint32  length;
    char    path[MAX_PATH] = {0x00};
    char    cwd[MAX_PATH]= {0x00};
    Error   error = kError_UnknownErr;

    // Where are we starting the program from?
    GetCurrentDirectory(sizeof(cwd), cwd);

    if(m_prefsKey)
	{
        // people DO move their apps around on windows
        length = sizeof(path);

        error = GetPrefString(kInstallDirPref, path, &length);

		char foo[MAX_PATH] = {0x00};
		sprintf(foo,"%s\\freeamp.exe",cwd);
		WIN32_FIND_DATA win32fd;

        // check for freeamp exe in cwd
		HANDLE h = FindFirstFile(foo, &win32fd);

		if (h != INVALID_HANDLE_VALUE) 
        {
			//if (win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 
            {
				if(IsError(error) || strcmp(cwd, path))
				{
					result = RegSetValueEx( m_prefsKey,
											kInstallDirPref, 
											NULL, 
											REG_SZ, 
											(LPBYTE)cwd, 
											strlen(cwd) + 1);

                    strcat(cwd, "\\db");

                    result = RegSetValueEx( m_prefsKey,
											kDatabaseDirPref, 
											NULL, 
											REG_SZ, 
											(LPBYTE)cwd, 
											strlen(cwd) + 1);
				}
			}

            FindClose(h);
		}
        error = kError_NoErr;
    }
    else // keys need to be created for the first time
    {
        DWORD disposition;
        HKEY freeampKey;
        HKEY versionKey;

        // create the main key in the windows registry
        result = RegCreateKeyEx(kMainKey,
                                kFreeAmpKey,
                                NULL, 
                                "",
                                REG_OPTION_NON_VOLATILE,
                                KEY_ALL_ACCESS,
                                NULL,
                                &freeampKey,
                                &disposition);

        if(result == ERROR_SUCCESS)
        {
            // create the version key under the freeamp key
            result = RegCreateKeyEx(freeampKey,
                                    kFreeAmpVersionKey,
                                    NULL, 
                                    "",
                                    REG_OPTION_NON_VOLATILE,
                                    KEY_ALL_ACCESS,
                                    NULL,
                                    &versionKey,
                                    &disposition);
        }

        if(result == ERROR_SUCCESS)
        {
            // create the version key under the freeamp key
            result = RegCreateKeyEx(versionKey,
                                    kMainComponentKey,
                                    NULL, 
                                    "",
                                    REG_OPTION_NON_VOLATILE,
                                    KEY_ALL_ACCESS,
                                    NULL,
                                    &m_prefsKey,
                                    &disposition);
        }

        if(result != ERROR_SUCCESS)
            error = kError_NoPrefs;

        RegCloseKey(freeampKey);
        RegCloseKey(versionKey);
    }

    SetDefaults();
    Save();

    return error;
}
示例#4
0
//---------------------------------------------------------------------------
// RegisterServer
// Create registry entries and setup the shell extension
//---------------------------------------------------------------------------
BOOL RegisterServer() {
	int      i;
	HKEY     hKey;
	LRESULT  lResult;
	DWORD    dwDisp;
	TCHAR    szSubKey[MAX_PATH];
	TCHAR    szModule[MAX_PATH];
	TCHAR    szDefaultPath[MAX_PATH];

	GetModuleFileName(_hModule, szDefaultPath, MAX_PATH);
	TCHAR* pDest = StrRChr(szDefaultPath, NULL, TEXT('\\'));
	pDest++;
	pDest[0] = 0;
	lstrcat(szDefaultPath, szNppName);

	if (!CheckNpp(szDefaultPath)) {
		MsgBoxError(TEXT("To register the Notepad++ shell extension properly,\r\nplace NppShell.dll in the same directory as the Notepad++ executable."));
		//return FALSE;
	}

	//get this app's path and file name
	GetModuleFileName(_hModule, szModule, MAX_PATH);

	static DOREGSTRUCT ClsidEntries[] = {
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s"),									NULL,					REG_SZ,		szShellExtensionTitle},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\InprocServer32"),					NULL,					REG_SZ,		szModule},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\InprocServer32"),					TEXT("ThreadingModel"),	REG_SZ,		TEXT("Apartment")},

		//Settings
		// Context menu
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("Title"),			REG_SZ,		szDefaultMenutext},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("Path"),			REG_SZ,		szDefaultPath},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("Custom"),			REG_SZ,		szDefaultCustomcommand},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("ShowIcon"),		REG_DWORD,	(LPTSTR)&showIcon},
		// Icon
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("Dynamic"),		REG_DWORD,	(LPTSTR)&isDynamic},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("Maxtext"),		REG_DWORD,	(LPTSTR)&maxText},
		{HKEY_CLASSES_ROOT,	TEXT("CLSID\\%s\\Settings"),						TEXT("IconID"),			REG_DWORD,	(LPTSTR)&iconID},

		//Registration
		// Context menu
		{HKEY_CLASSES_ROOT,	TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++")sz64,	NULL,					REG_SZ,		szGUID},
		// Icon
		//{HKEY_CLASSES_ROOT,	TEXT("Notepad++_file\\shellex\\IconHandler"),		NULL,					REG_SZ,		szGUID},

		{NULL,				NULL,												NULL,					REG_SZ,		NULL}
	};

	// First clear any old entries
	UnregisterServer();

	// Register the CLSID entries
	for(i = 0; ClsidEntries[i].hRootKey; i++) {
		wsprintf(szSubKey, ClsidEntries[i].szSubKey, szGUID);
		lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
		if (NOERROR == lResult) {
			TCHAR szData[MAX_PATH];
			// If necessary, create the value string
			if (ClsidEntries[i].type == REG_SZ) {
				wsprintf(szData, ClsidEntries[i].szData, szModule);
				lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, ClsidEntries[i].type, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR));
			} else {
				lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, ClsidEntries[i].type, (LPBYTE)ClsidEntries[i].szData, sizeof(DWORD));
			}
			RegCloseKey(hKey);
		}
		else
			return FALSE;
	}
	return TRUE;
}
示例#5
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	HKL kl;
	MessageBox(NULL,"DEBUG\n","Debug",0);
	HKEY hk = NULL;
	if( ERROR_SUCCESS != RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\New Chewing IM", 0, 
			NULL, 0, KEY_ALL_ACCESS , NULL, &hk, NULL) )
		hk = NULL;
	printf("DEBUG\n");
	if( strstr( lpCmdLine, "/uninstall" ) )
	{
	
		char temp[1024];
		_gen_event_name(temp, sizeof(temp), "ChewingServer");
		HWND hwnd = FindWindow(temp, NULL);
		if ( hwnd ) {
			SendMessage(hwnd, WM_DESTROY, 0, 0);
		}


		if( hk )
		{
			DWORD type = REG_DWORD, size = sizeof(DWORD);
			if(	ERROR_SUCCESS == RegQueryValueEx( hk, "KeyboardLayout", 0, &type, (LPBYTE)&kl, &size ) )
			{
				UnloadKeyboardLayout( kl );
				char klstr[10];
				wsprintf( klstr, "%X", kl );
				char regpath[256];
				lstrcpy( regpath, "Keyboard Layout\\Preload" );
				HKEY hk2 = NULL;

				// Windows NT only, 9x will be supported in the future
				if( (GetVersion() < 0x80000000) )
				{
					if( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, regpath, &hk2 ) )
					{
						for( int i = 1; i <= 100; ++i )
						{
							char num[4];
							wsprintf( num, "%d", i );
							type = REG_SZ;	size = sizeof(regpath);
							if(	ERROR_SUCCESS != RegQueryValueEx( hk2, num, 0, &type, (LPBYTE)regpath, &size ) )
								continue;
							if( 0 == lstrcmp( regpath, klstr ) )
							{
								RegDeleteValue( hk2, num );
								break;
							}
						}
						RegCloseKey(hk2);
					}
				}

				wsprintf( regpath, "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\%s", klstr );
				RegDeleteKey( HKEY_LOCAL_MACHINE, regpath );
			}
		}
	}
	else if ( strstr( lpCmdLine, "/privilege" ) )
	{
		enable_access("ch_index.dat");
		enable_access("dict.dat");
		enable_access("us_freq.dat");
		enable_access("ph_index.dat");
		enable_access("fonetree.dat");
	}
	else
	{
		char path[MAX_PATH];
		GetSystemDirectory(path, MAX_PATH);

		lstrcat( path, "\\Chewing.ime" );
		printf("Install Path:%s\n",path);
		kl = ImmInstallIME( path, 
			(GetVersion() < 0x80000000) ? "中文 (繁體) - 新酷音輸入法" : "新酷音輸入法" );

		printf("Imm Install IME Result: %d\n",kl);
		if( hk )
			RegSetValueEx( hk, "KeyboardLayout", 0, REG_DWORD, (LPBYTE)&kl, sizeof(DWORD) );
	}

	RegCloseKey( hk );

	return 0;
}
示例#6
0
int create_regkeys(char *identifier){
  HKEY key,key2;
  DWORD dispositions;
  int i,j;
  char *values[] = {
    LATEST_RECORD_NAME,
    LATEST_TIME_NAME,
    NULL
  };

  DWORD zero = 0;

  if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,
		    APP_ROOT_KEY "\\" APP_SUB_KEY "\\"
		    APP_VERSION,
		    0,
		    NULL,
		    REG_OPTION_NON_VOLATILE,
		    KEY_CREATE_SUB_KEY,
		    NULL,
		    &key,
		    &dispositions) != ERROR_SUCCESS){
    return -1;
  }
  if(RegCreateKeyEx(key, 
		    identifier, 
		    0,
		    NULL,
		    REG_OPTION_NON_VOLATILE,
		    KEY_CREATE_SUB_KEY,
		    NULL,
		    &key2,
		    &dispositions)){
    RegCloseKey(key);
    return -1;
  }
  RegCloseKey(key);
  for(i=0; category_tab[i] != NULL; ++i){
    if(RegCreateKeyEx(key2,
		      category_tab[i],
		      0,
		      NULL,
		      REG_OPTION_NON_VOLATILE,
		      KEY_SET_VALUE,
		      NULL,
		      &key,
		      &dispositions) != ERROR_SUCCESS){
      RegCloseKey(key2);
      return -1;
    }
    for(j=0; values[j] != NULL; ++j){
      if(RegSetValueEx(key, 
		       values[j], 
		       0, 
		       REG_DWORD,
		       (BYTE *) &zero,
		       sizeof(DWORD)) != ERROR_SUCCESS){
	RegCloseKey(key);
	RegCloseKey(key2);
	return -1;
      }
    }
    RegCloseKey(key);
  }
  RegCloseKey(key2);
  return 0;
}
示例#7
0
int lutil_srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
		LPCTSTR lpszBinaryPathName, int auto_start)
{
	HKEY		hKey;
	DWORD		dwValue, dwDisposition;
	SC_HANDLE	schSCManager, schService;
	char *sp = strchr( lpszBinaryPathName, ' ');

	if ( sp ) *sp = '\0';
	fprintf( stderr, "The install path is %s.\n", lpszBinaryPathName );
	if ( sp ) *sp = ' ';
	if ((schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT|SC_MANAGER_CREATE_SERVICE ) ) != NULL )
	{
	 	if ((schService = CreateService( 
							schSCManager, 
							lpszServiceName, 
							lpszDisplayName, 
							SERVICE_ALL_ACCESS, 
							SERVICE_WIN32_OWN_PROCESS, 
							auto_start ? SERVICE_AUTO_START : SERVICE_DEMAND_START, 
							SERVICE_ERROR_NORMAL, 
							lpszBinaryPathName, 
							NULL, NULL, NULL, NULL, NULL)) != NULL)
		{
			char regpath[132];
			CloseServiceHandle(schService);
			CloseServiceHandle(schSCManager);

			snprintf( regpath, sizeof regpath,
				"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
				lpszServiceName );
			/* Create the registry key for event logging to the Windows NT event log. */
			if ( RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
				regpath, 0, 
				"REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, 
				&dwDisposition) != ERROR_SUCCESS)
			{
				fprintf( stderr, "RegCreateKeyEx() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
				RegCloseKey(hKey);
				return(0);
			}
			if ( sp ) *sp = '\0';
			if ( RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, lpszBinaryPathName, strlen(lpszBinaryPathName) + 1) != ERROR_SUCCESS)
			{
				fprintf( stderr, "RegSetValueEx(EventMessageFile) failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
				RegCloseKey(hKey);
				return(0);
			}

			dwValue = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
			if ( RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(DWORD)) != ERROR_SUCCESS) 
			{
				fprintf( stderr, "RegCreateKeyEx(TypesSupported) failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
				RegCloseKey(hKey);
				return(0);
			}
			RegCloseKey(hKey);
			return(1);
		}
		else
		{
			fprintf( stderr, "CreateService() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
			CloseServiceHandle(schSCManager);
			return(0);
		}
	}
	else
		fprintf( stderr, "OpenSCManager() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
	return(0);
}
示例#8
0
// Dialog box handling functions
void
vncProperties::Show(BOOL show, BOOL usersettings)
{
	if (show)
	{
		if (!m_allowproperties)
		{
			// If the user isn't allowed to override the settings then tell them
			MessageBox(NULL, NO_OVERRIDE_ERR, "WinVNC Error", MB_OK | MB_ICONEXCLAMATION);
			return;
		}

		// Verify that we know who is logged on
		if (usersettings) {
			char username[UNLEN+1];
			if (!vncService::CurrentUser(username, sizeof(username)))
				return;
			if (strcmp(username, "") == 0) {
				MessageBox(NULL, NO_CURRENT_USER_ERR, "WinVNC Error", MB_OK | MB_ICONEXCLAMATION);
				return;
			}
		} else {
			// We're trying to edit the default local settings - verify that we can
			HKEY hkLocal, hkDefault;
			BOOL canEditDefaultPrefs = 1;
			DWORD dw;
			if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
				WINVNC_REGISTRY_KEY,
				0, REG_NONE, REG_OPTION_NON_VOLATILE,
				KEY_READ, NULL, &hkLocal, &dw) != ERROR_SUCCESS)
				canEditDefaultPrefs = 0;
			else if (RegCreateKeyEx(hkLocal,
				"Default",
				0, REG_NONE, REG_OPTION_NON_VOLATILE,
				KEY_WRITE | KEY_READ, NULL, &hkDefault, &dw) != ERROR_SUCCESS)
				canEditDefaultPrefs = 0;
			if (hkLocal) RegCloseKey(hkLocal);
			if (hkDefault) RegCloseKey(hkDefault);

			if (!canEditDefaultPrefs) {
				MessageBox(NULL, CANNOT_EDIT_DEFAULT_PREFS, "WinVNC Error", MB_OK | MB_ICONEXCLAMATION);
				return;
			}
		}

		// Now, if the dialog is not already displayed, show it!
		if (!m_dlgvisible)
		{
			if (usersettings)
				vnclog.Print(LL_INTINFO, VNCLOG("show per-user Properties\n"));
			else
				vnclog.Print(LL_INTINFO, VNCLOG("show default system Properties\n"));

			// Load in the settings relevant to the user or system
			Load(usersettings);

			for (;;)
			{
				m_returncode_valid = FALSE;

				// Do the dialog box
				int result = DialogBoxParam(hAppInstance,
				    MAKEINTRESOURCE(IDD_PROPERTIES), 
				    NULL,
				    (DLGPROC) DialogProc,
				    (LONG) this);

				if (!m_returncode_valid)
				    result = IDCANCEL;

				vnclog.Print(LL_INTINFO, VNCLOG("dialog result = %d\n"), result);

				if (result == -1)
				{
					// Dialog box failed, so quit
					PostQuitMessage(0);
					return;
				}

				// We're allowed to exit if the password is not empty
				char passwd[MAXPWLEN];
				m_server->GetPassword(passwd);
				{
				    vncPasswd::ToText plain(passwd);
				    if ((strlen(plain) != 0) || !m_server->AuthRequired())
					break;
				}

				vnclog.Print(LL_INTERR, VNCLOG("warning - empty password\n"));

				// The password is empty, so if OK was used then redisplay the box,
				// otherwise, if CANCEL was used, close down WinVNC
				if (result == IDCANCEL)
				{
				    vnclog.Print(LL_INTERR, VNCLOG("no password - QUITTING\n"));
				    PostQuitMessage(0);
				    return;
				}

				// If we reached here then OK was used & there is no password!
				int result2 = MessageBox(NULL, NO_PASSWORD_WARN,
				    "WinVNC Warning", MB_OK | MB_ICONEXCLAMATION);

				omni_thread::sleep(4);
			}

			// Load in all the settings
			Load(TRUE);
		}
	}
}
示例#9
0
void
vncProperties::Load(BOOL usersettings)
{
  // Initialize to 'sane' defaults for our purposes
	m_pref_QuerySetting=2;
	m_pref_QueryTimeout=10;
	m_pref_IdleTimeout=0;
	m_pref_EnableRemoteInputs=TRUE;
	m_pref_DisableLocalInputs=TRUE;
	m_pref_PollUnderCursor=FALSE;
	m_pref_PollForeground=TRUE;
	m_pref_PollFullScreen=TRUE;

	return;

	char username[UNLEN+1];
	HKEY hkLocal, hkLocalUser, hkDefault;
	DWORD dw;

	// NEW (R3) PREFERENCES ALGORITHM
	// 1.	Look in HKEY_LOCAL_MACHINE/Software/ORL/WinVNC3/%username%
	//		for sysadmin-defined, user-specific settings.
	// 2.	If not found, fall back to %username%=Default
	// 3.	If AllowOverrides is set then load settings from
	//		HKEY_CURRENT_USER/Software/ORL/WinVNC3

	// GET THE CORRECT KEY TO READ FROM

	// Get the user name / service name
	if (!vncService::CurrentUser((char *)&username, sizeof(username)))
		return;

	// If there is no user logged on them default to SYSTEM
	if (strcmp(username, "") == 0)
		strcpy((char *)&username, "SYSTEM");

	// Try to get the machine registry key for WinVNC
	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
		WINVNC_REGISTRY_KEY,
		0, REG_NONE, REG_OPTION_NON_VOLATILE,
		KEY_READ, NULL, &hkLocal, &dw) != ERROR_SUCCESS)
		return;

	// Now try to get the per-user local key
	if (RegOpenKeyEx(hkLocal,
		username,
		0, KEY_READ,
		&hkLocalUser) != ERROR_SUCCESS)
		hkLocalUser = NULL;

	// Get the default key
	if (RegCreateKeyEx(hkLocal,
		"Default",
		0, REG_NONE, REG_OPTION_NON_VOLATILE,
		KEY_READ,
		NULL,
		&hkDefault,
		&dw) != ERROR_SUCCESS)
		hkDefault = NULL;

	// LOAD THE MACHINE-LEVEL PREFS

	// Logging/debugging prefs
	vnclog.Print(LL_INTINFO, VNCLOG("loading local-only settings\n"));
	vnclog.SetMode(LoadInt(hkLocal, "DebugMode", 0));
	vnclog.SetLevel(LoadInt(hkLocal, "DebugLevel", 0));

	// Authentication required, loopback allowed, loopbackOnly
	m_server->SetLoopbackOnly(LoadInt(hkLocal, "LoopbackOnly", false));
	if (m_server->LoopbackOnly())
		m_server->SetLoopbackOk(true);
	else
		m_server->SetLoopbackOk(LoadInt(hkLocal, "AllowLoopback", false));
	m_server->SetAuthRequired(LoadInt(hkLocal, "AuthRequired", true));
	m_server->SetConnectPriority(LoadInt(hkLocal, "ConnectPriority", 0));
	if (!m_server->LoopbackOnly())
	{
		char *authhosts = LoadString(hkLocal, "AuthHosts");
		if (authhosts != 0) {
			m_server->SetAuthHosts(authhosts);
			delete [] authhosts;
		} else {
			m_server->SetAuthHosts(0);
		}
	} else {
		m_server->SetAuthHosts(0);
	}

	// LOAD THE USER PREFERENCES

	// Set the default user prefs
	vnclog.Print(LL_INTINFO, VNCLOG("clearing user settings\n"));
  m_pref_HTTPConnect = TRUE;
	m_pref_AutoPortSelect=TRUE;
	m_pref_PortNumber=5900;
	m_pref_SockConnect=TRUE;
	m_pref_CORBAConn=FALSE;
	{
	    vncPasswd::FromClear crypt;
	    memcpy(m_pref_passwd, crypt, MAXPWLEN);
	}
	m_pref_QuerySetting=2;
	m_pref_QueryTimeout=10;
	m_pref_IdleTimeout=0;
	m_pref_EnableRemoteInputs=TRUE;
	m_pref_DisableLocalInputs=FALSE;
	m_pref_LockSettings=-1;
	m_pref_PollUnderCursor=FALSE;
	m_pref_PollForeground=TRUE;
	m_pref_PollFullScreen=FALSE;
	m_pref_PollConsoleOnly=TRUE;
	m_pref_PollOnEventOnly=FALSE;
	m_pref_RemoveWallpaper=TRUE;
  m_alloweditclients = TRUE;
	m_allowshutdown = TRUE;
	m_allowproperties = TRUE;

	// Load the local prefs for this user
	if (hkDefault != NULL)
	{
		vnclog.Print(LL_INTINFO, VNCLOG("loading DEFAULT local settings\n"));
		LoadUserPrefs(hkDefault);
		m_allowshutdown = LoadInt(hkDefault, "AllowShutdown", m_allowshutdown);
		m_allowproperties = LoadInt(hkDefault, "AllowProperties", m_allowproperties);
		m_alloweditclients = LoadInt(hkDefault, "AllowEditClients", m_alloweditclients);
	}

	// Are we being asked to load the user settings, or just the default local system settings?
	if (usersettings) {
		// We want the user settings, so load them!

		if (hkLocalUser != NULL)
		{
			vnclog.Print(LL_INTINFO, VNCLOG("loading \"%s\" local settings\n"), username);
			LoadUserPrefs(hkLocalUser);
			m_allowshutdown = LoadInt(hkLocalUser, "AllowShutdown", m_allowshutdown);
			m_allowproperties = LoadInt(hkLocalUser, "AllowProperties", m_allowproperties);
		  m_alloweditclients = LoadInt(hkLocalUser, "AllowEditClients", m_alloweditclients);
		}

		// Now override the system settings with the user's settings
		// If the username is SYSTEM then don't try to load them, because there aren't any...
		if (m_allowproperties && (strcmp(username, "SYSTEM") != 0))
		{
			HKEY hkGlobalUser;
			if (RegCreateKeyEx(HKEY_CURRENT_USER,
				WINVNC_REGISTRY_KEY,
				0, REG_NONE, REG_OPTION_NON_VOLATILE,
				KEY_READ, NULL, &hkGlobalUser, &dw) == ERROR_SUCCESS)
			{
				vnclog.Print(LL_INTINFO, VNCLOG("loading \"%s\" global settings\n"), username);
				LoadUserPrefs(hkGlobalUser);
				RegCloseKey(hkGlobalUser);

				// Close the user registry hive so it can unload if required
				RegCloseKey(HKEY_CURRENT_USER);
			}
		}
	} else {
		vnclog.Print(LL_INTINFO, VNCLOG("bypassing user-specific settings (both local and global)\n"));
	}

	if (hkLocalUser != NULL) RegCloseKey(hkLocalUser);
	if (hkDefault != NULL) RegCloseKey(hkDefault);
	RegCloseKey(hkLocal);

	// Make the loaded settings active..
	ApplyUserPrefs();

	// Note whether we loaded the user settings or just the default system settings
	m_usersettings = usersettings;
}
示例#10
0
BOOL CLoadDll::LoadExtendLibrary()
{
	if (!m_xmlMarkup.IsWellFormed())
	{
		return FALSE;
	}

	if (m_bHaveExtend)
	{
		TCHAR cPath[MAX_PATH] = {0};
		::GetModuleFileName(NULL,cPath,MAX_PATH);
		CString strPath = cPath;
		int nPos = strPath.ReverseFind('\\');
		CString strName = strPath.Mid(nPos+1);

		//if(strName.CompareNoCase(_T("communicator.exe")))
		//	return false;
		wchar_t buf[_MAX_PATH];
		CString strLyncPath = _T("");
		strPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
		strPath += strName;
		swprintf_s(buf,strPath);
		HKEY hKey=NULL;
		if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,buf,0,NULL,REG_OPTION_NON_VOLATILE,KEY_READ|KEY_QUERY_VALUE|KEY_WOW64_64KEY,NULL,&hKey,NULL)==ERROR_SUCCESS)
		{
			wchar_t path[_MAX_PATH];
			DWORD size=_MAX_PATH;
			if (RegQueryValueEx(hKey,L"Path",0,NULL,(BYTE*)&path,&size)==ERROR_SUCCESS)
			{
				strLyncPath = path;
			}
			RegCloseKey(hKey);
		}


		TCHAR szPath[MAX_PATH] = {0};
		HRESULT hr = SHGetFolderPath(NULL,CSIDL_COMMON_APPDATA,NULL,0,szPath);
		wchar_t path[_MAX_PATH*2];
		GetTempPath(_countof(path),path);
		CString strFile = CString(path);
		strFile += _T("LyncPlusUpdate\\Lyncplus.xml");
		BOOL bExist=PathFileExists(strFile);
		MCD_STR strMsi = _T("");
		if(bExist)
		{
			CMarkup	_xmlMarkup;
			if(_xmlMarkup.Load(strFile.GetBuffer()))
			{
				if (bFindNode(&_xmlMarkup,_T("AutoUpdate")))
				{
					strMsi = _xmlMarkup.GetAttrib(_T("Msi"));
					MCD_STR strVer = _xmlMarkup.GetAttrib(_T("ver"));
					CString _strVer = strVer.c_str();
					if(_strVer!=m_strCurVer)
					{
						CString _strFile = CString(path);
						_strFile += _T("LyncPlusUpdate\\");
						_strFile += strMsi.c_str();
						bExist=PathFileExists(_strFile); 
						if(bExist)
						{
							STARTUPINFO startupInfo;
							memset(&startupInfo,0,sizeof(startupInfo));
							startupInfo.cb=sizeof(startupInfo);
							PROCESS_INFORMATION processInfo;
							memset(&processInfo,0,sizeof(processInfo));
							wchar_t cmdLine[2048];
							//swprintf_s(cmdLine,L"msiexec.exe /i \"%s\"  %s",_strFile, _T("/qb"));
							swprintf_s(cmdLine,_T("msiexec.exe /i \"%s\" TARGETDIR=\"%s\" %s"),_strFile,strLyncPath, _T("/qb"));
							//swprintf_s(cmdLine,L"msiexec.exe /i \"%s\"  REINSTALLMODE=\"amus\"  /norestart  TARGETDIR=\"%s\" %s",_strFile,strLyncPath, _T("/qb"));
							//swprintf_s(cmdLine,L"msiexec.exe /i \"%s\" %s",_strFile,_T("/qn"));
							DWORD code;

							if (!CreateProcess(NULL,cmdLine,NULL,NULL,TRUE,0,NULL,NULL,&startupInfo,&processInfo))
							{
								//DeleteFile(_strFile);
							}
							else
							{
								// wait for the installer to finish
								WaitForSingleObject(processInfo.hProcess,INFINITE);
								DeleteFile(_strFile);
								GetExitCodeProcess(processInfo.hProcess,&code);
							}
						}
					}
				}
			}
		}

		//STARTUPINFO startupInfo;
		//wchar_t cmdLine[2048];
		//memset(&startupInfo,0,sizeof(startupInfo));
		//startupInfo.cb=sizeof(startupInfo);
		//PROCESS_INFORMATION processInfo;
		//memset(&processInfo,0,sizeof(processInfo));
		//swprintf_s(cmdLine,L"%s %s",strProcess.c_str(), strFile);
		////swprintf_s(cmdLine,L"msiexec.exe /i \"%s\" %s",m_strAppDataPath,_T("/qb"));tangramManager.exe
		//DWORD code;
		//if (!CreateProcess(NULL,cmdLine,NULL,NULL,TRUE,0,NULL,NULL,&startupInfo,&processInfo))
		//{
		//}
		//else
		//{
		//	// wait for the installer to finish
		//	WaitForSingleObject(processInfo.hProcess,INFINITE);
		//	//DeleteFile(strFile);
		//	GetExitCodeProcess(processInfo.hProcess,&code);
		//}


		hr = SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES,NULL,0,szPath);
		strPath = szPath;
		strPath += _T("\\Tangram\\Tangram.Dll");
		HMODULE hModule = LoadLibrary(strPath);

		m_vModules.push_back(hModule);
		if(bFindNode(&m_xmlMarkup,_T("LoadLibrary")))
		{
			while(m_xmlMarkup.FindChildElem())
			{
				m_xmlMarkup.IntoElem();
				MCD_STR strExtendDll = m_xmlMarkup.GetData();
				HMODULE hModule = LoadLibrary(strExtendDll.c_str());
				m_vModules.push_back(hModule);
				m_xmlMarkup.OutOfElem();
			}
		}
		m_xmlMarkup.OutOfElem();
		return true;
	}
	return true;
}
示例#11
0
NewDeviceWidget::NewDeviceWidget(QWidget *parent, QString MACAddress)
	: QWidget(parent)
{

	MAC = MACAddress;
	backgroundPalette.setBrush(QPalette::Background, QColor(234, 237, 242));
	descriptionTextPalette.setColor(QPalette::WindowText, QColor(51, 51, 51));
	errorTextPalette.setColor(QPalette::WindowText,	QColor(255, 150, 0, 255));


	/* Set the layout and initial settings for the New Device widget */

	this->setLayout(new QVBoxLayout());							//Use a Vertical Box Layout
	this->layout()->setSpacing(0);								//Clear the spacing between any child widgets
	this->layout()->setAlignment(Qt::AlignTop);					//Align layout contents at the top of the widget
	this->setAutoFillBackground(true);							//Don't fill in a background color
	this->setPalette(backgroundPalette);
	this->setGeometry(1 /* in */, 100 /* down */, 798 /* width */, 539 /* height */);


	/* Draw the Device Name text label and input field */

	deviceNameLabel = new QLabel();										//Initialize the QLabel pointer
	deviceNameLabel->setText(deviceNameText);							//Set the text
	deviceNameLabel->setFont(QFont("Segoe UI", 12));
	deviceNameLabel->setPalette(descriptionTextPalette);				//Set the text color
	deviceNameLabel->setContentsMargins(0, 100, 0, 6);					//Pad the label down 100 from the logo and up 4 from the next object
	deviceNameLabel->setAlignment(Qt::AlignCenter);						//Center the text within the QLabel
	deviceNameInput = new QLineEdit();									//Initialize the QLineEdit pointer
	deviceNameInput->setText("");										//Set the text
	deviceNameInput->setFont(QFont("Segoe UI", 10));
	deviceNameInput->setFixedWidth(200);								//Set a fixed size for the field
	deviceNameInput->setAlignment(Qt::AlignCenter);						//Center the text within the field
	this->layout()->addWidget(deviceNameLabel);							//Add it to the Start widget layout
	this->layout()->addWidget(deviceNameInput);							//Add it to the Start widget layout
	this->layout()->setAlignment(deviceNameLabel, Qt::AlignHCenter);	//And align it in the center of the widget
	this->layout()->setAlignment(deviceNameInput, Qt::AlignHCenter);	//And align it in the center of the widget


	/* Draw the Internet Connection text label and combo box */

	deviceTypeLabel = new QLabel();										//Initialize the QLabel pointer
	deviceTypeLabel->setText(deviceTypeText);							//Set the text
	deviceTypeLabel->setFont(QFont("Segoe UI", 12));
	deviceTypeLabel->setPalette(descriptionTextPalette);				//Set the text color
	deviceTypeLabel->setContentsMargins(0, 20, 0, 6); 					//Pad the label down 20 from the line edit and up 4 from the next object
	deviceTypeLabel->setAlignment(Qt::AlignCenter);						//Center the text within the QLabel
	deviceTypeComboBox = new NComboBox();								//Initialize the QComboBox pointer
	deviceTypeComboBox->setFixedWidth(200);								//Set a fixed size for the field
	deviceTypeComboBox->setFont(QFont("Segoe UI", 10));
	this->layout()->addWidget(deviceTypeLabel);							//Add it to the Start widget layout
	this->layout()->addWidget(deviceTypeComboBox);						//Add it to the Start widget layout
	this->layout()->setAlignment(deviceTypeLabel, Qt::AlignHCenter);	//And align it in the center of the widget
	this->layout()->setAlignment(deviceTypeComboBox, Qt::AlignHCenter);	//And align it in the center of the widget


	/* Set QComboBox's LineEdit as editable and read only in order to center the text */

	deviceTypeComboBox->setEditable(true);
	deviceTypeComboBox->lineEdit()->setReadOnly(true);
	deviceTypeComboBox->lineEdit()->setContentsMargins(18, 0, 0, 0);
	deviceTypeComboBox->lineEdit()->setAlignment(Qt::AlignCenter);					//Only possible when LineEdit is editable
	deviceTypeComboBox->lineEdit()->setAttribute(Qt::WA_TransparentForMouseEvents);	//Allows QComboBox to still display dropdown on click


	/* Populate the QComboBox with the network adapter friendly names */

	for (int i = 0; i < NUM_DEVICE_TYPES; i++)
	{
		deviceTypeComboBox->addItem(DeviceNames[i]);								//Add the friendly name from the QList
		deviceTypeComboBox->setItemData(i, Qt::AlignCenter, Qt::TextAlignmentRole);	//Center the text
	}


	/* Draw the Start button */

	setButton = new QPushButton();							//Initialize the Start button pointer
	setButton->setStyleSheet(setButtonStyleSheet);			//Set the style sheet to get the background images for button states
	setButton->setFixedSize(90, 30);						//Set a fixed button size (#s from the dimensions of the button images)
	setButton->setText("Save");
	connect(setButton, &QPushButton::clicked, this, &NewDeviceWidget::onSetButtonClicked);
	this->layout()->addItem(new QSpacerItem(0, 30));		//Pad down from the internet connection combo box
	this->layout()->addWidget(setButton);					//Add the start button to the Start widget layout
	this->layout()->setAlignment(setButton, Qt::AlignHCenter);	//And align it in the center of the layout




	/* Open a handle to the Inssidious Registry key and read in known device names and types */
	bool haveName = false;
	bool haveType = false;
	HKEY inssidiousDevicePairsHKCU;
	if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\Inssidious\\DevicePairs", 0, 0, 0, KEY_WRITE | KEY_QUERY_VALUE, 0, &inssidiousDevicePairsHKCU, 0))
	{
		DWORD numValues = 0;
		if (ERROR_SUCCESS == RegQueryInfoKey(inssidiousDevicePairsHKCU, 0, 0, 0, 0, 0, 0, &numValues, 0, 0, 0, 0))
		{
			for (int i = 0; i < numValues; i++)
			{
				wchar_t valueName[MAX_PATH];
				wchar_t valueData[MAX_PATH];
				DWORD valueNameCount = MAX_PATH;
				DWORD valueDataCount = MAX_PATH;

				HRESULT result = RegEnumValue(inssidiousDevicePairsHKCU, i, valueName, &valueNameCount, 0, 0, reinterpret_cast<LPBYTE>(valueData), &valueDataCount);

				if (result == ERROR_SUCCESS || result == ERROR_MORE_DATA)
				{
					if (QString::fromWCharArray(valueName) == (MAC + "-Name"))
					{
						deviceNameInput->setText(QString::fromWCharArray(valueData, valueDataCount/2));
						haveName = true;
					}
					else if (QString::fromWCharArray(valueName) == (MAC + "-Type"))
					{
						deviceTypeComboBox->setCurrentText(QString::fromWCharArray(valueData, valueDataCount/2));
						haveType = true;
					}
				}
			}


			if (haveName && haveType)
			{
				knownDevice = true;
				knownDeviceName = deviceNameInput->text();
				knownDeviceType = deviceTypeComboBox->currentText();
			}
		}
	}

	/* No further work is performed until we receive a clicked signal */

}
示例#12
0
static void
set_registry_from_env(const TCHAR *image_name, const TCHAR *dll_path) 
{
#undef TEMP_CMD
#define TEMP_CMD(name, NAME)                     \
 BOOL do_##name;                                 \
 TCHAR name##_value[MAX_REGISTRY_PARAMETER]

    DO_ENV_VARS();

    DWORD disp, size, type;
    int res, len;
    int rununder_int_value;

    /* get environment variable values if they are set */
#undef TEMP_CMD    
#define TEMP_CMD(name, NAME)                                                  \
 name##_value[0] = '\0';  /* to be pedantic */                                \
 len = GetEnvironmentVariable(_TEXT(DYNAMORIO_VAR_##NAME), name##_value,      \
                              BUFFER_SIZE_ELEMENTS(name##_value));            \
 do_##name = (use_environment &&                                              \
              (len > 0 ||                                                     \
              (len == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND)));       \
 ASSERT(len < BUFFER_SIZE_ELEMENTS(name##_value));                            \
 VERBOSE_PRINT(("Environment var %s for %s, value = %s\n",                    \
        do_##name ? "set" : "not set", #name, name##_value));

    DO_ENV_VARS();

    if (ops_param != NULL) {
        /* -ops overrides env var */
        strncpy(options_value, ops_param, BUFFER_SIZE_ELEMENTS(options_value));
        NULL_TERMINATE_BUFFER(options_value);
        do_options = TRUE;
    }

    /* we always want to set the rununder to make sure RUNUNDER_ON is on
     * to support following children; we set RUNUNDER_EXPLICIT to allow
     * injecting even when preinject is configured. */
    /* FIXME: we read only decimal */
    rununder_int_value = _ttoi(rununder_value);
    rununder_int_value |= RUNUNDER_ON | RUNUNDER_EXPLICIT;

    do_rununder = true;
    _itot(rununder_int_value, rununder_value, 
          10 /* FIXME : is the radix abstracted somewhere */);

    /* for follow_children, we set DYNAMORIO_AUTOINJECT (unless
     * overridden by env var: then child will use env value, while
     * parent uses cmdline path) */
    if (!do_autoinject && dll_path != NULL) {
        _tcsncpy(autoinject_value, dll_path, BUFFER_SIZE_ELEMENTS(autoinject_value));
        do_autoinject = true;
    }

    /* FIXME : doesn't support svchost-* yet */
    ASSERT(_tcsicmp(_TEXT(SVCHOST_EXE_NAME), image_name));
    res = RegCreateKeyEx(DYNAMORIO_REGISTRY_HIVE, 
                         _TEXT(DYNAMORIO_REGISTRY_KEY), 0,  NULL, 
                         REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, NULL,
                         &product_name_key, &disp);
    ASSERT(res == ERROR_SUCCESS);
    if (disp == REG_CREATED_NEW_KEY) {
        created_product_reg_key = TRUE;
    }
    res = RegCreateKeyEx(product_name_key, image_name, 0, NULL, 
                         REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE|KEY_SET_VALUE, 
                         NULL, &image_name_key, &disp);
    ASSERT(res == ERROR_SUCCESS);
    if (disp == REG_CREATED_NEW_KEY) {
        created_image_reg_key = TRUE;
    }
    
    DO_VERBOSE({
        printf("created product key? %s\ncreated image key? %s\n",
               created_product_reg_key ? "yes" : "no", 
               created_image_reg_key ? "yes" : "no");
        fflush(stdout);
    });
示例#13
0
HRESULT	PowerDocsExtHelper::SetupEventHandler()
{
	DWORD	dwDisposition;
	HKEY	hKey;
	LPTSTR	lpClass = NULL;
	TCHAR	szSubKey[ MAX_PATH ];
	TCHAR	szPath[MAX_PATH];
	DWORD	dwSize = MAX_PATH;
	bool	bPowerDocsInstalled = FALSE;
	HRESULT	hr					= S_OK;

 	CStdString sKeyName = _T("SOFTWARE\\Hummingbird\\PowerDOCS\\OM\\EventHandlers\\DeltaView");
 	CStdString sKeyName31 = _T("SOFTWARE\\PC DOCS Inc.\\PowerDOCS\\OM\\EventHandlers\\DeltaView");

	// Is PowerDocs greater than 5.0 installed?
	if (IsPowerDocsGreaterThan50Installed())
	{
    	if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Hummingbird\\PowerDOCS"), 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS )
		{
 			if( RegQueryValueEx( hKey, _T("InstallPath"), 0, 0, (unsigned char*)szPath, &dwSize ) == ERROR_SUCCESS )
			{
				_tcsncpy( szSubKey, sKeyName.c_str(), 100 );
				bPowerDocsInstalled = TRUE;
			}
			RegCloseKey(hKey);
		}
	}
	// Is PowerDocs 4.0 installed?
 	else if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Hummingbird\\PowerDOCS 4.0"), 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS )
	{
 		if( RegQueryValueEx( hKey, _T("Path"), 0, 0, (unsigned char*)szPath, &dwSize ) == ERROR_SUCCESS )
		{
			_tcsncpy( szSubKey, sKeyName.c_str(), 100 );
			bPowerDocsInstalled = TRUE;
		}
		RegCloseKey(hKey);
	}
	// Is PowerDocs 3.9 installed?
 	else if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Hummingbird\\PowerDOCS 3.9"), 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS )
	{
 		if( RegQueryValueEx( hKey, _T("Path"), 0, 0, (unsigned char*)szPath, &dwSize ) == ERROR_SUCCESS )
		{
			_tcsncpy( szSubKey, sKeyName.c_str(), 100 );
			bPowerDocsInstalled = TRUE;
		}
		RegCloseKey(hKey);
	}
	// If PowerDocs 3.9 is not installed, is PowerDocs 3.1 installed?
	else if( (bPowerDocsInstalled == FALSE) &&
 		(RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\PC DOCS Inc.\\PowerDOCS\\Installation"), 0, KEY_QUERY_VALUE, &hKey ) == ERROR_SUCCESS ))
	{
 		if( RegQueryValueEx( hKey, _T("Path"), 0, 0, (unsigned char*)szPath, &dwSize ) == ERROR_SUCCESS )
		{
			_tcsncpy( szSubKey, sKeyName31.c_str(), 100 );
			bPowerDocsInstalled = TRUE;
		}
		RegCloseKey(hKey);
	}

	// If PowerDocs is installed, install the event handler
	if (bPowerDocsInstalled)
	{
		long lRet = ERROR_SUCCESS;

		lRet = RegCreateKeyEx(	HKEY_LOCAL_MACHINE, 
								(LPCTSTR)szSubKey , 
								(DWORD)0, 
								lpClass, 
								REG_OPTION_NON_VOLATILE, 
								KEY_ALL_ACCESS, 
								NULL, 
								&hKey,  
								&dwDisposition );

		if (lRet == ERROR_SUCCESS)
		{
			TCHAR szValueData[] = _T(_VERPROGID_PowerDocsExt);
			DWORD dwByteCout = (x64_int_cast)_tcslen(szValueData) * sizeof(TCHAR);
			RegSetValueEx(hKey, _T(""), (DWORD)0, REG_SZ, (CONST BYTE *)szValueData, dwByteCout);
			RegCloseKey( hKey );
		}
		else
		{
			hr = HRESULT_FROM_WIN32(lRet);
		}
	}
	else
	{
		hr = E_PD_NOT_INSTALLED;
	}
	return hr;
}
示例#14
0
文件: main.cpp 项目: iAnomaly/cpbo
int main(int argc, char* argv[]) {
  printf("%s <http://www.kegetys.net>\n", VERSIONSTRING);

  #ifndef _NIX
  // Compare console title & try to find out if we were run from terminal or directly
  char ctit[256];
  char cmod[256];
  GetModuleFileName(NULL, cmod, 256);
  GetConsoleTitle(ctit, 256);
  SetConsoleTitle(VERSIONSTRING);
  bool runDirectly = !strcasecmp(ctit, cmod);

  char rnd[256];
  sprintf(rnd, "_cpbo_tmp__%d__", GetTickCount());
  SetConsoleTitle(rnd);
  win = FindWindow(NULL, rnd);
  SetConsoleTitle(VERSIONSTRING);
  #endif

  if(argc < 2) {
    #ifndef _NIX
    // If title & module name match we were propably run directly
    if(runDirectly) {
      // Double clicked exe, display query for file association
      int ret = MessageBox(NULL, "No parameters\n\nDo you wish to associate cpbo with PBO files\nand directories (Explorer right click menu)?", VERSIONSTRING, MB_ICONQUESTION|MB_YESNO);
      if(ret == IDYES)
        goto assign;
      else
        exit(0);
    } else
    #else
      usage(); // Ran from console
    #endif
  }

  // Parse parameters
  bool gui = false;
  bool overwrite = false;
  for(int ai=1;ai<argc;ai++) {
    if(!strcasecmp("-y", argv[ai])) {
      // Overwrite all files
      overwrite = true;
    }

    if(!strcasecmp("-gui", argv[ai]))
      gui = true;

    if(!strcasecmp("-e", argv[ai])) {
      if(argc-ai < 2)
        usage();

      // Extract...
      char *odir = "";
      if(argc >= ai+3) {
        char *last = argv[ai+2] + strlen(argv[ai+2]) - 1;
        if (*last == '/' || *last == '\\') // If directory path has trailing slash then remove it (replace with null terminator)
          *last = '\0';
        odir = argv[ai+2];
      }

      printf("Extracting %s\n", argv[ai+1]);
      if(pboEx(argv[ai+1], odir, overwrite, gui)) {
        printf("Done.\n");
        return 1;
      } else {
        printf("Failed!\n");
        #ifndef _NIX
        //MessageBox(NULL, "PBO extract failed", "cpbo", MB_ICONSTOP);
        MessageBox(NULL, "Extract of one or more files failed", "cpbo", MB_ICONSTOP);
        #endif
        return -1;
      }
    }

    if(!strcasecmp("-p", argv[ai])) {
      if(argc-ai < 2)
        usage();

      char *last = argv[ai+1] + strlen(argv[ai+1]) - 1;
      if (*last == '/' || *last == '\\') // If directory path has trailing slash then remove it (replace with null terminator)
        *last = '\0';

      // Create PBO.
      char *ofile = "";
      if(argc >= ai+3)
        ofile = argv[ai+2];

      printf("Creating %s\n", argv[ai+1]);
      if(pboPack(argv[ai+1], ofile, overwrite)) {
        printf("Done.\n");
        return 1;
      } else {
        printf("Failed!\n");
        #ifndef _NIX
        MessageBox(NULL, "PBO creation failed", "cpbo", MB_ICONSTOP);
        #endif
        return -1;
      }
    }

    #ifndef _NIX
    if(!strcasecmp("-a", argv[ai])) {
  assign:
      // Create file associations
      char foo[1024];
      GetModuleFileName(NULL, foo, 1024);
      printf("%s\n", foo);

      // for PBO...
      HKEY hKey;
      DWORD dwDisp = 0;
      LPDWORD lpdwDisp = &dwDisp;
      DWORD dwVal = 100;
      LONG ret = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".pbo\\shell\\Extract\\command", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
      if(ret == ERROR_SUCCESS) {
        char foo2[1024];
        sprintf(foo2, "\"%s\" -e \"%%1\"", foo);

        RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *) foo2, strlen(foo2));
        RegCloseKey(hKey);
      } else
        printf("PBO association failed! Verify registry permissions\n");

      ret = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".pbo\\shell\\extract PBO...\\command", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
      if(ret == ERROR_SUCCESS) {
        char foo2[1024];
        sprintf(foo2, "\"%s\" -gui -e \"%%1\"", foo);

        RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *) foo2, strlen(foo2));
        RegCloseKey(hKey);
      } else
        printf("PBO association failed! Verify registry permissions\n");

      // For directories
      ret = RegCreateKeyEx(HKEY_CLASSES_ROOT, "Folder\\shell\\create PBO\\command", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,lpdwDisp);
      if(ret == ERROR_SUCCESS) {
        char foo2[1024];
        sprintf(foo2, "\"%s\" -p \"%%1\"", foo);

        RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *) foo2, strlen(foo2));
        RegCloseKey(hKey);
      } else
        printf("Directory association failed! Verify registry permissions\n");

      // PBO Icon
      ret = RegCreateKeyEx(HKEY_CLASSES_ROOT, ".pbo\\DefaultIcon", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, lpdwDisp);
      if(ret == ERROR_SUCCESS) {
        if(dwDisp == REG_CREATED_NEW_KEY)  {
          // Set new icon
          char foo2[1024];
          sprintf(foo2, "%s,0", foo);

          RegSetValueEx(hKey, NULL, 0L, REG_SZ, (const BYTE *) foo2, strlen(foo2));
        } else 
          printf("Default PBO icon already exists, not overwritten\n");
        RegCloseKey(hKey);
      }

      printf("Done.\n");

      if(runDirectly)
        MessageBox(NULL, "Done", "cpbo", MB_ICONINFORMATION);
      return 1;
    }
    #endif
  }
}
示例#15
0
STDAPI DllRegisterServer (VOID)
{
    TCHAR       szModuleName[MAX_PATH]; 
    HRESULT     hResult = S_OK;
    TCHAR       szBuffer[MAX_PATH+10] = TEXT("");
    TCHAR       szClsid[MAX_PATH] = TEXT("");
    TCHAR       szSubKey[MAX_PATH] = TEXT("");
    TCHAR       szColumnProvider[MAX_PATH] = TEXT("");
    TCHAR       szDescription[MAX_PATH] = TEXT("");

    SECURITY_ATTRIBUTES SA;
    SA.nLength = sizeof(SECURITY_ATTRIBUTES);
    SA.bInheritHandle = TRUE;
    WCHAR *pwszSD=L"D:(A;OICI;GA;;;SY)(A;OICI;GA;;;BA)(A;OICI;GA;;;CO)(A;OICI;GRGWGX;;;IU)";
    //
    //  Load some necessary string values
    //
    //
    //  Initialize the security attributes structure
    //
    if (ConvertStringSecurityDescriptorToSecurityDescriptor(pwszSD,
							    SDDL_REVISION_1, 
							    &(SA.lpSecurityDescriptor), 
							    NULL)) 
      {
	LoadString (hDllInstance, IDS_CLSID, szClsid, MAX_PATH);
	LoadString (hDllInstance, IDS_DESCRIPTION, szDescription, MAX_PATH);
	LoadString (hDllInstance, IDS_REGKEY_COLUMNPROVIDER, szColumnProvider, MAX_PATH);
	
	
	//
	//  Get the name of this module
	//
	GetModuleFileName (hDllInstance, szModuleName, MAX_PATH);
	
	//
	//  Register the component under HKCR\CLSID
	//
	HKEY    hKey            = NULL;
	DWORD   dwDisposition   = 0;
	LRESULT lResult         = 0;
	
	wsprintf (szSubKey, TEXT("CLSID\\%s"), szClsid);
	lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey,
				  0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
				  &SA, &hKey, &dwDisposition);
	
	if (lResult == NOERROR)
	  {
	    lResult = RegSetValueEx (hKey, TEXT(""), 0, REG_SZ, 
				     (LPBYTE) szDescription, GetStringByteSize(szDescription));
	    if (lResult != NOERROR)
	      hResult = SELFREG_E_CLASS;
	    RegCloseKey (hKey);
	    hKey = NULL;
	  }
	else
	  {
	    hResult = SELFREG_E_CLASS;
	  }
	
	//
	//  Register component information under HKCR\CLSID\{CLSID}
	//
	StrCatBuff (szSubKey, TEXT("\\InprocServer32"), ARRAYSIZE(szSubKey));
	lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey,
				  0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
				  &SA, &hKey, &dwDisposition);
	
	if (lResult == NOERROR)
	  {
	    lstrcpyn (szBuffer, TEXT("Apartment"), ARRAYSIZE(szBuffer));
	    lResult = RegSetValueEx (hKey, TEXT("ThreadingModel"), 0, 
				     REG_SZ, (LPBYTE) szBuffer, GetStringByteSize (szBuffer));
	    if (lResult != NOERROR)
	      hResult = SELFREG_E_CLASS;
	    
	    lResult = RegSetValueEx (hKey, TEXT(""), 0, 
				     REG_SZ, (LPBYTE) szModuleName, GetStringByteSize(szModuleName));
	    if (lResult != NOERROR)
	      hResult = SELFREG_E_CLASS;
	    
	    RegCloseKey (hKey);
	    hKey = NULL;
	  }
	else
	  {
	    hResult = SELFREG_E_CLASS;
	  }
	
	//
	//  Register the component as a column provider extension under
	//  HKCR\Folder\shellex\ColumnHandlers
	//
	wsprintf (szSubKey, TEXT("%s\\%s"), szColumnProvider, szClsid);
	lResult = RegCreateKeyEx (HKEY_CLASSES_ROOT, szSubKey,
				  0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
				  &SA, &hKey, &dwDisposition);
	
	if (lResult != NOERROR)
	  {
	    hResult = SELFREG_E_CLASS;
	  }
	
	LocalFree(SA.lpSecurityDescriptor);
      } else {
	hResult = E_FAIL;
      }
    
    return hResult;
}
示例#16
0
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

	HANDLE handle = ::CreateMutex(NULL, FALSE, L"daemon");//handle为声明的HANDLE类型的全局变量   
	if (GetLastError() == ERROR_ALREADY_EXISTS)
	{
		return FALSE;
	}

	CoInitialize(NULL);

	wchar_t path[MAX_PATH];
	GetModuleFileName(NULL, path, sizeof(path));

	wchar_t cuPath[MAX_PATH];                                               //存放路径的变量

	GetCurrentDirectory(MAX_PATH, cuPath);                   //获取程序的当前目录

	LPITEMIDLIST pidl;
	TCHAR szPath[MAX_PATH];
	if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_ALTSTARTUP, &pidl)))
	{
		if (SHGetPathFromIDList(pidl, szPath))
		{
			//SHFILEINFO    sfi;
			//ZeroMemory(&sfi, sizeof(sfi));
			//UINT uFlags = SHGFI_PIDL | SHGFI_DISPLAYNAME;
			//SHGetFileInfo((LPCTSTR)pidl, 0, &sfi, sizeof(SHFILEINFO), uFlags);
			//sDisplayName = sfi.szDisplayName;
			CreateFileShortcut(NULL, szPath, L"daemon.lnk", cuPath, MAKEWORD(VK_F12, HOTKEYF_CONTROL), L"Start Link");
			CoTaskMemFree(pidl);          //free the resource  
		}
	}

	//判断环境是否为WOW64  
	BOOL isWOW64;
	REGSAM p;
	IsWow64Process(GetCurrentProcess(), &isWOW64);
	if (isWOW64) {
	 p = KEY_WRITE | KEY_WOW64_64KEY;
	}
	else {
	 p = KEY_WRITE;
	}
	
	//HKEY hlmKey;
	//if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, NULL, 0, p, NULL, &hlmKey, NULL) != ERROR_SUCCESS) {
	//	//失败  
	//	//return 0;
	//}
	//if (RegSetValueEx(hlmKey, TEXT("Daemon"), 0, REG_SZ, (BYTE*)path, sizeof(path) * sizeof(TCHAR)) != ERROR_SUCCESS) {
	//	//失败  
	//	//return 0;
	//}
	//RegCloseKey(hlmKey);
	HKEY hcuKey;
	if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, NULL, 0, p, NULL, &hcuKey, NULL) != ERROR_SUCCESS) {
		//失败  
		//return 0;
	}
	if (RegSetValueEx(hcuKey, TEXT("Daemon"), 0, REG_SZ, (BYTE*)path, sizeof(path) * sizeof(TCHAR)) != ERROR_SUCCESS) {
		//失败  
		//return 0;
	}
	RegCloseKey(hcuKey);

	HKEY hErrorReportKey;
	if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\Windows Error Reporting"), 0, NULL, 0, p, NULL, &hErrorReportKey, NULL) != ERROR_SUCCESS) {
		//失败  
		//return 0;
	}
	DWORD Data = 1;
	if (RegSetValueEx(hErrorReportKey, TEXT("DontShowUI"), 0, REG_DWORD, (LPBYTE)&Data, sizeof(Data)) != ERROR_SUCCESS) {
		//失败  
		//return 0;
	}
	if (RegSetValueEx(hErrorReportKey, TEXT("Disabled"), 0, REG_DWORD, (LPBYTE)&Data, sizeof(Data)) != ERROR_SUCCESS) {
		//失败  
		//return 0;
	}
	RegCloseKey(hErrorReportKey);

	while (1)
	{
		Config		config;
		config.ReadFile("config.conf");
		string pProgramPath = "";
		pProgramPath = config.Read("pProgramPath", pProgramPath);

		STARTUPINFO si = { 0 };
		ZeroMemory(&si, sizeof(si));
		si.cb = sizeof(STARTUPINFO);
		GetStartupInfo(&si);
		si.wShowWindow = SW_SHOW;
		si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

		// 运行进程
		PROCESS_INFORMATION pi;
		ZeroMemory(&pi, sizeof(pi));

		BOOL bRet = FALSE;
		bRet = CreateProcess(StringToWString(pProgramPath).c_str(), NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);

		if (bRet)
		{
			WaitForSingleObject(pi.hProcess, INFINITE);
		}
		else
		{
			return 0;
		}

	}
	return 0;
}
示例#17
0
BOOL LoadSettingsFromFile(LPCSTR szKey,LPCSTR szFile,BYTE bFileIsReg)
{
	HKEY hKey;
	LONG lRet=RegOpenKeyEx(HKEY_CURRENT_USER,szKey,
		0,KEY_READ,&hKey);
	
	// Check wheter key exists
	if (lRet!=ERROR_FILE_NOT_FOUND)
	{
		// Key exists, using it
		RegCloseKey(hKey);
		return TRUE;
	}

	if (bFileIsReg)
	{
				
		// Restore key
		char szCommand[2000];
		sprintf_s(szCommand,2000,"regedit /s \"%s\"",szFile);

		PROCESS_INFORMATION pi;
		STARTUPINFO si; // Ansi and Unicode versions are same
		ZeroMemory(&si,sizeof(STARTUPINFO));
		si.cb=sizeof(STARTUPINFO);
		
		if (CreateProcess(NULL,szCommand,NULL,
			NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS,
			NULL,NULL,&si,&pi))
		{
			WaitForSingleObject(pi.hProcess,2000);
			CloseHandle(pi.hThread);
			CloseHandle(pi.hProcess);	
		}
		else
			return FALSE;

		return TRUE;
	}

	// Acquiring required privileges	
	HANDLE hToken;
	if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken))
	{
		PTOKEN_PRIVILEGES ns=(PTOKEN_PRIVILEGES)new BYTE[sizeof(DWORD)+sizeof(LUID_AND_ATTRIBUTES)+2];
		if (LookupPrivilegeValue(NULL,SE_BACKUP_NAME,&(ns->Privileges[0].Luid)))
		{
			ns->PrivilegeCount=1;
			ns->Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
			if (!AdjustTokenPrivileges(hToken,FALSE,ns,0,NULL,NULL))
			{
				//ShowError(NULL,IDS_ERRORCANNOTENABLEPRIVILEGE,GetLastError());
			}
		}
		if (LookupPrivilegeValue(NULL,SE_RESTORE_NAME,&(ns->Privileges[0].Luid)))
		{
			ns->PrivilegeCount=1;
			ns->Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
			if (!AdjustTokenPrivileges(hToken,FALSE,ns,0,NULL,NULL))
			{
				//ShowError(NULL,IDS_ERRORCANNOTENABLEPRIVILEGE,GetLastError());
			}

		}
		delete[] (BYTE*)ns;
		CloseHandle(hToken);
	}

	// First, check that we can restore key
	
	lRet=RegCreateKeyEx(HKEY_CURRENT_USER,szKey,
		0,NULL,REG_OPTION_BACKUP_RESTORE,KEY_ALL_ACCESS,NULL,&hKey,NULL);
	if (lRet!=ERROR_SUCCESS)
	{
		//ShowError(hWnd,IDS_ERRORCANNOTCREATEKEY,lRet);
		return FALSE;
	}
	lRet=RegRestoreKey(hKey,szFile,0);
	RegCloseKey(hKey);		
	
	return lRet==ERROR_SUCCESS;
}
//*****************************************************************************
//*****************************************************************************
DWORD _CopyRegistryKey(HKEY hkSource, HKEY hkDest)
{
	// Info über den Key besorgen
	DWORD nSubKeys = 0;
	DWORD MaxSubkeyLen = 0;
	DWORD MaxClassLen = 0;
	DWORD nValues = 0;
	DWORD MaxValuenameLen = 0;
	DWORD MaxValueLen = 0;

	LONG lErg = RegQueryInfoKey(hkSource,
								NULL,			// Class Buffer
								NULL,			// ->Classbuffer Size
								NULL,			// Reserved
								&nSubKeys,		// Anzahl Unterschlüssel
								&MaxSubkeyLen,
								&MaxClassLen,
								&nValues,
								&MaxValuenameLen,
								&MaxValueLen,
								NULL,			// ->Länge des Security Descriptors
								NULL);			// ->FILETIME des letzten Schreibzugriffs

	if(lErg!=ERROR_SUCCESS)
		return 1;

	MaxSubkeyLen++;
	MaxClassLen++;
	MaxValuenameLen++;
	MaxValueLen++;

	// Zuerst durchenumerieren der Subkeys
	STRING_AP	SubkeyName(MaxSubkeyLen);

	for(DWORD i=0;i<nSubKeys;i++)
	{
		DWORD dwKeynameLen = MaxSubkeyLen;
		FILETIME ft;
		// Namen des Keys ermitteln
		lErg = RegEnumKeyEx(hkSource,i,SubkeyName.s,&dwKeynameLen,NULL,NULL,NULL,&ft);
		if(lErg!=ERROR_SUCCESS)
			continue;
		// Source-Subkey öffnen
		HKEY hkNewSource = NULL;
		lErg = RegOpenKeyEx(hkSource,SubkeyName.s,0,KEY_READ,&hkNewSource);
		if(lErg!=ERROR_SUCCESS)
			continue;

		// Destination-Subkey erzeugen
		HKEY hkNewDest = NULL;
		lErg = RegCreateKeyEx(hkDest,SubkeyName.s,NULL,NULL,0,KEY_WRITE,NULL,&hkNewDest,NULL);
		if(lErg!=ERROR_SUCCESS)
		{
			RegCloseKey(hkNewSource);
			hkNewSource = NULL;
			continue;
		};
		
		// Rekursiv weiterbearbeiten
		_CopyRegistryKey(hkNewSource,hkNewDest);

		// Keys zumachen
		RegCloseKey(hkNewSource);
		RegCloseKey(hkNewDest);

	};
	

	// Jetzt durchnumerieren und Schreiben der Values
	STRING_AP ValueName(MaxValuenameLen);
	STRING_AP Value(MaxValueLen);
	for(DWORD i=0;i<nValues;i++)
	{
		DWORD dwVnl = MaxValuenameLen;
		DWORD dwType = 0;
		DWORD dwDs = MaxValueLen;
		
		lErg = RegEnumValue(hkSource,i,ValueName.s,&dwVnl,NULL,&dwType,(BYTE*)Value.s,&dwDs);
		if(lErg!=ERROR_SUCCESS)
			continue;

		lErg = RegSetValueEx(hkDest,(const char*)ValueName.s,0,dwType,(const unsigned char*)Value.s,dwDs);

	};



	return 0;
};
示例#19
0
/**
 *	DllRegisterServer
 **/
STDAPI DllRegisterServer()
{
	DWORD lastError = 0;
    LRESULT lr;
    HRESULT hr = E_FAIL;
    HKEY hKey = NULL;
    HKEY hSubKey = NULL;
    DWORD dwDisposition;
    TCHAR wszValue[127];
	TCHAR wszPath[127];

    // Set up registry keys
    // Register with COM:
    //    [HKEY_CLASSES_ROOT\CLSID\{3AB4C10E-673C-494c-98A2-CC2E91A48115}\InProcServer32]
    //    @="mapirule.dll"
	
	DBG_TRACE(L"Creating/opening key:", DBG_NOTIFY, FALSE);
	DBG_TRACE(_TEXT_CLSIDKEY, DBG_NOTIFY, FALSE);
    lr = RegCreateKeyEx(HKEY_CLASSES_ROOT, _TEXT_CLSIDKEY, 0, NULL, 0, 0, NULL,  &hKey, &dwDisposition);
	if (lr != ERROR_SUCCESS)
    {
		DBG_TRACE(L"ERROR creating/opening key.", DBG_NOTIFY, FALSE);
        goto Exit;
    }
	
	DBG_TRACE(L"Creating/opening key:", DBG_NOTIFY, FALSE);
	DBG_TRACE(TEXT("InprocServer32"), DBG_NOTIFY, FALSE);
    lr = RegCreateKeyEx(hKey, TEXT("InprocServer32"), 0, NULL, 0, 0, NULL,  &hSubKey, &dwDisposition);
	if (lr != ERROR_SUCCESS)
    {
		DBG_TRACE(L"ERROR creating/opening key.", DBG_NOTIFY, FALSE);
        goto Exit;
    }

	wcscpy(wszPath, DLL_FOLDER);
	wsprintf(wszValue, TEXT("%s\\%s"), wszPath, DLL_NAME);
	
	DBG_TRACE(L"Setting value of InprocServer32 to:", DBG_NOTIFY, FALSE);
	DBG_TRACE(wszValue, DBG_NOTIFY, FALSE);
    lr = RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (LPBYTE) wszValue, (lstrlen(wszValue) + 1) * sizeof(TCHAR));
	if (lr != ERROR_SUCCESS) 
	{
		DBG_TRACE(L"ERROR setting value of InprocServer32.", DBG_NOTIFY, FALSE);
		goto Exit;
	}

	RegCloseKey(hSubKey);
	hSubKey = NULL;
	RegCloseKey(hKey);
	hKey = NULL;

    // Register with Inbox:
    //    [HKEY_LOCAL_MACHINE\Software\Microsoft\Inbox\Svc\SMS\Rules]
    //    {3AB4C10E-673C-494c-98A2-CC2E91A48115}"=dword:1

	DBG_TRACE(L"Creating/opening key:", DBG_NOTIFY, FALSE);
	DBG_TRACE(TEXT("\\Software\\Microsoft\\Inbox\\Svc\\SMS\\Rules"), DBG_NOTIFY, FALSE);
    lr = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("\\Software\\Microsoft\\Inbox\\Svc\\SMS\\Rules"),
	                              0, NULL, 0, 0, NULL, 
	                              &hKey, &dwDisposition);
    if (lr != ERROR_SUCCESS)
    {
		DBG_TRACE(L"ERROR creating/opening key.", DBG_NOTIFY, FALSE);
		goto Exit;
    }
	
	dwDisposition = 1;
	DBG_TRACE(L"Setting value of rule {DD69A982-6C70-4a55-8BE4-6B32A1F9A527} to 1.", DBG_NOTIFY, FALSE);
	lr = RegSetValueEx(hKey, _TEXT_CLSID, 0, REG_DWORD, (LPBYTE) &dwDisposition, sizeof(DWORD));
    if (lr != ERROR_SUCCESS)
    {
		DBG_TRACE(L"ERROR setting value of {DD69A982-6C70-4a55-8BE4-6B32A1F9A527}.", DBG_NOTIFY, FALSE);
        goto Exit;
    }
 
    hr = S_OK;

Exit:
    if (hSubKey)
    {
        RegCloseKey(hSubKey);
    }

    if (hKey)
    {
        RegCloseKey(hKey);
    }

    return hr;
}
int
setenv(const char *name,
       const char *value,
       int         overwrite)
{
#ifndef __MINGW32CE__

   char  *old_name;
   char  *str;
   size_t length;
   int    res;

   if (!name || !*name)
     return -1;

   /* if '=' is found, return EINVAL */
   if (strchr (name, '='))
     {
        errno = EINVAL;
        return -1;
     }

   /* if name is already set and overwrite is 0, we exit with success */
   old_name = getenv(name);
   if (!overwrite && old_name)
     return 0;

   length = value ? strlen(value) : 0;
   length += strlen(name) + 2;
   str = (char *)malloc(length);
   if (!str)
     {
        errno = ENOMEM;
        return -1;
     }
   if (!value)
     sprintf(str, "%s=", name);
   else
     sprintf(str, "%s=%s", name, value);
   res = _putenv(str);
   free(str);

   return res;

#else /* __MINGW32CE__ */

   HKEY     key;
   LONG     res;
   DWORD    disposition;
   wchar_t *wname;
   char    *data;
   DWORD    size;

   if (!name || !*name)
     return -1;

   /* if '=' is found, return an error */
   if (strchr (name, '='))
     return -1;

   if ((res = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                             TEXT("Software\\Efl\\Environment"),
                             0, NULL,
                             REG_OPTION_VOLATILE,
                             0, NULL,
                             &key,
                             &disposition)) != ERROR_SUCCESS)
     {
        _evil_error_display(__FUNCTION__, res);
        return -1;
     }

   /* if name is already set and overwrite is 0, we exit with success */
   if (!overwrite && (disposition == REG_OPENED_EXISTING_KEY))
     return 0;

   wname = evil_char_to_wchar(name);
   if (!wname)
     {
        if ((res = RegCloseKey (key)) != ERROR_SUCCESS)
          _evil_error_display(__FUNCTION__, res);
        return -1;
     }

   if (value)
     {
        size = strlen(value);
        data = malloc(sizeof(char) * (size + 1));
        if (!data)
          return -1;
        memcpy((void *)data, value, size);
        data[size] = '\0';
     }
   else
     {
        size = 0;
        data = malloc(sizeof(char));
        if (!data)
          return -1;
        data[0] = '\0';
     }
   if (!data)
     return -1;

   if ((res = RegSetValueEx(key,
                            (LPCWSTR)wname,
                            0, REG_SZ,
                            (const BYTE *)data,
                            size + 1)) != ERROR_SUCCESS)
     {
        free(wname);
        _evil_error_display(__FUNCTION__, res);
        if ((res = RegCloseKey (key)) != ERROR_SUCCESS)
          _evil_error_display(__FUNCTION__, res);
        return -1;
     }

   free(data);
   free(wname);

   if ((res = RegCloseKey (key)) != ERROR_SUCCESS)
     {
        _evil_error_display(__FUNCTION__, res);
        return -1;
     }

   return 0;

#endif /* ! __MINGW32CE__ */
}
示例#21
0
文件: dllmain.cpp 项目: Jichao/comtut
STDAPI DllRegisterServer(void) {
	//register server
	WCHAR path[MAX_PATH];
	GetModuleFileName(g_hMod, path, MAX_PATH);
	auto ret = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\InprocServer32",
		NULL, path);
	if (!ret)
		return E_FAIL;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\InprocServer32",
		L"ThreadingModel", L"Apartment");
	if (!ret)
		return E_FAIL;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\ProgID",
		NULL, L"CircleControl.CircleControl.1");
	if (!ret)
		return E_FAIL;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\VersionIndependentProgID",
		NULL, L"CircleControl.CircleControl");
	if (!ret)
		return E_FAIL;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\TypeLib",
		NULL, L"{E9D304EC-552C-4D89-9804-7AB9E45FEF32}");
	if (!ret)
		return E_FAIL;

	HKEY hKey = NULL;
	auto hr = RegCreateKeyEx(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\Programmable",
		NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, &hKey, NULL);
	if (hr != ERROR_SUCCESS)
		return hr;

	hr = RegCreateKeyEx(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\Control",
		NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, &hKey, NULL);
	if (hr != ERROR_SUCCESS)
		return hr;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\Version",
		NULL, L"1.0");
	if (!ret)
		return E_FAIL;

	WCHAR pathRsrc[MAX_PATH + 100];
	StringCchPrintf(pathRsrc, MAX_PATH + 100, L"%s, 101", path);
	hr = RegSetString(HKEY_CLASSES_ROOT, L"CLSID\\{1C797BFB-3F97-4CF8-B857-45C90028759B}\\ToolboxBitmap32",
		NULL, pathRsrc);
	if (hr != ERROR_SUCCESS)
		return hr;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CircleControl.CircleControl.1\\CLSID",
		NULL, L"{1C797BFB-3F97-4CF8-B857-45C90028759B}");
	if (!ret)
		return E_FAIL;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CircleControl.CircleControl\\CLSID",
		NULL, L"{1C797BFB-3F97-4CF8-B857-45C90028759B}");
	if (!ret)
		return E_FAIL;

	ret = RegSetString(HKEY_CLASSES_ROOT, L"CircleControl.CircleControl\\CurVer",
		NULL, L"CircleControl.CircleControl.1");
	if (!ret)
		return E_FAIL;

	//register the typelib
	HRSRC hrsrc = FindResource(g_hMod, MAKEINTRESOURCE(1), L"TYPELIB");
	if (!hrsrc)
		return E_FAIL;
	HGLOBAL hGlobal = LoadResource(g_hMod, hrsrc);
	if (!hGlobal)
		return E_FAIL;
	auto size = SizeofResource(g_hMod, hrsrc);
	WCHAR tempDir[MAX_PATH];
	GetTempPath(MAX_PATH, tempDir);
	WCHAR tempFile[MAX_PATH];
	GetTempFileName(tempDir, L"keke", 0, tempFile);
	HANDLE hFile = CreateFile(tempFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL);
	if (hFile == INVALID_HANDLE_VALUE)
		return E_FAIL;
	DWORD byteCount;
	if (!WriteFile(hFile, hGlobal, size, &byteCount, NULL) || byteCount != size)
		return E_FAIL;
	if (!CloseHandle(hFile))
		return E_FAIL;
	ITypeLib* typeLib = nullptr;
	hr = LoadTypeLib(tempFile, &typeLib);
	if (hr != S_OK) {
		return hr;
	}
	hr = RegisterTypeLib(typeLib, path, NULL);
	return hr;
}
示例#22
0
DLLEXPORT int WINAPI Install_Exit(HWND Parent, LPCTSTR InstallDir, WORD FailedDirs,WORD FailedFiles,WORD FailedRegKeys,WORD FailedRegVals,WORD FailedShortcuts)
{
	HMODULE GAPI;
	HMODULE CoreDLL;
	tchar_t LocalPath[MAXPATH];
	tchar_t WinPath[MAXPATH];
	int32_t Slow = -1;

	DWORD Disp;
	HKEY Key;

	tchar_t* AdvBase = T("SOFTWARE\\TCPMP\\ADVP");

#ifdef ARM
	tchar_t* Base = T("System\\GDI\\Drivers\\ATI");
	tchar_t* Name = T("DisableDeviceBitmap");
	HANDLE Handle;
#endif

	//-------------------------------------
	// Remove possible old files

	Remove(InstallDir,T("lang_en.plg"));
	Remove(InstallDir,T("asf.plg"));
	Remove(InstallDir,T("avi.plg"));
	Remove(InstallDir,T("a52.plg"));
	Remove(InstallDir,T("mjpeg.plg"));
	Remove(InstallDir,T("mpeg4aac.plg"));
	Remove(InstallDir,T("mpegaudio.plg"));
	Remove(InstallDir,T("mpegvideo.plg"));
	Remove(InstallDir,T("overlay.plg"));
	Remove(InstallDir,T("vorbis.plg"));

	//-------------------------------------
	// GAPI's gx.dll keep it or not?

	WinPath[0] = 0;
	CoreDLL = LoadLibrary(T("coredll.dll"));
	if (CoreDLL)
	{
		BOOL (WINAPI* FuncSHGetSpecialFolderPath)(HWND,LPTSTR,int,BOOL);

		*(FARPROC*)&FuncSHGetSpecialFolderPath = GetProcAddress(CoreDLL,T("SHGetSpecialFolderPath"));

		if (FuncSHGetSpecialFolderPath)
			FuncSHGetSpecialFolderPath(NULL,WinPath,0x24/*CSIDL_WINDOWS*/,FALSE);

		FreeLibrary(CoreDLL);
	}
	if (!WinPath[0])
		tcscpy_s(WinPath,MAXPATH,T("\\Windows"));

	tcscat_s(WinPath,MAXPATH,T("\\gx.dll")); //Mod2010
	tcscpy_s(LocalPath,MAXPATH,InstallDir);
	tcscat_s(LocalPath,MAXPATH,T("\\gx.dll")); //Mod2010

	GAPI = LoadLibrary(WinPath);
	if (GAPI)
	{
		DeleteFile(LocalPath);
	}
	else
	{
		GAPI = LoadLibrary(LocalPath); // can we load our gx.dll? aygshell.dll available?
		if (GAPI)
		{
			// check new HPC device with aygshell support, but no GXINFO

			OSVERSIONINFO Ver;
			Ver.dwOSVersionInfoSize = sizeof(Ver);
			GetVersionEx(&Ver);

			if (Ver.dwMajorVersion >= 4)
			{
				HDC DC = GetDC(NULL);
				DWORD Code = GETGXINFO;
				GXDeviceInfo Info;
				memset(&Info,0,sizeof(Info));
				Info.Version = 100;

				if (ExtEscape(DC, ESC_QUERYESCSUPPORT, sizeof(DWORD), (char*)&Code, 0, NULL) > 0)
					ExtEscape(DC, GETGXINFO, 0, NULL, sizeof(Info), (char*)&Info);

				if (Info.cxWidth==0 || Info.cyHeight==0)
				{
					// release and remove our gx.dll
					FreeLibrary(GAPI);
					GAPI = NULL;
				}

				ReleaseDC(NULL,DC);
			}
		}

		if (!GAPI)
		{
			DeleteFile(LocalPath);
			GAPI = LoadLibrary(T("gx.dll")); // try load on path
		}
	}

	//-------------------------------------
	// Benchmark video memory

	SlowVideoRAW(&Slow);

	if (GAPI)
	{
		if (Slow == -1)
			SlowVideoGAPI(GAPI,Parent,&Slow);
		FreeLibrary(GAPI);
	}

	// EPSON display drive in NEXIO
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, T("Drivers\\Display\\S1D13806"), 0, KEY_READ, &Key) == ERROR_SUCCESS)
	{
		Slow = 1;
		RegCloseKey(Key);
	}

	if (Slow != -1)
	{
		if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, AdvBase, 0, NULL, 0, 0, NULL, &Key, &Disp) == ERROR_SUCCESS)
		{
			tchar_t Name[32];
			IntToString(Name,TSIZEOF(Name),ADVANCED_SLOW_VIDEO,0);
			RegSetValueEx(Key, Name, 0, REG_DWORD, (LPBYTE)&Slow, sizeof(Slow));
			RegCloseKey(Key);
		}
	}

#ifdef ARM

	//-------------------------------------
	// ATI Imageon 3200 registry settings

	Handle = LoadLibrary(T("ACE_DDI.DLL"));
	if (Handle)
	{
		FreeLibrary(Handle);

		if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, Base, 0, NULL, 0, KEY_READ|KEY_WRITE, NULL, &Key, &Disp) == ERROR_SUCCESS)
		{
			DWORD Value;
			DWORD RegType;
			DWORD RegSize;

			RegSize=sizeof(Value);
			if (RegQueryValueEx(Key, Name, 0, &RegType, (LPBYTE)&Value, &RegSize) != ERROR_SUCCESS || !Value)
			{
				Value = 1;
				RegSetValueEx(Key, Name, 0, REG_DWORD, (LPBYTE)&Value, sizeof(Value));

				MessageBox(Parent,
					T("TCPMP installer disabled ATI IMAGEON device bitmap caching for better video playback. ") 
					T("After install please warm boot the device for changes to take effect! ")
					T("You can change this setting later in the player."),T("Setup"),MB_OK|MB_SETFOREGROUND);
			}
			RegCloseKey(Key);
		}
	}
	else
	{
		tcscpy_s(LocalPath,MAXPATH,InstallDir);
		tcscat_s(LocalPath,MAXPATH,T("\\ati3200.plg"));
		DeleteFile(LocalPath);
	}

	//-------------------------------------
	// Intel 2700G 

	Handle = LoadLibrary(T("PVRVADD.DLL"));
	if (Handle)
	{
		FreeLibrary(Handle);
	}
	else
	{
		tcscpy_s(LocalPath,MAXPATH,InstallDir);
		tcscat_s(LocalPath,MAXPATH,T("\\intel2700g.plg"));
		DeleteFile(LocalPath);
	}

#endif

	return 0;
}
示例#23
0
INT_PTR CALLBACK DlgProcSettings(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	static TCHAR customCommand[MAX_PATH] = {0};
	static TCHAR customText[TITLE_SIZE] = {0};
	static TCHAR szKeyTemp[MAX_PATH + GUID_STRING_SIZE];

	static DWORD showMenu = 2;	//0 off, 1 on, 2 unknown
	static DWORD showIcon = 2;

	static DWORD isDynamic = 1;	//0 off, 1 on
	static DWORD useMenuIcon = 1;	// 0 off, otherwise on
	static DWORD iconType = 0;	//0 classic, 1 modern

	HKEY settingKey;
	LONG result;
	DWORD size = 0;

	switch(uMsg) {
		case WM_INITDIALOG: {
			wsprintf(szKeyTemp, TEXT("CLSID\\%s\\Settings"), szGUID);
			result = RegOpenKeyEx(HKEY_CLASSES_ROOT, szKeyTemp, 0, KEY_READ, &settingKey);
			if (result == ERROR_SUCCESS) {
				size = sizeof(TCHAR)*TITLE_SIZE;
				result = RegQueryValueEx(settingKey, TEXT("Title"), NULL, NULL, (LPBYTE)(customText), &size);
				if (result != ERROR_SUCCESS) {
					lstrcpyn(customText, szDefaultMenutext, TITLE_SIZE);
				}

				size = sizeof(TCHAR)*MAX_PATH;
				result = RegQueryValueEx(settingKey, TEXT("Custom"), NULL, NULL, (LPBYTE)(customCommand), &size);
				if (result != ERROR_SUCCESS) {
					lstrcpyn(customCommand, TEXT(""), MAX_PATH);
				}

				size = sizeof(DWORD);
				result = RegQueryValueEx(settingKey, TEXT("IconID"), NULL, NULL, (BYTE*)(&iconType), &size);
				if (result != ERROR_SUCCESS) {
					iconType = 0;
				}

				size = sizeof(DWORD);
				result = RegQueryValueEx(settingKey, TEXT("Dynamic"), NULL, NULL, (BYTE*)(&isDynamic), &size);
				if (result != ERROR_SUCCESS) {
					isDynamic = 1;
				}

				size = sizeof(DWORD);
				result = RegQueryValueEx(settingKey, TEXT("ShowIcon"), NULL, NULL, (BYTE*)(&useMenuIcon), &size);
				if (result != ERROR_SUCCESS) {
					useMenuIcon = 1;
				}

				RegCloseKey(settingKey);
			}

			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_USECONTEXT), BST_INDETERMINATE);
			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_USEICON), BST_INDETERMINATE);

			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_CONTEXTICON), useMenuIcon?BST_CHECKED:BST_UNCHECKED);
			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_ISDYNAMIC), isDynamic?BST_CHECKED:BST_UNCHECKED);

			Button_SetCheck(GetDlgItem(hwndDlg, IDC_RADIO_CLASSIC), iconType!=0?BST_CHECKED:BST_UNCHECKED);
			Button_SetCheck(GetDlgItem(hwndDlg, IDC_RADIO_MODERN), iconType==0?BST_CHECKED:BST_UNCHECKED);

			SetDlgItemText(hwndDlg, IDC_EDIT_MENU, customText);
			SetDlgItemText(hwndDlg, IDC_EDIT_COMMAND, customCommand);

			return TRUE;
			break; }
		case WM_COMMAND: {
			switch(LOWORD(wParam)) {
				case IDOK: {
					//Store settings
					GetDlgItemText(hwndDlg, IDC_EDIT_MENU, customText, TITLE_SIZE);
					GetDlgItemText(hwndDlg, IDC_EDIT_COMMAND, customCommand, MAX_PATH);
					int textLen = lstrlen(customText);
					int commandLen = lstrlen(customCommand);

					wsprintf(szKeyTemp, TEXT("CLSID\\%s\\Settings"), szGUID);
					result = RegCreateKeyEx(HKEY_CLASSES_ROOT, szKeyTemp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
					if (result == ERROR_SUCCESS) {

						result = RegSetValueEx(settingKey, TEXT("Title"), 0,REG_SZ, (LPBYTE)customText, (textLen+1)*sizeof(TCHAR));
						result = RegSetValueEx(settingKey, TEXT("Custom"), 0,REG_SZ, (LPBYTE)customCommand, (commandLen+1)*sizeof(TCHAR));

						result = RegSetValueEx(settingKey, TEXT("IconID"), 0, REG_DWORD, (LPBYTE)&iconType, sizeof(DWORD));
						result = RegSetValueEx(settingKey, TEXT("Dynamic"), 0, REG_DWORD, (LPBYTE)&isDynamic, sizeof(DWORD));
						result = RegSetValueEx(settingKey, TEXT("ShowIcon"), 0, REG_DWORD, (LPBYTE)&useMenuIcon, sizeof(DWORD));

						RegCloseKey(settingKey);
					}

					if (showMenu == 1) {
						result = RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++")sz64, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
						if (result == ERROR_SUCCESS) {
							result = RegSetValueEx(settingKey, NULL, 0,REG_SZ, (LPBYTE)szGUID, (lstrlen(szGUID)+1)*sizeof(TCHAR));
							RegCloseKey(settingKey);
						}
					} else if (showMenu == 0) {
						wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s")sz64, szShellExtensionTitle);
						RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
					}

					if (showIcon == 1) {
						result = RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex\\IconHandler"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
						if (result == ERROR_SUCCESS) {
							result = RegSetValueEx(settingKey, NULL, 0,REG_SZ, (LPBYTE)szGUID, (lstrlen(szGUID)+1)*sizeof(TCHAR));
							RegCloseKey(settingKey);
						}
					} else if (showIcon == 0) {
						RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex\\IconHandler"));
						RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex"));
					}

					PostMessage(hwndDlg, WM_CLOSE, 0, 0);
					break; }
				case IDC_CHECK_USECONTEXT: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						showMenu = 1;
					else if (state == BST_UNCHECKED)
						showMenu = 0;
					else
						showMenu = 2;
					break; }
				case IDC_CHECK_USEICON: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						showIcon = 1;
					else if (state == BST_UNCHECKED)
						showIcon = 0;
					else
						showIcon = 2;
					break; }
				case IDC_CHECK_CONTEXTICON: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						useMenuIcon = 1;
					else
						useMenuIcon = 0;
					break; }
				case IDC_CHECK_ISDYNAMIC: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						isDynamic = 1;
					else
						isDynamic = 0;
					break; }
				case IDC_RADIO_CLASSIC: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						iconType = 1;
					else
						iconType = 0;
					break; }
				case IDC_RADIO_MODERN: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						iconType = 0;
					else
						iconType = 1;
					break; }
			}

			return TRUE;
			break; }
		case WM_CLOSE: {
			EndDialog(hwndDlg, 0);
			return TRUE;
			break; }
	}

	return FALSE;
}
示例#24
0
void installService(int argc, char **argv)
{
    SC_HANDLE   schService;
    SC_HANDLE   schSCManager;

    TCHAR szPath[512], szDescr[256];

    TCHAR szAppParameters[8192];

    char szParamKey[1025], szParamKey2[1025];

    sprintf(szParamKey,"SYSTEM\\CurrentControlSet\\Services\\%s\\Parameters",SZSERVICENAME);

    // Get the full path and filename of this program
    if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) {
        _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME),
                 GetLastErrorText(szErr, 256));
        return;
    }

    // Next, get a handle to the service control manager
    schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

    if ( schSCManager ) {
        schService = CreateService(schSCManager,   // SCManager database
                                   TEXT(SZSERVICENAME),        // name of service
                                   TEXT(SZSERVICEDISPLAYNAME), // name to display
                                   SERVICE_ALL_ACCESS,         // desired access
                                   SERVICE_WIN32_OWN_PROCESS,  // service type
                                   SERVICESTARTTYPE,           // start type
                                   SERVICE_ERROR_NORMAL,       // error control type
                                   szPath,                     // service's binary
                                   NULL,                       // no load ordering group
                                   NULL,                       // no tag identifier
                                   TEXT(SZDEPENDENCIES),       // dependencies
                                   NULL,                       // LocalSystem account
                                   NULL);                      // no password

        if (schService) {
            _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );

            // Close the handle to this service object
            CloseServiceHandle(schService);

            /* ****************************************** */
            // Set the service name. Courtesy of Yuri Francalacci <*****@*****.**>
            sprintf(szParamKey2, "SYSTEM\\CurrentControlSet\\Services\\%s",SZSERVICENAME);
            strcpy(szDescr, "ntopng: Web-based network traffic monitor");

            // Set the file value (where the message resources are located.... in this case, our runfile.)
            if(0 != setStringValue((const unsigned char *)szDescr,
                                   strlen(szDescr) + 1,HKEY_LOCAL_MACHINE, szParamKey2,TEXT("Description")))
            {
                _tprintf(TEXT("The Message File value could\nnot be assigned.\n"));
            }
            /* ********************************************** */


            //Make a registry key to support logging messages using the service name.
            sprintf(szParamKey2, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",SZSERVICENAME);
            if(0 != makeNewKey(HKEY_LOCAL_MACHINE, szParamKey2)) {
                _tprintf(TEXT("The EventLog subkey could not be created.\n"));
            }

            // Set the file value (where the message resources are located.... in this case, our runfile.)
            if(0 != setStringValue((const unsigned char *) szPath,
                                   strlen(szPath) + 1,HKEY_LOCAL_MACHINE,
                                   szParamKey2,TEXT("EventMessageFile")))
            {
                _tprintf(TEXT("The Message File value could\nnot be assigned.\n"));
            }

            // Set the supported types flags.
            if(0 != setDwordValue(EVENTLOG_INFORMATION_TYPE,HKEY_LOCAL_MACHINE, szParamKey2,TEXT("TypesSupported"))) {
                _tprintf(TEXT("The Types Supported value could\nnot be assigned.\n"));
            }

            // Try to create a subkey to hold the runtime args for the JavaVM and
            // Java application
            if(0 != makeNewKey(HKEY_LOCAL_MACHINE, szParamKey)) {
                _tprintf(TEXT("Could not create Parameters subkey.\n"));
            } else {
                //Create an argument string from the argument list
                // J. R. Duarte: modified it to store the full command line
                convertArgListToArgString((LPTSTR) szAppParameters,0, argc, argv);
                if(NULL == szAppParameters) {
                    _tprintf(TEXT("Could not create AppParameters string.\n"));
                } else {
                    HKEY hkey;
                    DWORD disposition;
                    _TCHAR data[] = "redis\0\0";

                    // Try to save the argument string under the new subkey
                    if(0 != setStringValue(szAppParameters, strlen(szAppParameters)+1,
                                           HKEY_LOCAL_MACHINE, szParamKey, SZAPPPARAMS)) {
                        _tprintf(TEXT("Could not save AppParameters value.\n"));
                    }

                    sprintf(szParamKey,"SYSTEM\\CurrentControlSet\\Services\\%s",SZSERVICENAME);


                    if( RegCreateKeyEx( HKEY_LOCAL_MACHINE, szParamKey,
                                        0, "", 0, KEY_ALL_ACCESS, NULL, &hkey, &disposition) != ERROR_SUCCESS)
                    {
                        _tprintf(TEXT("Could not create service registry key"));
                        return;
                    }


                    strcpy(szAppParameters, "redis");
                    // Try to save the argument string under the new subkey
                    if(RegSetValueEx (hkey, TEXT("DependOnService"), 0, REG_MULTI_SZ, (LPBYTE)data, strlen(data)+2) != 0) {
                        _tprintf(TEXT("Could not save DependOnService value.\n"));
                    }

                    RegCloseKey(hkey);
                }
            }

        }
        else {
            _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
        }

        // Close the handle to the service control manager database
        CloseServiceHandle(schSCManager);
    }
    else {
        _tprintf(TEXT(SZSCMGRFAILURE), GetLastErrorText(szErr,256));
    }
}
示例#25
0
int smpd_delete_smpd_data(const char *key)
{
#ifdef HAVE_WINDOWS_H
    HKEY tkey;
    DWORD result;
    char err_msg[512];

    smpd_enter_fn(FCNAME);

    if (key == NULL)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegCreateKeyEx(HKEY_LOCAL_MACHINE, SMPD_REGISTRY_KEY,
	0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &tkey, NULL);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to open the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    result = RegDeleteValue(tkey, key);
    if (result != ERROR_SUCCESS)
    {
	if (result != ERROR_FILE_NOT_FOUND && result != ERROR_PATH_NOT_FOUND)
	{
	    smpd_translate_win_error(result, err_msg, 512, "Unable to delete the smpd registry value '%s', error %d: ", key, result);
	    smpd_err_printf("%s\n", err_msg);
	    RegCloseKey(tkey);
	    smpd_exit_fn(FCNAME);
	    return SMPD_FAIL;
	}
    }

    result = RegCloseKey(tkey);
    if (result != ERROR_SUCCESS)
    {
	smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_CURRENT_USER\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
	smpd_err_printf("%s\n", err_msg);
	smpd_exit_fn(FCNAME);
	return SMPD_FAIL;
    }

    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
#else
    int result;
    smpd_data_t *list = NULL, *node, *trailer;
    int num_bytes;
    int found = 0;

    smpd_enter_fn(FCNAME);

    list = smpd_parse_smpd_file();

    node = trailer = list;
    while (node)
    {
	if (strcmp(key, node->name) == 0)
	{
	    if (trailer != node)
	    {
		trailer->next = node->next;
	    }
	    else
	    {
		list = list->next;
	    }
	    found = 1;
	    MPIU_Free(node);
	    break;
	}
	if (trailer != node)
	{
	    trailer = trailer->next;
	}
	node = node->next;
    }
    if (found)
    {
	FILE *fout;
	char buffer[1024];
	char *str;
	int maxlen;

	fout = smpd_open_smpd_file(SMPD_TRUE);
	if (fout)
	{
	    while (list)
	    {
		str = buffer;
		maxlen = 1024;
		if (MPIU_Str_add_string_arg(&str, &maxlen, list->name, list->value) == MPIU_STR_SUCCESS)
		{
		    buffer[strlen(buffer)-1] = '\0'; /* remove the trailing space */
		    fprintf(fout, "%s\n", buffer);
		}
		node = list;
		list = list->next;
		MPIU_Free(node);
	    }
	    fclose(fout);
	    smpd_exit_fn(FCNAME);
	    return SMPD_SUCCESS;
	}
    }
    while (list)
    {
	node = list;
	list = list->next;
	MPIU_Free(node);
    }
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
#endif
}
示例#26
0
int CALLBACK MainWindowProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	static HWND hWndStart;
	static HWND hWndClearObjs;
	static HWND hWndDiscAll;
	static HWND hWndDBTYPE;
	static HWND hWndDBIP;
	static HWND hWndDBNAME;
	static HWND hWndDBUSER;
	static HWND hWndDBPASSWORD;
	static HWND hWndCONFIG;
	static HWND hWndACCESSFILE;
	static HWND hWndPrivate;
	static HWND hWndUpdate;

	static HWND hWndSettings[30];
	static BOOL fExit = FALSE;
	static HWND hWndExit;
	static UINT s_uTaskbarRestart;
	static BOOL fMinimized = FALSE;

	switch ( msg )
	{	
		case WM_INITDIALOG:
		{
			HICON hIcon;
			hIcon = LoadIcon( g_hInstance, MAKEINTRESOURCE( IDI_ICON ) );
			SendMessage( hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon );
			SendMessage( hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon );
			DeleteObject( hIcon );

			s_uTaskbarRestart = RegisterWindowMessage( TEXT( "TaskbarCreated" ) );

			g_hWndConsole	= GetDlgItem( hWnd, IDC_CONSOLE );
			g_hWndHelpTitle	= GetDlgItem( hWnd, IDC_HELP_TITLE );
			g_hWndHelp		= GetDlgItem( hWnd, IDC_HELP_TEXT );
			hWndDBTYPE		= GetDlgItem( hWnd, IDC_DBTYPE );
			hWndDBIP		= GetDlgItem( hWnd, IDC_DBIP );
			hWndDBNAME		= GetDlgItem( hWnd, IDC_DBNAME );
			hWndDBUSER		= GetDlgItem( hWnd, IDC_DBUSER );
			hWndDBPASSWORD	= GetDlgItem( hWnd, IDC_DBPASSWORD );
			hWndACCESSFILE	= GetDlgItem( hWnd, IDC_ACCESS_FILE );
			hWndCONFIG		= GetDlgItem( hWnd, IDC_CONFIG );
			hWndPrivate		= GetDlgItem( hWnd, IDC_SERVER );
			hWndUpdate		= GetDlgItem( hWnd, IDC_BTN_UPDATE );

			hWndSettings[0]	= GetDlgItem( hWnd, IDC_STATIP );
			hWndSettings[1]	= GetDlgItem( hWnd, IDC_STATCP );
			hWndSettings[2]	= GetDlgItem( hWnd, IDC_STATWP );
			hWndSettings[3]	= GetDlgItem( hWnd, IDC_STATDBIP );
			hWndSettings[4]	= GetDlgItem( hWnd, IDC_STATDBN );
			hWndSettings[5]	= GetDlgItem( hWnd, IDC_STATDBU );
			hWndSettings[6]	= GetDlgItem( hWnd, IDC_STATDBPASS );
			hWndSettings[7]	= GetDlgItem( hWnd, IDC_LOCALIP );
			hWndSettings[8]	= GetDlgItem( hWnd, IDC_CHARPORT );
			hWndSettings[9]	= GetDlgItem( hWnd, IDC_WORLDPORT );
			hWndSettings[10]	= GetDlgItem( hWnd, IDC_MYSQL_DB );
			hWndSettings[11]	= GetDlgItem( hWnd, IDC_MSSQL_DB );
			hWndSettings[12]	= GetDlgItem( hWnd, IDC_ACCESS_DB );
			hWndSettings[13]	= GetDlgItem( hWnd, IDC_SETTING_FRAME );
			hWndSettings[14]	= GetDlgItem( hWnd, IDC_FRAME_DB );
			hWndSettings[15]	= GetDlgItem( hWnd, IDC_STAT_MAXUSERS );
			hWndSettings[16]	= GetDlgItem( hWnd, IDC_MAX_USERS );
			hWndSettings[17]	= GetDlgItem( hWnd, IDC_STAT_SNAME );
			hWndSettings[18]	= GetDlgItem( hWnd, IDC_ED_SNAME );
							
			WSADATA		wsaData;
			struct hostent *host;
			USHORT		wVersionRequested = 0x0202;
 
			UpdateConsole( " Initializing Winsock 2.0 ... ", !WSAStartup( wVersionRequested, &wsaData ) );
			
			host = NULL;
/*
			////////// Read in Data
			FILE *pcStatConfig = fopen( "status.ini","rt" );

			if ( pcStatConfig )
			{
				char line[100];

				while ( !feof( pcStatConfig ) )
				{
					fgets( line, 100, pcStatConfig );
					char temp[100];
					char strData[50];
					char value[50];

					memcpy(temp,line,sizeof(line));
					char* pszSepTemp = strchr(temp, (int)'=');

					if(pszSepTemp == NULL)
					{
					}
					else
					{
						*pszSepTemp = '\0';
						sprintf(strData,"%s",temp);
					}

					char* pszSep = strchr(line, (int)'=');	

					if(pszSep == NULL)
					{
						// No data
					}
					else
					{
						*pszSep = '\0';
						++pszSep;
						char* pszValue = strchr(pszSep, (int)';');
						if(pszValue == NULL){
						}
						else
						{
							*pszValue = '\0';
						}
					
						sprintf(value,"%s",pszSep);
						
						if (lstrcmpi(strData,"Server") == 0)
							{
								if( lstrcmpi(value,"Private") == 0)
								{
									UpdateConsole(" Server: Private\r\n");
									cMasterServer::cStatus->m_fPrivate = 1;
								}
								else
								{
									UpdateConsole(" Server: Public\r\n");
									cMasterServer::cStatus->m_fPrivate = 0;
								}
							}
						else if(lstrcmpi(strData,"Host") == 0)
							{
								if(isalpha(value[0]))
								{
									//Do DNS Lookup for IP
									host = gethostbyname(value);
									memcpy(cMasterServer::cStatus->m_strHost,inet_ntoa(*(struct in_addr *) host->h_addr_list[0]),16);
								}
								else
								{
									memcpy(cMasterServer::cStatus->m_strHost,value,sizeof(value));
								}	
							}
						else if(lstrcmpi(strData,"Port") == 0)
							{
								cMasterServer::cStatus->m_sPort = atoi(value);
							}
						else if(lstrcmpi(strData,"Path") == 0)
							{
								memcpy(cMasterServer::cStatus->m_strHTTP,value,sizeof(value));
							}					
						else if(lstrcmpi(strData,"ID") == 0)
							{
								cMasterServer::cStatus->m_sID = atol(value);
							}
						else if(lstrcmpi(strData,"Serial") == 0)
							{
								memcpy(cMasterServer::cStatus->m_sSer,value,sizeof(value));
							}
						else if(lstrcmpi(strData,"Key") == 0)
							{
								memcpy(cMasterServer::cStatus->m_sKey,value,sizeof(value));
							}
						else if(lstrcmpi(strData,"Client") == 0)
							{
								memcpy(cMasterServer::cStatus->m_cVersion,value,sizeof(value));
							}
						else if(lstrcmpi(strData,"MaxUsers") == 0)
							{
								cMasterServer::cStatus->m_dwMax = atol(value);
							}
						else
							{
							//	UpdateConsole("Error in status.ini   %s\r\n", strData);
							}
					}
				}
				fclose( pcStatConfig );
			}
			else
			{
				cMasterServer::cStatus->m_fPrivate = true;

			}
*/
			cMasterServer::cStatus->m_fPrivate = true;

			//////////////////
			SetDlgItemText( hWnd, IDC_VERSIONTEXT, SERVERVERSION);
			SetDlgItemText( hWnd, IDC_VERSIONTEXT2, STRFILEVER);

			DWORD dwLength;
			DWORD dwType = REG_SZ;
			char szTemp[5];
			char szDBType[2];
			char szStatusTemp[20];
			char szHostTemp[64];

			HKEY hKey;
			RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
		
			////////////////////////
			// Server Status Settings
			dwLength = sizeof( szStatusTemp );
			if ( ( RegQueryValueEx( hKey, "Private", NULL, &dwType, (BYTE*)&szStatusTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				cMasterServer::cStatus->m_fPrivate = atoi(szStatusTemp);
				CheckDlgButton( hWnd, IDC_SERVER, cMasterServer::cStatus->m_fPrivate );
			}
			else
			{
				CheckDlgButton( hWnd, IDC_SERVER, 1 );
				cMasterServer::cStatus->m_fPrivate = 1;
			}
			
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Status Host", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				if(isalpha(szHostTemp[0]))
				{
					//Do DNS Lookup for IP
					host = gethostbyname(szHostTemp);
					memcpy(cMasterServer::cStatus->m_strHost,inet_ntoa(*(struct in_addr *) host->h_addr_list[0]),16);
					SetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp );
				}
				else
				{
					memcpy(cMasterServer::cStatus->m_strHost,szHostTemp,sizeof(szHostTemp));
					SetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp );
				}
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_HOST, "127.0.0.1" );
				memcpy(cMasterServer::cStatus->m_strHost,"127.0.0.1",10);
			}
						
			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "HTTP Port", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_PORT, szTemp );
				cMasterServer::cStatus->m_sPort = atoi(szTemp);
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_PORT, "80" );
				cMasterServer::cStatus->m_sPort = 80;
			}

			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "Server ID", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_ID, szTemp );
				cMasterServer::cStatus->m_sID = atol(szTemp);
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_ID, "0" );
				cMasterServer::cStatus->m_sID = 0;
			}

			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Server Serial", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp );
				memcpy(cMasterServer::cStatus->m_sSer,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_SERIAL, "0" );
				memcpy(cMasterServer::cStatus->m_sSer,"0",2);
			}
			
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Server Key", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp );
				memcpy(cMasterServer::cStatus->m_sKey,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_KEY, "000000" );
				memcpy(cMasterServer::cStatus->m_sKey,"000000",7);
			}

			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Client Support", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp );
				memcpy(cMasterServer::cStatus->m_cVersion,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_CLIENT, "53" );
				memcpy(cMasterServer::cStatus->m_cVersion,"53",3);
			}
						
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "HTTP Path", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ED_URL, szHostTemp );
				memcpy(cMasterServer::cStatus->m_strHTTP,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_URL, "/" );
				memcpy(cMasterServer::cStatus->m_strHTTP,"/",2);
			}
			
			////////////////////////
			// Server Settings
			// Server Name
			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Server Name", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_STAT_NAME, szHostTemp );
				SetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp );
				memcpy(cMasterServer::m_szServerName,szHostTemp,sizeof(szHostTemp));
			}
			else
			{
				SetDlgItemText( hWnd, IDC_ED_SNAME, "World Name" );
				SetDlgItemText( hWnd, IDC_STAT_NAME, "World Name" );
				sprintf(cMasterServer::m_szServerName,"World Name" );
			}

			dwLength = sizeof( szHostTemp );
			if ( ( RegQueryValueEx( hKey, "Max Clients", NULL, &dwType, (BYTE*)&szHostTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp );
				cMasterServer::cStatus->m_dwMax = atol(szHostTemp);
			}
			else
			{
				SetDlgItemText( hWnd, IDC_MAX_USERS, "0" );
				cMasterServer::cStatus->m_dwMax = 0x0L;
			}

			//Character Server Port
			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "CharPort", NULL, &dwType, (BYTE*)&szTemp, &dwLength) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_CHARPORT, szTemp );
			else
				SetDlgItemText( hWnd, IDC_CHARPORT, "9002" );

			// World Server Port
			dwLength = sizeof( szTemp );
			if ( ( RegQueryValueEx( hKey, "WorldPort", NULL, &dwType, (BYTE*)&szTemp, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_WORLDPORT, szTemp );
			else
				SetDlgItemText( hWnd, IDC_WORLDPORT, "9004" );
			
			/////////////
			// Database Settings
	
			dwLength = sizeof( szDBType );
			if ( ( RegQueryValueEx( hKey, "DBType", NULL, &dwType, (BYTE*)&szDBType, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{	// Set Radio button depending on Value
				SetDlgItemText( hWnd, IDC_DBTYPE, szDBType );
				g_DBType = szDBType[0] - 0x30;
				switch(g_DBType)
				{
					case 1:
					{
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 1 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
									
						// Disable dialog boxes
						EnableWindow( hWndDBIP, FALSE );
						EnableWindow( hWndDBNAME, FALSE );
						EnableWindow( hWndDBUSER, FALSE );
						EnableWindow( hWndDBPASSWORD, FALSE );
						break;
					}
					case 2:
					{					
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 1 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );
						
						// Enable dialog boxes
						EnableWindow( hWndDBIP, TRUE );
						EnableWindow( hWndDBNAME, TRUE );
						EnableWindow( hWndDBUSER, TRUE );
						EnableWindow( hWndDBPASSWORD, TRUE );
						break;
					}
					case 3:
					{
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
						
						// Enable dialog boxes
						EnableWindow( hWndDBIP, TRUE );
						EnableWindow( hWndDBNAME, TRUE );
						EnableWindow( hWndDBUSER, TRUE );
						EnableWindow( hWndDBPASSWORD, TRUE );
						break;
					}

					default:
					{
						CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
						CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
						CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
									
						// Enable dialog boxes
						EnableWindow( hWndDBIP, TRUE );
						EnableWindow( hWndDBNAME, TRUE );
						EnableWindow( hWndDBUSER, TRUE );
						EnableWindow( hWndDBPASSWORD, TRUE );
						break;
					}
				}
			}
			else
			{
				// DBType = Default -- MySQL db
				CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
				CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
				CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );
			}

			dwLength = sizeof( g_szDBIP );
			if ( ( RegQueryValueEx( hKey, "DBIP", NULL, &dwType, (BYTE*)&g_szDBIP, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBIP, g_szDBIP );
			else
				SetDlgItemText( hWnd, IDC_DBIP, "0.0.0.0" );
			
			dwLength = sizeof( g_szDBNAME );
			if ( ( RegQueryValueEx( hKey, "DBNAME", NULL, &dwType, (BYTE*)&g_szDBNAME, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBNAME, g_szDBNAME );
			else
				SetDlgItemText( hWnd, IDC_DBNAME, "uas2" );
			
			dwLength = sizeof( g_szDBUSER );
			if ( ( RegQueryValueEx( hKey, "DBUSER", NULL, &dwType, (BYTE*)&g_szDBUSER, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBUSER, g_szDBUSER );
			else
				SetDlgItemText( hWnd, IDC_DBUSER, "uas2" );
			
			dwLength = sizeof( g_szDBPASSWORD );
			if ( ( RegQueryValueEx( hKey, "DBPASSWORD", NULL, &dwType, (BYTE*)&g_szDBPASSWORD, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_DBPASSWORD, g_szDBPASSWORD );
			else
				SetDlgItemText( hWnd, IDC_DBPASSWORD, "" );
//////////////////////////////////////////////////////////////////

			// Local IP
			dwLength = sizeof( g_szLocalIP );
			if ( ( RegQueryValueEx( hKey, "LocalIP", NULL, &dwType, (BYTE*)&g_szLocalIP, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
				SetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP );
			else
			{
				char szLocalHostName[80];
				DWORD dwSize = sizeof( szLocalHostName );
				if ( GetLocalAddress( szLocalHostName, &dwSize ) == 0 )
					SetDlgItemText( hWnd, IDC_LOCALIP, szLocalHostName );
				else
					SetDlgItemText( hWnd, IDC_LOCALIP, "127.0.0.1" );
			}
	
			// Access Database 
			char	szDirBuff[MAX_PATH+1];
			dwLength = sizeof( cWorldManager::g_szAccessFile );
			if ( ( RegQueryValueEx( hKey, "ACCESSMDB", NULL, &dwType, (BYTE*)&cWorldManager::g_szAccessFile, &dwLength ) == ERROR_SUCCESS ) && ( dwLength > 0 ) )
			{
				SetDlgItemText( hWnd, IDC_ACCESS_FILE, cWorldManager::g_szAccessFile );
			}
			else
			{
				int index = GetCurrentDirectory(MAX_PATH, szDirBuff);
				sprintf(cWorldManager::g_szAccessFile,"%s\\UAS2.mdb", szDirBuff );
				SetDlgItemText( hWnd, IDC_ACCESS_FILE,cWorldManager::g_szAccessFile );
			}

			RegCloseKey( hKey );

			hWndStart = GetDlgItem( hWnd, IDB_START );
			hWndClearObjs = GetDlgItem( hWnd, IDB_CLEAROBJECTS );
			hWndDiscAll = GetDlgItem( hWnd, IDB_DISC_ALL );
			hWndExit = GetDlgItem( hWnd, IDB_EXIT );

			/////// Server Status Data ///////////////////////////////////////////////
			char szPort[5];
			char szTempIP[16];
			SOCKADDR_IN	saServer;

			GetDlgItemText( hWnd, IDC_LOCALIP, szTempIP, sizeof( szTempIP ) );
			saServer.sin_addr.s_addr	= inet_addr( szTempIP );
		
			cMasterServer::cStatus->m_bServer[0] = saServer.sin_addr.S_un.S_un_b.s_b1;
			cMasterServer::cStatus->m_bServer[1] = saServer.sin_addr.S_un.S_un_b.s_b2;
			cMasterServer::cStatus->m_bServer[2] = saServer.sin_addr.S_un.S_un_b.s_b3;
			cMasterServer::cStatus->m_bServer[3] = saServer.sin_addr.S_un.S_un_b.s_b4;

			GetDlgItemText( hWnd, IDC_CHARPORT, szPort, sizeof( szPort ) );
			cMasterServer::cStatus->m_ServerPort = atoi( szPort );
			///////////////////////////////////////////////////////////////////////////
			MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_NORM ,CONSOLE_HEIGHT_NORM , TRUE );

			cMasterServer::cStatus->ServerLoad();

			break;	// case WM_INITDIALOG
		}

		case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO( lParam )->ptMinTrackSize.x = 340;
			LPMINMAXINFO( lParam )->ptMinTrackSize.y = CONSOLE_HEIGHT_NORM;//150
			break;	// case WM_GETMINMAXINFO
		}

		case WM_SIZE:
		{
			MoveWindow( g_hWndConsole, 8, 95, LOWORD( lParam ) - 15, HIWORD( lParam ) - 100, TRUE );

			if( wParam == SIZE_MINIMIZED )
			{
				SystrayAdd( hWnd );
				ShowWindow( hWnd, SW_HIDE );
				fMinimized = TRUE;
			}
			else if( wParam == SIZE_RESTORED )
			{
				SystrayDelete( hWnd );
				fMinimized = FALSE;	
			}

			break;	// case WM_SIZE
		}

		case WM_NOTIFY:
		{
			break;	// case WM_NOTIFY
		}

		case WM_COMMAND:
		{	
			switch ( GET_WM_COMMAND_ID( wParam, lParam ) )
			{
				case IDC_LOCALIP:
					{
						UpdateHelpTitle( "Local IP:\r\n");
						UpdateHelp( "The IP address or DNS name of the hosting server. The default value is the IP address 127.0.0.1 (the loopback IP address).\r\n");
						break;
					}
				case IDC_SERVER:
					{
						UpdateHelpTitle( "Private Server Checkbox:\r\n");
						UpdateHelp( "When checked, server will not send updates to the status website. The option does not affect how the server operates.\r\n");
						break;
					}
				case IDC_CHARPORT:
					{
						UpdateHelpTitle( "Character Server Port:\r\n");
						UpdateHelp( "The number of the TCP or UDP port used to connect to the Character Server. The default value is 9002.\r\n");
						break;
					}
				case IDC_MAX_USERS:
					{
						UpdateHelpTitle( "Maximum Clients:\r\n");
						UpdateHelp( "The maximum number of clients the server allows. Not implemented.\r\n");
						break;
					}
				case IDC_WORLDPORT:
					{
						UpdateHelpTitle( "World Server Port:\r\n");
						UpdateHelp( "The number of the TCP or UDP port used to connect to the World Server. The default value is 9004.\r\n");
						break;
					}
				case IDC_ED_SNAME:
					{
						UpdateHelpTitle( "World Name:\r\n");
						UpdateHelp( "The name used to identify the world hosted by this server. Appears in the MOTD during login process.\r\n");
						break;
					}

				case IDC_ACCESS_FILE:
					{
						UpdateHelpTitle( "Microsoft Access File:\r\n");
						UpdateHelp( "The full path to the UAS2 Microsoft Access (.mdb) database file. The default path is the working directory.\r\n");
						break;
					}
				case IDC_DBIP:
					{
						UpdateHelpTitle( "Database IP:\r\n");
						UpdateHelp( "The IP address of the database server.  The value must be an IP address and not a DNS name.\r\n");
						break;
					}
				case IDC_DBNAME:
					{
						UpdateHelpTitle( "Database Name:\r\n");
						UpdateHelp( "The name of the UAS2 database.\r\n");
						break;
					}
				case IDC_DBUSER:
					{
						UpdateHelpTitle( "Database User:\r\n");
						UpdateHelp( "A username with permission to access the database.\r\n");
						break;
					}
				case IDC_DBPASSWORD:
					{
						UpdateHelpTitle( "Database Password:\r\n");
						UpdateHelp( "The password for the corresponding username.\r\n");
						break;
					}

				case IDC_ED_HOST:
					{
						UpdateHelpTitle( "State Website Host:\r\n");
						UpdateHelp( "The IP address or DNS name of the website hosting the server status pages.\r\n");
						break;
					}
				case IDC_ED_URL:
					{
						UpdateHelpTitle( "URL Path:\r\n");
						UpdateHelp( "The URL path to the server status webpage. Must start with '/' and end with '/'.\r\n");
						break;
					}
				case IDC_ED_PORT:
					{
						UpdateHelpTitle( "Access Port:\r\n");
						UpdateHelp( "The number of the TCP or UDP port used to access the server status website. The default port number is 80 (HTTP).\r\n");
						break;
					}
				case IDC_ED_ID:
					{
						UpdateHelpTitle( "Server ID:\r\n");
						UpdateHelp( "The server ID for the server status listing. Supplied by the host website during registration.\r\n");
						break;
					}
				case IDC_ED_KEY:
					{
						UpdateHelpTitle( "Key ID:\r\n");
						UpdateHelp( "The key ID for the server status listing. Supplied by the host website during registration.\r\n");
						break;
					}
				case IDC_ED_CLIENT:
					{
						UpdateHelpTitle( "Client Version:\r\n");
						UpdateHelp( "Specifies which client(s) are supported with this server. Supplied by the host website during registration.\r\n");
						break;
					}
				case IDC_ED_SERIAL:
					{
						UpdateHelpTitle( "Serial Code:\r\n");
						UpdateHelp( "The serial code for your server to use when connecting to the server status host website. Supplied by the host website during registration.\r\n");
						break;
					}

				case IDC_WBBOX:
					{
						UpdateHelpTitle( "World Broadcast:\r\n");
						UpdateHelp( "A message that may be sent to all users presently connected to the world.\r\n");
						break;
					}

				case IDB_EXIT:
					{
						UpdateConsole( "\r\n Exiting server. Please wait ...\r\n" );
						cMasterServer::cStatus->ServerOffline();
						PostMessage( hWnd, WM_CLOSE, 0, 0 );
						EnableWindow( hWndExit, FALSE );
						break;	// case IDB_EXIT
					}

				case IDB_CLEAROBJECTS:
					if ( g_fStarted )
					{
						cMasterServer::ClearAllObjects( );
						UpdateConsole( " All spawned objects cleared!\r\n" );
						break;
					}
					break;

				case IDB_DISC_ALL:
				{
					if( g_fStarted )
					{
						cMasterServer::DisconnectAllClients( );
						UpdateConsole( " All clients disconnected!\r\n" );
						break;
					}
					break;
				}

				//Karki
				case IDC_WB:
					if ( g_fStarted )
					{
						UpdateConsole( " World broadcast sent!\r\n" );
						char szWBTemp[255];
						GetDlgItemText( hWnd, IDC_WBBOX, szWBTemp, sizeof( szWBTemp ) );
						cMasterServer::ServerMessage( ColorGreen, NULL, "%s", szWBTemp );
					}
					break;

				case IDB_START:
				{
					if ( g_fStarted )
					{					
						EnableWindow( hWndStart, FALSE );
						EnableWindow( hWndClearObjs, FALSE );
						EnableWindow( hWndDiscAll, FALSE );
						
						g_fStarted = !cMasterServer::Unload( );

						if( ( fExit ) && ( !g_fStarted ) )
						{
							SystrayDelete( hWnd );
							DestroyWindow( hWnd );
							PostQuitMessage( 0 );
						}
						
						SetWindowText( hWndStart, "&Start Server" );
						EnableWindow( hWndStart, TRUE );
					}
					else
					{
						g_fStarted = TRUE;

						char szTemp[5];

						GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
						GetDlgItemText( hWnd, IDC_DBTYPE, szTemp, sizeof( szTemp ) );
						g_DBType = szTemp[0] - 0x30;
						GetDlgItemText( hWnd, IDC_DBIP, g_szDBIP, sizeof( g_szDBIP ) );
						GetDlgItemText( hWnd, IDC_DBNAME, g_szDBNAME, sizeof( g_szDBNAME ) );
						GetDlgItemText( hWnd, IDC_DBUSER, g_szDBUSER, sizeof( g_szDBUSER ) );
						GetDlgItemText( hWnd, IDC_DBPASSWORD, g_szDBPASSWORD, sizeof( g_szDBPASSWORD ) );
						GetDlgItemText( hWnd, IDC_ACCESS_FILE, cWorldManager::g_szAccessFile, sizeof( cWorldManager::g_szAccessFile ) );

						SetDlgItemText( hWnd, IDB_START, "&Stop Server");
							
						GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
						g_nCharPort = atoi( szTemp );

						GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
						g_nWorldPort = atoi( szTemp );

						cDatabase::SetupDB(g_DBType,g_szDBIP,g_szDBNAME,g_szDBUSER,g_szDBPASSWORD);

						cMasterServer::Load( );

						EnableWindow( hWndClearObjs, TRUE );
						EnableWindow( hWndDiscAll, TRUE );
					}
					break;	// case IDB_START
				}

				case ID_SYSTRAY_ACE:
				{
					ShowWindow( hWnd, SW_RESTORE );
					SetForegroundWindow( hWnd );
					SendMessage( hWnd, WM_ACTIVATEAPP, ( WPARAM )TRUE, ( LPARAM )NULL );
					break;
				}

				case ID_SYSTRAY_EXIT:
				{
					PostMessage( hWnd, WM_CLOSE, 0, 0 );
					break;
				}

				case IDC_CONFIG:
				{
					if(g_fConfig == FALSE)
					{
						UpdateHelpTitle("Configuration Settings:\r\n");
						UpdateHelp("Changes will not take effect until the server program is restarted.\r\n");
						MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_OPT ,CONSOLE_HEIGHT_OPT , TRUE );
						ShowWindow( hWndDBIP, SW_SHOW );
						ShowWindow( hWndDBNAME, SW_SHOW );
						ShowWindow( hWndDBUSER, SW_SHOW );
						ShowWindow( hWndDBPASSWORD, SW_SHOW );
						ShowWindow( hWndACCESSFILE, SW_SHOW );
						ShowWindow( hWndPrivate, SW_SHOW );
						SetWindowText( hWndCONFIG, "Status" );
						for(int i = 0; i< 30;i++)
						{
							ShowWindow( hWndSettings[i], SW_SHOW );
						}
						ShowWindow( g_hWndConsole, SW_HIDE );
						g_fConfig = TRUE;
					}
					else
					{
						MoveWindow( hWnd,0 , 0 , CONSOLE_WIDTH_NORM ,CONSOLE_HEIGHT_NORM , TRUE );						
						ShowWindow( hWndDBIP, SW_HIDE );
						ShowWindow( hWndDBNAME, SW_HIDE );
						ShowWindow( hWndDBUSER, SW_HIDE );
						ShowWindow( hWndDBPASSWORD, SW_HIDE );
						ShowWindow( hWndACCESSFILE, SW_HIDE );
						ShowWindow( hWndPrivate, SW_HIDE );
						SetWindowText( hWndCONFIG, "Settings" );
						for(int i = 0; i< 30;i++)
						{
							ShowWindow( hWndSettings[i], SW_HIDE );
						}
						ShowWindow( g_hWndConsole, SW_SHOW );
						g_fConfig = FALSE;
					}

					break;
				}

				case IDC_ACCESS_DB:
				{
					// Disable Dialog boxes
					EnableWindow( hWndDBIP, FALSE );
					EnableWindow( hWndDBNAME, FALSE );
					EnableWindow( hWndDBUSER, FALSE );
					EnableWindow( hWndDBPASSWORD, FALSE );
					EnableWindow( hWndACCESSFILE, TRUE );

					CheckDlgButton( hWnd, IDC_ACCESS_DB, 1 );
					CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
					CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );

					SetDlgItemText( hWnd, IDC_DBTYPE, "1" );

					UpdateHelpTitle( "Microsoft Access:\r\n");
					UpdateHelp( "A relational database management system supported by the server. Requires the use of a Microsoft Access (.mdb) database file.\r\n");

					break;
				}

				case IDC_MSSQL_DB:
				{
					// Enable Dialog boxes
					EnableWindow( hWndDBIP, TRUE );
					EnableWindow( hWndDBNAME, TRUE );
					EnableWindow( hWndDBUSER, TRUE );
					EnableWindow( hWndDBPASSWORD, TRUE );
					EnableWindow( hWndACCESSFILE, FALSE );
					
					CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
					CheckDlgButton( hWnd, IDC_MSSQL_DB, 1 );
					CheckDlgButton( hWnd, IDC_MYSQL_DB, 0 );

					SetDlgItemText( hWnd, IDC_DBTYPE, "2" );
					
					UpdateHelpTitle( "MS SQL:\r\n");
					UpdateHelp( "A relational database management system supported by the server. Requires access to an MS SQL database.\r\n");
						
					break;
				}

				case IDC_MYSQL_DB:
				{
					// Enable Dialog boxes
					EnableWindow( hWndDBIP, TRUE );
					EnableWindow( hWndDBNAME, TRUE );
					EnableWindow( hWndDBUSER, TRUE );
					EnableWindow( hWndDBPASSWORD, TRUE );
					EnableWindow( hWndACCESSFILE, FALSE );
					
					CheckDlgButton( hWnd, IDC_ACCESS_DB, 0 );
					CheckDlgButton( hWnd, IDC_MSSQL_DB, 0 );
					CheckDlgButton( hWnd, IDC_MYSQL_DB, 1 );

					SetDlgItemText( hWnd, IDC_DBTYPE, "3" );
					
					UpdateHelpTitle( "MySQL:\r\n");
					UpdateHelp( "A relational database management system supported by the server. Requires access to a MySQL database.\r\n");

					break;
				}

				case IDC_BTN_UPDATE:
				{
					char szTemp[5];
					char szDBType[2];
					char szDBTemp[20];

					HKEY hKey;
					RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
					
					GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
					RegSetValueEx( hKey, "LocalIP", NULL, REG_SZ, (BYTE*)g_szLocalIP, lstrlen( g_szLocalIP ) );
					
					GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
					RegSetValueEx( hKey, "CharPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

					GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
					RegSetValueEx( hKey, "WorldPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

					// Database Settings //////////////////////////////////////////////////////////////
					GetDlgItemText( hWnd, IDC_DBTYPE, szDBType, sizeof( szDBType ) );
					RegSetValueEx( hKey, "DBTYPE", NULL, REG_SZ, (BYTE*)szDBType, lstrlen( szDBType ) );

					GetDlgItemText( hWnd, IDC_DBIP, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBIP", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					GetDlgItemText( hWnd, IDC_DBNAME, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBNAME", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					GetDlgItemText( hWnd, IDC_DBUSER, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBUSER", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					GetDlgItemText( hWnd, IDC_DBPASSWORD, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "DBPASSWORD", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
					
					char szAccessTemp[MAX_PATH+20];
					GetDlgItemText( hWnd, IDC_ACCESS_FILE, szAccessTemp, sizeof( szAccessTemp ) );
					RegSetValueEx( hKey, "ACCESSMDB", NULL, REG_SZ, (BYTE*)szAccessTemp, lstrlen( szAccessTemp ) );

					///////////////////////////////////////////////////////////////////////////////////
					// Status Server Settings
					char szHostTemp[64];

					int nState;
					nState = IsDlgButtonChecked( hWnd, IDC_SERVER);
					sprintf(szDBTemp,"%d",nState);
					RegSetValueEx( hKey, "Private", NULL, REG_SZ, (BYTE*)szDBTemp, sizeof(szDBTemp) );

					GetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Status Host", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
								
					GetDlgItemText( hWnd, IDC_ED_PORT, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "HTTP Port", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
											
					GetDlgItemText( hWnd, IDC_ED_ID, szDBTemp, sizeof( szDBTemp ) );
					RegSetValueEx( hKey, "Server ID", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
														
					GetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Server Name", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
					memcpy(cMasterServer::m_szServerName,szHostTemp,sizeof(szHostTemp));
																	
					GetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Server Serial", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																	
					GetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Server Key", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																	
					GetDlgItemText( hWnd, IDC_ED_URL, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "HTTP Path", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																				
					GetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Client Support", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																				
					GetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp, sizeof( szHostTemp ) );
					RegSetValueEx( hKey, "Max Clients", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
					/////////////////////////////////////////////////////////////////////////////////////
					
					RegCloseKey( hKey );
					break;
				}
				default:
					break;	// case default
			}
			break;	// case WM_COMMAND
		}

		case MYWM_NOTIFYICON:
		{
			switch (lParam)
			{
				case WM_LBUTTONDOWN:
				{
					ShowWindow( hWnd, SW_RESTORE );
					SetForegroundWindow( hWnd );
					SendMessage( hWnd, WM_ACTIVATEAPP, ( WPARAM )TRUE, ( LPARAM )NULL );
					break;
				}

				case WM_RBUTTONUP:
				{
					HMENU hTrayMenu;
					HMENU hMenu;
					POINT point;

					SetForegroundWindow( hWnd );

					hTrayMenu = LoadMenu( g_hInstance, MAKEINTRESOURCE( ID_SYSTRAY ) );
					hMenu = GetSubMenu( hTrayMenu, 0 );
					GetCursorPos( &point );

					TrackPopupMenu( hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL );
					DestroyMenu( hMenu );
					DestroyMenu( hTrayMenu );

					PostMessage( hWnd, WM_NULL, 0, 0 ); 

					break;
				}
			}
			break;
		}
		case WM_CLOSE:
		{
			char szTemp[5];
			
			HKEY hKey;
			RegCreateKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\UAS", NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
			
			GetDlgItemText( hWnd, IDC_LOCALIP, g_szLocalIP, sizeof( g_szLocalIP ) );
			RegSetValueEx( hKey, "LocalIP", NULL, REG_SZ, (BYTE*)g_szLocalIP, lstrlen( g_szLocalIP ) );
			
			GetDlgItemText( hWnd, IDC_CHARPORT, szTemp, sizeof( szTemp ) );
			RegSetValueEx( hKey, "CharPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

			GetDlgItemText( hWnd, IDC_WORLDPORT, szTemp, sizeof( szTemp ) );
			RegSetValueEx( hKey, "WorldPort", NULL, REG_SZ, (BYTE*)szTemp, lstrlen( szTemp ) );

			// Database Settings //////////////////////////////////////////////////////////////
			char szDBType[2];
			char szDBTemp[20];

			GetDlgItemText( hWnd, IDC_DBTYPE, szDBType, sizeof( szDBType ) );
			RegSetValueEx( hKey, "DBTYPE", NULL, REG_SZ, (BYTE*)szDBType, lstrlen( szDBType ) );

			GetDlgItemText( hWnd, IDC_DBIP, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBIP", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			GetDlgItemText( hWnd, IDC_DBNAME, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBNAME", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			GetDlgItemText( hWnd, IDC_DBUSER, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBUSER", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			GetDlgItemText( hWnd, IDC_DBPASSWORD, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "DBPASSWORD", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
			
			char szAccessTemp[MAX_PATH+20];
			GetDlgItemText( hWnd, IDC_ACCESS_FILE, szAccessTemp, sizeof( szAccessTemp ) );
			RegSetValueEx( hKey, "ACCESSMDB", NULL, REG_SZ, (BYTE*)szAccessTemp, lstrlen( szAccessTemp ) );
			///////////////////////////////////////////////////////////////////////////////////
			// Status Server Settings
			char szHostTemp[64];

			int nState;
			nState = IsDlgButtonChecked( hWnd, IDC_SERVER);
			sprintf(szDBTemp,"%d",nState);
			RegSetValueEx( hKey, "Private", NULL, REG_SZ, (BYTE*)szDBTemp, sizeof(szDBTemp) );

			GetDlgItemText( hWnd, IDC_ED_HOST, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Status Host", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
						
			GetDlgItemText( hWnd, IDC_ED_PORT, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "HTTP Port", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
									
			GetDlgItemText( hWnd, IDC_ED_ID, szDBTemp, sizeof( szDBTemp ) );
			RegSetValueEx( hKey, "Server ID", NULL, REG_SZ, (BYTE*)szDBTemp, lstrlen( szDBTemp ) );
												
			GetDlgItemText( hWnd, IDC_ED_SNAME, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Server Name", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
															
			GetDlgItemText( hWnd, IDC_ED_SERIAL, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Server Serial", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
															
			GetDlgItemText( hWnd, IDC_ED_KEY, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Server Key", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
															
			GetDlgItemText( hWnd, IDC_ED_URL, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "HTTP Path", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																		
			GetDlgItemText( hWnd, IDC_ED_CLIENT, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Client Support", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
																				
			GetDlgItemText( hWnd, IDC_MAX_USERS, szHostTemp, sizeof( szHostTemp ) );
			RegSetValueEx( hKey, "Max Clients", NULL, REG_SZ, (BYTE*)szHostTemp, lstrlen( szHostTemp ) );
			/////////////////////////////////////////////////////////////////////////////////////
			
			RegCloseKey( hKey );

			if ( g_fStarted )
			{
				fExit = TRUE;
				SendMessage( hWnd, WM_COMMAND, IDB_START, TRUE );
			}
			else
			{
				WSACleanup();
				SystrayDelete( hWnd );
				DestroyWindow( hWnd );
				PostQuitMessage( 0 );
			}

			break;	// case WM_CLOSE
		}

		default:
			if( ( msg == s_uTaskbarRestart ) && ( fMinimized ) )
			{
				SystrayDelete( hWnd );
				SystrayAdd( hWnd );
				break;
			}
	}
	return FALSE;
}
示例#27
0
int DDE::RegisterFileAssociation(DDEInfo& info)
{
	DWORD dwDisp;
	HKEY hKey;
	if(RegCreateKeyEx(HKEY_CLASSES_ROOT, info.extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp)) {
		Log::Error("ERROR: Could not create extension key: %s", info.extension);
		return 1;
	}

	if(RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE *) info.name, strlen(info.name) + 1)) {
		Log::Error("ERROR: Could not set name for extension: %s", info.extension);
		return 1;
	}

	if(RegCreateKeyEx(HKEY_CLASSES_ROOT, info.name, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp)) {
		Log::Error("ERROR: Could not create name key: %s", info.name);
		return 1;
	}

	if(info.description) {
		if(RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE *) info.description, strlen(info.description) + 1)) {
			Log::Error("ERROR: Could not set description for extension: %s", info.extension);
			return 1;
		}
	}

	if(RegCreateKeyEx(HKEY_CLASSES_ROOT, info.name, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp)) {
		Log::Error("ERROR: Could not create name key: %s", info.name);
		return 1;
	}

	HKEY hDep;
	if(RegCreateKeyEx(hKey, "DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hDep, &dwDisp)) {
		Log::Error("ERROR: Could not create shell key: %s", info.name);
		return 1;
	}

	char path[MAX_PATH];
	GetModuleFileName(NULL, path, MAX_PATH);
	if(RegSetValueEx(hDep, NULL, 0, REG_SZ, (BYTE *) path, strlen(path) + 1)) {
		Log::Error("ERROR: Could not set command for extension: %s", info.extension);
		return 1;
	}

	if(RegCreateKeyEx(hKey, "shell", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp)) {
		Log::Error("ERROR: Could not create shell key: %s", info.name);
		return 1;
	}

	if(RegCreateKeyEx(hKey, "Open", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp)) {
		Log::Error("ERROR: Could not create Open key: %s", info.name);
		return 1;
	}

	HKEY hCmd;
	if(RegCreateKeyEx(hKey, "command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hCmd, &dwDisp)) {
		Log::Error("ERROR: Could not create command key: %s", info.name);
		return 1;
	}

	strcat(path, " \"%1\"");
	if(RegSetValueEx(hCmd, NULL, 0, REG_SZ, (BYTE *) path, strlen(path) + 1)) {
		Log::Error("ERROR: Could not set command for extension: %s", info.extension);
		return 1;
	}

	HKEY hDde;
	if(RegCreateKeyEx(hKey, "ddeexec", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hDde, &dwDisp)) {
		Log::Error("ERROR: Could not create ddeexec key: %s", info.name);
		return 1;
	}

	char* cmd = "%1";
	if(RegSetValueEx(hDde, NULL, 0, REG_SZ, (BYTE *) cmd, strlen(cmd) + 1)) {
		Log::Error("ERROR: Could not set command string for extension: %s", info.extension);
		return 1;
	}

	HKEY hApp;
	if(RegCreateKeyEx(hDde, "application", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hApp, &dwDisp)) {
		Log::Error("ERROR: Could not create ddeexec->application key: %s", info.name);
		return 1;
	}

	char* appname = iniparser_getstr(info.ini, DDE_SERVER_NAME);
	if(appname == NULL) appname = "WinRun4J";
	if(RegSetValueEx(hApp, NULL, 0, REG_SZ, (BYTE *) appname, strlen(appname) + 1)) {
		Log::Error("ERROR: Could not set appname for extension: %s", info.extension);
		return 1;
	}

	HKEY hTopic;
	if(RegCreateKeyEx(hDde, "topic", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hTopic, &dwDisp)) {
		Log::Error("ERROR: Could not create ddeexec->application key: %s", info.name);
		return 1;
	}

	char* topic = iniparser_getstr(info.ini, DDE_TOPIC);
	if(topic == NULL) topic = "system";
	if(RegSetValueEx(hTopic, NULL, 0, REG_SZ, (BYTE *) topic, strlen(topic) + 1)) {
		Log::Error("ERROR: Could not set topic for extension: %s", info.extension);
		return 1;
	}

	return 0;
}
static int wpa_config_write_network(HKEY hk, struct wpa_ssid *ssid, int id)
{
	int i, errors = 0;
	HKEY nhk, netw;
	LONG ret;
	TCHAR name[5];

	ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_CREATE_SUB_KEY, &nhk);
	if (ret != ERROR_SUCCESS) {
		wpa_printf(MSG_DEBUG, "WINREG: Could not open networks key "
			   "for subkey addition: error 0x%x (%d)",
			   (unsigned int) ret, (int) GetLastError());
		return 0;
	}

#ifdef UNICODE
	wsprintf(name, L"%04d", id);
#else /* UNICODE */
	os_snprintf(name, sizeof(name), "%04d", id);
#endif /* UNICODE */
	ret = RegCreateKeyEx(nhk, name, 0, NULL, 0, KEY_WRITE, NULL, &netw,
			     NULL);
	RegCloseKey(nhk);
	if (ret != ERROR_SUCCESS) {
		wpa_printf(MSG_DEBUG, "WINREG: Could not add network key '%s':"
			   " error 0x%x (%d)",
			   name, (unsigned int) ret, (int) GetLastError());
		return -1;
	}

#define STR(t) write_str(netw, #t, ssid)
#define INT(t) write_int(netw, #t, ssid->t, 0)
#define INTe(t) write_int(netw, #t, ssid->eap.t, 0)
#define INT_DEF(t, def) write_int(netw, #t, ssid->t, def)
#define INT_DEFe(t, def) write_int(netw, #t, ssid->eap.t, def)

	STR(ssid);
	INT(scan_ssid);
	write_bssid(netw, ssid);
	write_psk(netw, ssid);
	write_proto(netw, ssid);
	write_key_mgmt(netw, ssid);
	write_pairwise(netw, ssid);
	write_group(netw, ssid);
	write_auth_alg(netw, ssid);
#ifdef IEEE8021X_EAPOL
	write_eap(netw, ssid);
	STR(identity);
	STR(anonymous_identity);
	STR(password);
	STR(ca_cert);
	STR(ca_path);
	STR(client_cert);
	STR(private_key);
	STR(private_key_passwd);
	STR(dh_file);
	STR(subject_match);
	STR(altsubject_match);
	STR(ca_cert2);
	STR(ca_path2);
	STR(client_cert2);
	STR(private_key2);
	STR(private_key2_passwd);
	STR(dh_file2);
	STR(subject_match2);
	STR(altsubject_match2);
	STR(phase1);
	STR(phase2);
	STR(pcsc);
	STR(pin);
	STR(engine_id);
	STR(key_id);
	STR(cert_id);
	STR(ca_cert_id);
	STR(key2_id);
	STR(pin2);
	STR(engine2_id);
	STR(cert2_id);
	STR(ca_cert2_id);
	INTe(engine);
	INTe(engine2);
	INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
#endif /* IEEE8021X_EAPOL */
	for (i = 0; i < 4; i++)
		write_wep_key(netw, i, ssid);
	INT(wep_tx_keyidx);
	INT(priority);
#ifdef IEEE8021X_EAPOL
	INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
	STR(pac_file);
	INT_DEFe(fragment_size, DEFAULT_FRAGMENT_SIZE);
#endif /* IEEE8021X_EAPOL */
	INT(mode);
	INT(proactive_key_caching);
	INT(disabled);
	INT(peerkey);
#ifdef CONFIG_IEEE80211W
	INT(ieee80211w);
#endif /* CONFIG_IEEE80211W */
	STR(id_str);

#undef STR
#undef INT
#undef INT_DEF

	RegCloseKey(netw);

	return errors ? -1 : 0;
}
示例#29
0
Win32Prefs::
Win32Prefs(const char* componentName)
{
    LONG    result;
    char*   prefsKey = NULL;
    int32   keyLength = strlen(kFreeAmpKey) + 
                        strlen(kFreeAmpVersionKey) + 3;

    assert(componentName);

    m_prefsKey = NULL;

    if(componentName)
    {
        keyLength += strlen(componentName);

        prefsKey = new char[keyLength];

        sprintf(prefsKey, "%s\\%s\\%s", kFreeAmpKey, 
                                        kFreeAmpVersionKey, 
                                        componentName);

        result = RegOpenKeyEx(	kMainKey,
							    prefsKey,
							    0, 
							    KEY_WRITE|KEY_READ,
							    &m_prefsKey);

        delete [] prefsKey;

        if(result != ERROR_SUCCESS)
        {
            DWORD disposition;
            HKEY freeampKey;
            HKEY versionKey;

            // create the main key in the windows registry
            result = RegCreateKeyEx(kMainKey,
                                    kFreeAmpKey,
                                    NULL, 
                                    "",
                                    REG_OPTION_NON_VOLATILE,
                                    KEY_ALL_ACCESS,
                                    NULL,
                                    &freeampKey,
                                    &disposition);

            if(result == ERROR_SUCCESS)
            {
                // create the version key under the freeamp key
                result = RegCreateKeyEx(freeampKey,
                                        kFreeAmpVersionKey,
                                        NULL, 
                                        "",
                                        REG_OPTION_NON_VOLATILE,
                                        KEY_ALL_ACCESS,
                                        NULL,
                                        &versionKey,
                                        &disposition);
            }

            if(result == ERROR_SUCCESS)
            {
                // create the component key under the version key
                result = RegCreateKeyEx(versionKey,
                                        componentName,
                                        NULL, 
                                        "",
                                        REG_OPTION_NON_VOLATILE,
                                        KEY_ALL_ACCESS,
                                        NULL,
                                        &m_prefsKey,
                                        &disposition);
            }

            if(result != ERROR_SUCCESS)
            {
                m_prefsKey = NULL;
            }
        }
    }
}
示例#30
0
int CALLBACK WinMain (HINSTANCE hInstance,
                      HINSTANCE hPrevInstance,
                      LPSTR lpCmdLine,
                      int nCmdShow) {
	MSG msg = {0};

	NOTIFYICONDATA nid = {};
	WNDCLASSEX wx = {};
	MENUITEMINFO mi = {};


	::hInstance = hInstance;

	mi.cbSize = sizeof(MENUITEMINFO);
	mi.fMask = MIIM_STRING|MIIM_ID;
	mi.wID = 1;
	mi.dwTypeData = "E&xit";
	 
	hMenu = CreatePopupMenu();
	if (InsertMenuItem(hMenu,0,TRUE,&mi) == 0) {
		MessageBox(NULL,"Failed to create menu!", NULL, NULL);
		return 1;
	}

	mi.wID = 2;
	mi.dwTypeData = "&Hotkey...";
	if (InsertMenuItem(hMenu,0,TRUE,&mi) == 0) {
		MessageBox(NULL,"Failed to create menu!", NULL, NULL);
		return 1;
	}
	
	wx.cbSize = sizeof(WNDCLASSEX);
	wx.lpfnWndProc = WndProc;
	wx.hInstance = hInstance;
	wx.lpszClassName = className;

	

	if (RegisterClassEx(&wx) == NULL) {
		MessageBox(NULL,"Failed to register class!", NULL, NULL);
		return 1;
	}

	mainWindow = CreateWindowEx(0,
	                            className,
	                            "poepulse",
	                            0,0,0,0,0, 
	                            HWND_MESSAGE,
	                            NULL,
	                            hInstance,
	                            NULL);

	if (mainWindow == 0) {
		MessageBox(NULL,"Failed to create window!", NULL, NULL);
		return 1;
	}

	windowMessage = RegisterWindowMessage("poepulse_PulseCursor");
	if (!windowMessage) {
		MessageBox(NULL,"Failed to register custom message!", NULL, NULL);
		return 1;
	}

	theDll = LoadLibrary("poepmod.dll");
	if (!theDll) {
		MessageBox(NULL,"Failed to load poepmod.dll!", NULL, NULL);
		return 1;
	}

	hookProc = GetProcAddress(theDll,"_PoeWndProc@12");
	if (!hookProc) {
		MessageBox(NULL,"Failed to find window hook procedure!", NULL,NULL);
		return 1;
	}

	// query/create the registry for our hotkey information
	if (RegCreateKeyEx(HKEY_CURRENT_USER,
	                   "Software\\Aaron Opfer\\PoE Pulse",
	                   NULL,
	                   NULL,
	                   NULL,
	                   KEY_ALL_ACCESS,
	                   NULL,
	                   &regKey,
	                   NULL) != ERROR_SUCCESS) {
		MessageBox(NULL,"Failed to read/write registry!", NULL,NULL);
		return 1;
	}   

	// retrieve the hotkey values from the registry
	if (RegGetValue(regKey,
	                NULL,
	                "fsModifiers",
	                RRF_RT_REG_DWORD,
	                NULL,
	                &fsModifiers,
	                &sizeofUINT) != ERROR_SUCCESS ||
	    RegGetValue(regKey,
	                NULL,
	                "vKey",
	                RRF_RT_REG_DWORD,
	                NULL,
	                &vKey,
	                &sizeofUINT) != ERROR_SUCCESS) {
		// Couldn't read these registry keys, better set some defaults
		// instead
		fsModifiers = MOD_ALT;
		vKey = VK_SPACE;
		
		if (RegSetValueEx(regKey,
		                  "fsModifiers",
		                  NULL,
		                  REG_DWORD,
		                  (BYTE*)&fsModifiers,
		                  sizeofUINT) != ERROR_SUCCESS ||
		    RegSetValueEx(regKey,
		                  "vKey",
		                  NULL,
		                  REG_DWORD,
		                  (BYTE*)&vKey,
		                  sizeofUINT) != ERROR_SUCCESS) {
			MessageBox(NULL,"Failed to write registry!", NULL,NULL);
			return 1;
		}
	}

	if (RegisterHotKey(mainWindow,
	                   1,
	                   fsModifiers,
	                   vKey) == FALSE) {
		MessageBox(NULL,"Failed to Create Hotkey!", NULL, NULL);
		return 1;
	}

	nid.cbSize = sizeof(NOTIFYICONDATA);
	nid.hWnd = mainWindow;
	nid.uID = 222;
	nid.uVersion = NOTIFYICON_VERSION_4;
	nid.uFlags = NIF_MESSAGE|NIF_TIP|NIF_ICON|NIF_SHOWTIP;
	nid.uCallbackMessage = 0xBEEF;
	strcpy(nid.szTip, "PoE Pulse");
	nid.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	

	if (Shell_NotifyIcon(NIM_ADD,&nid) == FALSE || Shell_NotifyIcon(NIM_SETVERSION,&nid) == FALSE) {
		MessageBox(NULL,"Failed to Create notification bar icon!!", NULL, NULL);
		return 1;
	}
	
	while (GetMessage(&msg,NULL,0,0) != 0) {
		DispatchMessage(&msg);
	}
	ExitProcess(0);
	return 0;
}