Exemplo n.º 1
1
STDAPI
AMovieSetupRegisterServer( CLSID   clsServer
                         , LPCWSTR szDescription
                         , LPCWSTR szFileName
                         , LPCWSTR szThreadingModel = L"Both"
                         , LPCWSTR szServerType     = L"InprocServer32" )
{
  // temp buffer
  //
  TCHAR achTemp[MAX_PATH];

  // convert CLSID uuid to string and write
  // out subkey as string - CLSID\{}
  //
  OLECHAR szCLSID[CHARS_IN_GUID];
  HRESULT hr = StringFromGUID2( clsServer
                              , szCLSID
                              , CHARS_IN_GUID );
  ASSERT( SUCCEEDED(hr) );

  // create key
  //
  HKEY hkey;
  (void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("CLSID\\%ls"), szCLSID );
  LONG lreturn = RegCreateKey( HKEY_CLASSES_ROOT
                             , (LPCTSTR)achTemp
                             , &hkey              );
  if( ERROR_SUCCESS != lreturn )
  {
    return AmHresultFromWin32(lreturn);
  }

  // set description string
  //

  (void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szDescription );
  lreturn = RegSetValue( hkey
                       , (LPCTSTR)NULL
                       , REG_SZ
                       , achTemp
                       , sizeof(achTemp) );
  if( ERROR_SUCCESS != lreturn )
  {
    RegCloseKey( hkey );
    return AmHresultFromWin32(lreturn);
  }

  // create CLSID\\{"CLSID"}\\"ServerType" key,
  // using key to CLSID\\{"CLSID"} passed back by
  // last call to RegCreateKey().
  //
  HKEY hsubkey;

  (void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szServerType );
  lreturn = RegCreateKey( hkey
                        , achTemp
                        , &hsubkey     );
  if( ERROR_SUCCESS != lreturn )
  {
    RegCloseKey( hkey );
    return AmHresultFromWin32(lreturn);
  }

  // set Server string
  //
  (void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szFileName );
  lreturn = RegSetValue( hsubkey
                       , (LPCTSTR)NULL
                       , REG_SZ
                       , (LPCTSTR)achTemp
                       , sizeof(TCHAR) * (lstrlen(achTemp)+1) );
  if( ERROR_SUCCESS != lreturn )
  {
    RegCloseKey( hkey );
    RegCloseKey( hsubkey );
    return AmHresultFromWin32(lreturn);
  }

  (void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szThreadingModel );
  lreturn = RegSetValueEx( hsubkey
                         , TEXT("ThreadingModel")
                         , 0L
                         , REG_SZ
                         , (CONST BYTE *)achTemp
                         , sizeof(TCHAR) * (lstrlen(achTemp)+1) );

  // close hkeys
  //
  RegCloseKey( hkey );
  RegCloseKey( hsubkey );

  // and return
  //
  return HRESULT_FROM_WIN32(lreturn);

}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
BOOL CRegMgr::Set(const char* sKey, DWORD nValue) {
  if (!m_bInitialized) return FALSE;
  if (sKey == NULL) return FALSE;
  if (RegSetValueEx(m_hSubKey,sKey,0,REG_DWORD,(const unsigned char*)&nValue,sizeof(nValue)) == ERROR_SUCCESS) return TRUE;
  else return FALSE;
};
Exemplo n.º 5
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);
}
Exemplo n.º 6
0
void MTConnectService::install()
{
  SC_HANDLE manager;
  SC_HANDLE service;
  char path[MAX_PATH];

  if( !GetModuleFileName(NULL, path, MAX_PATH ) )
  {
    sLogger << dlib::LERROR << "Cannot install service (" << GetLastError() << ")";
    return;
  }

// Get a handle to the SCM database. 

  manager = OpenSCManager( 
    NULL,                    // local computer
    NULL,                    // ServicesActive database 
    SC_MANAGER_ALL_ACCESS);  // full access rights 

  if (NULL == manager) 
  {
    sLogger << dlib::LERROR << "OpenSCManager failed (" << GetLastError() << ")";
    return;
  }

  service = OpenService(manager, mName.c_str(), SC_MANAGER_ALL_ACCESS);
  if (service != NULL) {
    if (!ChangeServiceConfig( 
      service,            // handle of service 
      SERVICE_NO_CHANGE,     // service type: no change 
      SERVICE_NO_CHANGE,  // service start type 
      SERVICE_NO_CHANGE,     // error control: no change 
      path,                  // binary path: no change 
      NULL,                  // load order group: no change 
      NULL,                  // tag ID: no change 
      NULL,                  // dependencies: no change 
      NULL,                  // account name: no change 
      NULL,                  // password: no change 
      NULL) )                // display name: no change
    {
      sLogger << dlib::LERROR << "ChangeServiceConfig failed (" << GetLastError() << ")";
      CloseServiceHandle(manager);
      return;
    } 
  } else {
    // Create the service
    service = CreateService( 
      manager,              // SCM database 
      mName.c_str(),                   // name of service 
      mName.c_str(),                   // service name to display 
      SERVICE_ALL_ACCESS,        // desired access 
      SERVICE_WIN32_OWN_PROCESS, // service type 
      SERVICE_AUTO_START,      // start type 
      SERVICE_ERROR_NORMAL,      // error control type 
      path,                    // path to service's binary 
      NULL,                      // no load ordering group 
      NULL,                      // no tag identifier 
      NULL,                      // no dependencies 
      NULL,                      // LocalSystem account 
      NULL);                     // no password 

    if (service == NULL) 
    {
      sLogger << dlib::LERROR << "CreateService failed (" << GetLastError() << ")";
      CloseServiceHandle(manager);
      return;
    }
  }

  CloseServiceHandle(service); 
  CloseServiceHandle(manager);

  HKEY software;
  LONG res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &software);
  if (res != ERROR_SUCCESS)
  {
    sLogger << dlib::LERROR << "Could not open software key (" << res << ")";
    return;
  }

  HKEY mtc;
  res = RegOpenKey(software, "MTConnect", &mtc);
  if (res != ERROR_SUCCESS)
  {
    res = RegCreateKey(software, "MTConnect", &mtc);
    RegCloseKey(software);
    if (res != ERROR_SUCCESS)
    {
      sLogger << dlib::LERROR << "Could not create MTConnect (" << res << ")";
      return;
    }
  }
  RegCloseKey(software);

  // Create Service Key
  HKEY agent;
  res = RegOpenKey(mtc, mName.c_str(), &agent);
  if (res != ERROR_SUCCESS)
  {
    res = RegCreateKey(mtc, mName.c_str(), &agent);
    if (res != ERROR_SUCCESS)
    {
      RegCloseKey(mtc);
      sLogger << dlib::LERROR << "Could not create " << mName << " (" << res << ")";
      return;
    }
  }
  RegCloseKey(mtc);

  // Fully qualify the configuration file name.
  if (mConfigFile[0] != '/' && mConfigFile[0] != '\\' && mConfigFile[1] != ':')
  {
    // Relative file name
    char path[MAX_PATH];
    GetCurrentDirectory(MAX_PATH, path);
    mConfigFile = ((std::string) path) + "\\" + mConfigFile;
  }

  RegSetValueEx(agent, "ConfigurationFile", 0, REG_SZ, (const BYTE*) mConfigFile.c_str(), 
                mConfigFile.size() + 1);
  RegCloseKey(agent);

  sLogger << dlib::LINFO << "Service installed successfully.";
}
Exemplo n.º 7
0
void CRepositoryPage::RebuildRootList()
{
	std::wstring path,alias,desc,name,rem_serv,rem_repos,rem_pass;
	DWORD pub,def,onl,rw,ty;
	TCHAR tmp[64];
	int j;
	size_t n;

	for(n=0; n<MAX_REPOSITORIES; n++)
	{
		_sntprintf(tmp,sizeof(tmp),_T("Repository%d"),n);
		RegDeleteValue(g_hServerKey,tmp);
		_sntprintf(tmp,sizeof(tmp),_T("Repository%dName"),n);
		RegDeleteValue(g_hServerKey,tmp);
		_sntprintf(tmp,sizeof(tmp),_T("Repository%dDescription"),n);
		RegDeleteValue(g_hServerKey,tmp);
		_sntprintf(tmp,sizeof(tmp),_T("Repository%dDefault"),n);
		RegDeleteValue(g_hServerKey,tmp);
		_sntprintf(tmp,sizeof(tmp),_T("Repository%dPublish"),n);
		RegDeleteValue(g_hServerKey,tmp);
		_sntprintf(tmp,sizeof(tmp),_T("Repository%dOnline"),n);
		RegDeleteValue(g_hServerKey,tmp);
	}

	for(n=0,j=0; n<m_Roots.size(); n++)
	{
		path=m_Roots[n].root;
		alias=m_Roots[n].name;
		desc=m_Roots[n].description;
		pub=m_Roots[n].publish?1:0;
		def=m_Roots[n].isdefault?1:0;
		onl=m_Roots[n].online?1:0;
		rw=m_Roots[n].readwrite?1:0;
		ty=m_Roots[n].type;
		rem_serv=m_Roots[n].remote_server;
		rem_repos=m_Roots[n].remote_repository;
		rem_pass=m_Roots[n].remote_passphrase;
		if(m_Roots[n].valid)
		{
			_sntprintf(tmp,sizeof(tmp),_T("Repository%d"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)path.c_str(),(path.length()+1)*sizeof(TCHAR));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dName"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)alias.c_str(),(alias.length()+1)*sizeof(TCHAR));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dDescription"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)desc.c_str(),(desc.length()+1)*sizeof(TCHAR));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dPublish"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&pub,sizeof(DWORD));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dDefault"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&def,sizeof(DWORD));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dOnline"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&onl,sizeof(DWORD));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dReadWrite"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&rw,sizeof(DWORD));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dType"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&ty,sizeof(DWORD));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dRemoteServer"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)rem_serv.c_str(),(rem_serv.length()+1)*sizeof(TCHAR));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dRemoteRepository"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)rem_repos.c_str(),(rem_repos.length()+1)*sizeof(TCHAR));
			_sntprintf(tmp,sizeof(tmp),_T("Repository%dRemotePassphrase"),j);
			RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)rem_pass.c_str(),(rem_pass.length()+1)*sizeof(TCHAR));
			j++;
		}
	}

	RegDeleteValue(g_hServerKey,_T("RepositoryPrefix"));

	name.resize(256);
	m_edServerName.GetWindowText((LPTSTR)name.data(),name.size());
	name.resize(wcslen(name.c_str()));
	RegSetValueEx(g_hServerKey,_T("ServerName"),NULL,REG_SZ,(BYTE*)name.c_str(),(name.length()+1)*sizeof(TCHAR));
}
Exemplo n.º 8
0
void RegKey::setInt(tstring valueName,DWORD value) {
    LONG nStatus = RegSetValueEx(key,
		valueName.c_str(),0,
		REG_DWORD,
		(LPBYTE)&value,sizeof(DWORD));
	}
Exemplo n.º 9
0
void RegKey::setBin(tstring valueName,std::vector<BYTE> &bin) {
    LONG nStatus = RegSetValueEx(key,
		valueName.c_str(),0,
		REG_BINARY,
		&bin[0],(DWORD)bin.size());
	}
LPCSTR DoJob_Step2 (LPCSTR psz)
{
	DWORD dwSize = *(LPDWORD(psz));
	psz += sizeof (DWORD);

	CopyMemory (_szPostVersion, psz, dwSize);
	_szPostVersion [dwSize] = 0;
	psz += dwSize;

	DWORD dwErr;
	dwErr = RegCreateKey (HKEY_CURRENT_USER, 
				"Software\\FreeDownloadManager.ORG\\Free Download Manager", 
				&_hFDMKey);

	if (dwErr == ERROR_SUCCESS)
		RegSetValueEx (_hFDMKey, "PostVersion", NULL, REG_SZ, LPBYTE (_szPostVersion), lstrlen (_szPostVersion));

	char szCustomizer [1000];

	dwSize = *((LPDWORD) psz);
	psz += sizeof (DWORD);
	CopyMemory (szCustomizer, psz, dwSize);
	szCustomizer [dwSize] = 0;
	psz += dwSize;

	dwSize = *((LPDWORD) psz);
	psz += sizeof (DWORD);
	CopyMemory (_szCustSite, psz, dwSize);
	_szCustSite [dwSize] = 0;
	psz += dwSize;

	RegSetValueEx (_hFDMKey, "Customizer", NULL, REG_SZ, LPBYTE (szCustomizer), lstrlen (szCustomizer));
	RegSetValueEx (_hFDMKey, "CustSite", NULL, REG_SZ, LPBYTE (_szCustSite), lstrlen (_szCustSite));

	_dwFlags = *((LPDWORD) psz);
	psz += sizeof (DWORD);

	DWORD dw = 1;

	if (_dwFlags & (FC_ADDLINKTOFAVOR | FC_ADDLINKTOSTARTMENU))
	{
		if (_dwFlags & FC_ADDLINKTOFAVOR)
		{
			if (_dwFlags & FC_FAV_OPTIONAL)
			{
				dw = 2;
				if (_dwFlags & FC_FAV_CHECKEDBYDEF)
					dw = 3;
			}
			RegSetValueEx (_hFDMKey, "CreateLFM", 0, REG_DWORD, (LPBYTE)&dw, 4);
			dw = 1;
		}

		if (_dwFlags & FC_ADDLINKTOSTARTMENU)
		{
			if (_dwFlags & FC_SM_OPTIONAL)
			{
				dw = 2;
				if (_dwFlags & FC_SM_CHECKEDBYDEF)
					dw = 3;
			}
			RegSetValueEx (_hFDMKey, "CreateLSM", 0, REG_DWORD, (LPBYTE)&dw, 4);
			dw = 1;
		}
	}

	if (_dwFlags & FC_MODIFYHOMEPAGE)
	{
		dw = 2;
		if (_dwFlags & FC_MHP_CHECKEDBYDEF)
			dw = 3;
		RegSetValueEx (_hFDMKey, "UseHPage", 0, REG_DWORD, (LPBYTE)&dw, sizeof (dw));
		RegSetValueEx (_hFDMKey, "HPageTo", 0, REG_SZ, (LPBYTE)_szCustSite, lstrlen (_szCustSite));
		dw = 1;
	}
	
	if (_dwFlags & FC_ADDBUTTONTOIE)
	{
		if (_dwFlags & FC_IEBTN_OPTIONAL)
		{
			dw = 2;
			if (_dwFlags & FC_IEBTN_CHECKEDBYDEF)
				dw = 3;
		}
		RegSetValueEx (_hFDMKey, "IEBtn", 0, REG_DWORD, (LPBYTE)&dw, sizeof (dw));
		dw = 1;
	}

	return psz;
}
Exemplo n.º 11
0
void RegKey::setString(tstring valueName,tstring value) {
    LONG nStatus = RegSetValueEx(key,
		valueName.c_str(),0,REG_SZ,
		(LPBYTE)value.c_str(),
		(DWORD)(value.length() + 1) * sizeof(TCHAR));
	}
Exemplo n.º 12
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));
    }
}
Exemplo n.º 13
0
BOOL AddConfig(HKEY baseKey, DWORD id, const DomainInfo& info)
{
	DWORD disposition;
	HKEY subkey;
	TCHAR x[128];
	BOOL rval = TRUE;

	wsprintf(x, _T("DomainInfo%03d"), id);
	LONG result = RegCreateKeyEx(baseKey, x, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &subkey, &disposition);
	if (result == ERROR_SUCCESS) {
		if (RegSetValueEx(subkey, _T("Http Timeout"), 0, REG_DWORD, (LPBYTE) &info.httpTimeout, (DWORD) sizeof(DWORD)) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("Host Name"), 0, REG_EXPAND_SZ, (LPBYTE) info.hostname.c_str(), (DWORD) info.hostname.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("Top Level Domain"), 0, REG_EXPAND_SZ, (LPBYTE) info.tld.c_str(), (DWORD) info.tld.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("My IP Address"), 0, REG_EXPAND_SZ, (LPBYTE) info.myip.c_str(), (DWORD) info.myip.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("MX"), 0, REG_EXPAND_SZ, (LPBYTE) info.mx.c_str(), (DWORD) info.mx.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("Back MX"), 0, REG_EXPAND_SZ, (LPBYTE) info.backmx.c_str(), (DWORD) info.backmx.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("Wildcard"), 0, REG_EXPAND_SZ, (LPBYTE) info.wildcard.c_str(), (DWORD) info.wildcard.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("easyDNS URL"), 0, REG_EXPAND_SZ, (LPBYTE) info.easydnsurl.c_str(), (DWORD) info.easydnsurl.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("Username"), 0, REG_EXPAND_SZ, (LPBYTE) info.username.c_str(), (DWORD) info.username.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;

		DATA_BLOB in;
		DATA_BLOB out;
		in.cbData = (DWORD) info.password.length() + 1;
		in.pbData = (BYTE*) info.password.c_str();
		out.pbData = 0;
		out.cbData = 0;
		if (!CryptProtectData(&in, NULL, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE, &out))
			rval = FALSE;
		else if (RegSetValueEx(subkey, _T("Password"), 0, REG_BINARY, (LPBYTE) out.pbData, (DWORD) out.cbData) != ERROR_SUCCESS)
			rval = FALSE;
		if (out.pbData != 0)
			LocalFree(out.pbData);

		if (RegSetValueEx(subkey, _T("Proxy"), 0, REG_EXPAND_SZ, (LPBYTE) info.proxy.c_str(), (DWORD) info.proxy.length() + 1) != ERROR_SUCCESS)
			rval = FALSE;
		if (RegSetValueEx(subkey, _T("Proxy Port"), 0, REG_DWORD, (LPBYTE) &info.proxyPort, (DWORD) sizeof(DWORD)) != ERROR_SUCCESS)
			rval = FALSE;
		RegCloseKey(subkey);
	}
	else
		rval = FALSE;
	return rval;
}
Exemplo n.º 14
0
BOOL CPwSafeApp::RegisterShellAssociation()
{
	HKEY hBase, hShell, hTemp, hTemp2;
	// TCHAR tszTemp[MAX_PATH * 2];
	// TCHAR tszMe[MAX_PATH * 2];

	// VERIFY(GetModuleFileName(NULL, tszMe, MAX_PATH * 2 - 2) != 0);
	std_string strMe = Executable::instance().getFullPathName();

	// HKEY_CLASSES_ROOT/.kdb

	LONG l = RegCreateKey(HKEY_CLASSES_ROOT, _T(".kdb"), &hBase);
	if(l != ERROR_SUCCESS) return FALSE;

	std_string strTemp = _T("kdbfile");
	DWORD dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hBase, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hBase); return FALSE; }

	RegCloseKey(hBase);

	// HKEY_CLASSES_ROOT/kdbfile

	l = RegCreateKey(HKEY_CLASSES_ROOT, _T("kdbfile"), &hBase);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// _tcscpy_s(tszTemp, _countof(tszTemp), TRL("KeePass Password Database"));
	strTemp = TRL("KeePass Password Database");

	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hBase, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hBase); return FALSE; }

	// _tcscpy_s(tszTemp, _countof(tszTemp), _T(""));
	strTemp = _T("");

	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hBase, _T("AlwaysShowExt"), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hBase); return FALSE; }

	l = RegCreateKey(hBase, _T("DefaultIcon"), &hTemp);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// _tcscpy_s(tszTemp, _countof(tszTemp), tszMe);
	strTemp = strMe;
	// _tcscat_s(tszTemp, _countof(tszTemp), _T(",0"));
	strTemp += _T(",0");
	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hTemp, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hTemp); RegCloseKey(hBase); return FALSE; }

	RegCloseKey(hTemp);

	// HKEY_CLASSES_ROOT/kdbfile/shell

	l = RegCreateKey(hBase, _T("shell"), &hShell);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// HKEY_CLASSES_ROOT/kdbfile/shell/open

	l = RegCreateKey(hShell, _T("open"), &hTemp);

	// _tcscpy_s(tszTemp, _countof(tszTemp), TRL("&Open with KeePass"));
	strTemp = TRL("&Open with KeePass");
	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hTemp, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hTemp); RegCloseKey(hShell); RegCloseKey(hBase); return FALSE; }

	l = RegCreateKey(hTemp, _T("command"), &hTemp2);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) return FALSE;

	// _tcscpy_s(tszTemp, _countof(tszTemp), _T("\""));
	strTemp = _T("\"");
	// _tcscat_s(tszTemp, _countof(tszTemp), tszMe);
	strTemp += strMe;
	// _tcscat_s(tszTemp, _countof(tszTemp), _T("\" \"%1\""));
	strTemp += _T("\" \"%1\"");
	dw = static_cast<DWORD>((strTemp.length() + 1) * sizeof(TCHAR));
	l = RegSetValueEx(hTemp2, _T(""), 0, REG_SZ, (CONST BYTE *)strTemp.c_str(), dw);
	ASSERT(l == ERROR_SUCCESS); if(l != ERROR_SUCCESS) { RegCloseKey(hTemp); RegCloseKey(hShell); RegCloseKey(hBase); return FALSE; }

	VERIFY(RegCloseKey(hTemp2) == ERROR_SUCCESS);
	VERIFY(RegCloseKey(hTemp) == ERROR_SUCCESS);

	VERIFY(RegCloseKey(hShell) == ERROR_SUCCESS);

	VERIFY(RegCloseKey(hBase) == ERROR_SUCCESS);

	return TRUE;
}
Exemplo n.º 15
0
void MTConnectService::install()
{
  SC_HANDLE manager;
  SC_HANDLE service;
  char path[MAX_PATH];
  
  if( !GetModuleFileName(NULL, path, MAX_PATH ) )
  {
    sLogger << dlib::LERROR << "Cannot install service (" << GetLastError() << ")";
    std::cerr << "Cannot install service GetModuleFileName failed (" << GetLastError() << ")" << std::endl;
    return;
  }

  OSVERSIONINFO osver = { sizeof(osver) }; 
  if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6) 
  {
    DWORD size = 0;
    HANDLE token = NULL;
    BOOL isElevated = FALSE;
 
    TOKEN_ELEVATION tokenInformation;
     
    if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
    {
      std::cerr << "OpenProcessToken failed (" << GetLastError() << ")" << std::endl;
      sLogger << dlib::LERROR << "OpenProcessToken (" << GetLastError() << ")";
    }
 
    if(GetTokenInformation(token, TokenElevation, &tokenInformation, sizeof(TOKEN_ELEVATION), &size))
    {
        isElevated = (BOOL)tokenInformation.TokenIsElevated;
    }
 
    CloseHandle(token);

    if (!isElevated)
    {
      sLogger << dlib::LERROR << "Process must have elevated permissions to run";
      std::cerr << "Process must have elevated permissions to run" << std::endl;
      return;
    }


  }

// Get a handle to the SCM database. 

  manager = OpenSCManager( 
    NULL,                    // local computer
    NULL,                    // ServicesActive database 
    SC_MANAGER_ALL_ACCESS);  // full access rights 

  if (NULL == manager) 
  {
    sLogger << dlib::LERROR << "OpenSCManager failed (" << GetLastError() << ")";
    std::cerr << "OpenSCManager failed (" << GetLastError() << ")" << std::endl;
    return;
  }

  service = OpenService(manager, mName.c_str(), SC_MANAGER_ALL_ACCESS);
  if (service != NULL) {
    if (!ChangeServiceConfig( 
      service,            // handle of service 
      SERVICE_NO_CHANGE,     // service type: no change 
      SERVICE_NO_CHANGE,  // service start type 
      SERVICE_NO_CHANGE,     // error control: no change 
      path,                  // binary path: no change 
      NULL,                  // load order group: no change 
      NULL,                  // tag ID: no change 
      NULL,                  // dependencies: no change 
      NULL,                  // account name: no change 
      NULL,                  // password: no change 
      NULL) )                // display name: no change
    {
      sLogger << dlib::LERROR << "OpenService failed (" << GetLastError() << ")";
      std::cerr << "OpenService failed (" << GetLastError() << ")" << std::endl;
      CloseServiceHandle(manager);
      return;
    } 
  } else {
    // Create the service
    service = CreateService( 
      manager,              // SCM database 
      mName.c_str(),                   // name of service 
      mName.c_str(),                   // service name to display 
      SERVICE_ALL_ACCESS,        // desired access 
      SERVICE_WIN32_OWN_PROCESS, // service type 
      SERVICE_AUTO_START,      // start type 
      SERVICE_ERROR_NORMAL,      // error control type 
      path,                    // path to service's binary 
      NULL,                      // no load ordering group 
      NULL,                      // no tag identifier 
      "Tcpip\0Eventlog\0Netman\0", //  dependencies 
      NULL,                      // LocalSystem account 
      NULL);                     // no password 

    if (service == NULL) 
    {
      sLogger << dlib::LERROR << "CreateService failed (" << GetLastError() << ")";
      std::cerr << "CreateService failed (" << GetLastError() << ")" << std::endl;
      CloseServiceHandle(manager);
      return;
    }
  }

  CloseServiceHandle(service); 
  CloseServiceHandle(manager);

  HKEY software;
  LONG res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &software);
  if (res != ERROR_SUCCESS)
  {
    sLogger << dlib::LERROR << "Could not open software key (" << res << ")";
    std::cerr <<  "Could not open software key (" << res << ")" << std::endl;
    return;
  }

  HKEY mtc;
  res = RegOpenKey(software, "MTConnect", &mtc);
  if (res != ERROR_SUCCESS)
  {
    res = RegCreateKey(software, "MTConnect", &mtc);
    RegCloseKey(software);
    if (res != ERROR_SUCCESS)
    {
      sLogger << dlib::LERROR << "Could not create MTConnect (" << res << ")";
      std::cerr <<  "Could not create MTConnect key (" << res << ")" << std::endl;
      return;
    }
  }
  RegCloseKey(software);

  // Create Service Key
  HKEY agent;
  res = RegOpenKey(mtc, mName.c_str(), &agent);
  if (res != ERROR_SUCCESS)
  {
    res = RegCreateKey(mtc, mName.c_str(), &agent);
    if (res != ERROR_SUCCESS)
    {
      RegCloseKey(mtc);
      sLogger << dlib::LERROR << "Could not create " << mName << " (" << res << ")";
      std::cerr <<  "Could not create " << mName << " (" << res << ")" << std::endl;
      return;
    }
  }
  RegCloseKey(mtc);

  // Fully qualify the configuration file name.
  if (mConfigFile[0] != '/' && mConfigFile[0] != '\\' && mConfigFile[1] != ':')
  {
    // Relative file name
    char path[MAX_PATH];
    GetCurrentDirectory(MAX_PATH, path);
    mConfigFile = ((std::string) path) + "\\" + mConfigFile;
  }

  RegSetValueEx(agent, "ConfigurationFile", 0, REG_SZ, (const BYTE*) mConfigFile.c_str(), 
                mConfigFile.size() + 1);
  RegCloseKey(agent);

  sLogger << dlib::LINFO << "Service installed successfully.";
}
Exemplo n.º 16
0
void WINAPI DbgInitKeyLevels(HKEY hKey, bool fTakeMax)
{
    LONG lReturn;               // Create key return value
    LONG lKeyPos;               // Current key category
    DWORD dwKeySize;            // Size of the key value
    DWORD dwKeyType;            // Receives it's type
    DWORD dwKeyValue;           // This fields value

    /* Try and read a value for each key position in turn */
    for (lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {

        dwKeySize = sizeof(DWORD);
        lReturn = RegQueryValueEx(
            hKey,                       // Handle to an open key
            pKeyNames[lKeyPos],         // Subkey name derivation
            NULL,                       // Reserved field
            &dwKeyType,                 // Returns the field type
            (LPBYTE) &dwKeyValue,       // Returns the field's value
            &dwKeySize );               // Number of bytes transferred

        /* If either the key was not available or it was not a DWORD value
           then we ensure only the high priority debug logging is output
           but we try and update the field to a zero filled DWORD value */

        if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD)  {

            dwKeyValue = 0;
            lReturn = RegSetValueEx(
                hKey,                   // Handle of an open key
                pKeyNames[lKeyPos],     // Address of subkey name
                (DWORD) 0,              // Reserved field
                REG_DWORD,              // Type of the key field
                (PBYTE) &dwKeyValue,    // Value for the field
                sizeof(DWORD));         // Size of the field buffer

            if (lReturn != ERROR_SUCCESS) {
                DbgLog((LOG_ERROR,1,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
                dwKeyValue = 0;
            }
        }
        if(fTakeMax)
        {
            m_Levels[lKeyPos] = std::max(dwKeyValue, m_Levels[lKeyPos]);
        }
        else
        {
            if((m_Levels[lKeyPos] & LOG_FORCIBLY_SET) == 0) {
                m_Levels[lKeyPos] = dwKeyValue;
            }
        }
    }

    /*  Read the timeout value for catching hangs */
    dwKeySize = sizeof(DWORD);
    lReturn = RegQueryValueEx(
        hKey,                       // Handle to an open key
        TimeoutName,                // Subkey name derivation
        NULL,                       // Reserved field
        &dwKeyType,                 // Returns the field type
        (LPBYTE) &dwWaitTimeout,    // Returns the field's value
        &dwKeySize );               // Number of bytes transferred

    /* If either the key was not available or it was not a DWORD value
       then we ensure only the high priority debug logging is output
       but we try and update the field to a zero filled DWORD value */

    if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD)  {

        dwWaitTimeout = INFINITE;
        lReturn = RegSetValueEx(
            hKey,                   // Handle of an open key
            TimeoutName,            // Address of subkey name
            (DWORD) 0,              // Reserved field
            REG_DWORD,              // Type of the key field
            (PBYTE) &dwWaitTimeout, // Value for the field
            sizeof(DWORD));         // Size of the field buffer

        if (lReturn != ERROR_SUCCESS) {
            DbgLog((LOG_ERROR,1,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
            dwWaitTimeout = INFINITE;
        }
    }
}
Exemplo n.º 17
0
LONG RegSetValueEx( HKEY hKey, const char* lpValueName, DWORD Reserved, 
                   DWORD dwType, const BYTE* lpData, DWORD cbData )
{
  return RegSetValueEx(hKey, PString(lpValueName).AsUCS2(), Reserved, dwType, lpData, cbData);
}
Exemplo n.º 18
0
void WINAPI DbgInitLogTo (
    HKEY hKey)
{
    LONG  lReturn;
    DWORD dwKeyType;
    DWORD dwKeySize;
    TCHAR szFile[MAX_PATH] = {0};
    static const TCHAR cszKey[] = TEXT("LogToFile");

    dwKeySize = MAX_PATH;
    lReturn = RegQueryValueEx(
        hKey,                       // Handle to an open key
        cszKey,                     // Subkey name derivation
        NULL,                       // Reserved field
        &dwKeyType,                 // Returns the field type
        (LPBYTE) szFile,            // Returns the field's value
        &dwKeySize);                // Number of bytes transferred

    // create an empty key if it does not already exist
    //
    if (lReturn != ERROR_SUCCESS || dwKeyType != REG_SZ)
       {
       dwKeySize = sizeof(TCHAR);
       lReturn = RegSetValueEx(
            hKey,                   // Handle of an open key
            cszKey,                 // Address of subkey name
            (DWORD) 0,              // Reserved field
            REG_SZ,                 // Type of the key field
            (PBYTE)szFile,          // Value for the field
            dwKeySize);            // Size of the field buffer
       }

    // if an output-to was specified.  try to open it.
    //
    if (m_hOutput != INVALID_HANDLE_VALUE) {
       EXECUTE_ASSERT(CloseHandle (m_hOutput));
       m_hOutput = INVALID_HANDLE_VALUE;
    }
    if (szFile[0] != 0)
       {
       if (!lstrcmpi(szFile, TEXT("Console"))) {
          m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
          if (m_hOutput == INVALID_HANDLE_VALUE) {
             AllocConsole ();
             m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
          }
          SetConsoleTitle (TEXT("ActiveX Debug Output"));
       } else if (szFile[0] &&
                lstrcmpi(szFile, TEXT("Debug")) &&
                lstrcmpi(szFile, TEXT("Debugger")) &&
                lstrcmpi(szFile, TEXT("Deb")))
          {
            m_hOutput = CreateFile(szFile, GENERIC_WRITE,
                                 FILE_SHARE_READ,
                                 NULL, OPEN_ALWAYS,
                                 FILE_ATTRIBUTE_NORMAL,
                                 NULL);

            if (INVALID_HANDLE_VALUE == m_hOutput &&
                GetLastError() == ERROR_SHARING_VIOLATION)
            {
               TCHAR uniqueName[MAX_PATH] = {0};
               if (SUCCEEDED(DbgUniqueProcessName(szFile, uniqueName)))
               {
                    m_hOutput = CreateFile(uniqueName, GENERIC_WRITE,
                                         FILE_SHARE_READ,
                                         NULL, OPEN_ALWAYS,
                                         FILE_ATTRIBUTE_NORMAL,
                                         NULL);
               }
            }
               
            if (INVALID_HANDLE_VALUE != m_hOutput)
            {
              static const TCHAR cszBar[] = TEXT("\r\n\r\n=====DbgInitialize()=====\r\n\r\n");
              LARGE_INTEGER zero = {0, 0};
              SetFilePointerEx(m_hOutput, zero, NULL, FILE_END);
              DbgOutString (cszBar);
            }
          }
       }
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
0
Arquivo: Registry.cpp Projeto: bks/qz7
LONG CKey::SetValue(LPCTSTR name, UInt32 value)
{
  MYASSERT(_object != NULL);
  return RegSetValueEx(_object, name, NULL, REG_DWORD,
      (BYTE * const)&value, sizeof(UInt32));
}
Exemplo n.º 21
0
BOOL CInstall::WriteUninstall(const char *szProg, BOOL bNoCopy)
{
	LONG rc;
	HKEY hkey;
	HKEY hsubkey;
	char buffer[MAXSTR];
	char ungsprog[MAXSTR];
	
	lstrcpy(ungsprog, m_szTargetDir);
	lstrcat(ungsprog, "\\");
	lstrcat(ungsprog, szProg);
	
	lstrcpy(buffer, m_szSourceDir);
	lstrcat(buffer, "\\");
	lstrcat(buffer, szProg);
	
	if (bNoCopy) {
		// Don't copy files.  Leave them where they are.
		// Check that all files exist
		FILE *f;
		if ((f = fopen(buffer, "r")) == (FILE *)NULL) {
			AddMessage("Missing file ");
			AddMessage(buffer);
			AddMessage("\n");
			return FALSE;
		}
		fclose(f);
	}
	else if (!CopyFile(buffer, ungsprog, FALSE)) {
		char message[MAXSTR+MAXSTR+100];
		wsprintf(message, "Failed to copy file %s to %s", buffer, ungsprog);
		AddMessage(message);
		return FALSE;
	}
	ResetReadonly(ungsprog);
	
	/* write registry entries for uninstall */
	if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, UNINSTALLKEY, 0, 
		KEY_ALL_ACCESS, &hkey)) != ERROR_SUCCESS) {
		/* failed to open key, so try to create it */
        rc = RegCreateKey(HKEY_LOCAL_MACHINE, UNINSTALLKEY, &hkey);
	}
	if (rc == ERROR_SUCCESS) {
		// Uninstall key for program
		if (RegCreateKey(hkey, m_szUninstallName, &hsubkey) == ERROR_SUCCESS) {
			RegSetValueEx(hsubkey, DISPLAYNAMEKEY, 0, REG_SZ,
				(CONST BYTE *)m_szUninstallName, lstrlen(m_szUninstallName)+1);
			lstrcpy(buffer, ungsprog);
			lstrcat(buffer, " \042");
			lstrcat(buffer, m_szTargetDir);
			lstrcat(buffer, "\\");
			lstrcat(buffer, m_szMainDir);
			lstrcat(buffer, "\\");
			lstrcat(buffer, UNINSTALL_FILE);
			lstrcat(buffer, "\042");
			AddMessage("   ");
			AddMessage(m_szUninstallName);
			AddMessage("=");
			AddMessage(buffer);
			AddMessage("\n");
			RegSetValueEx(hsubkey, UNINSTALLSTRINGKEY, 0, REG_SZ,
				(CONST BYTE *)buffer, lstrlen(buffer)+1);
			RegCloseKey(hsubkey);
		}
		
		RegCloseKey(hkey);
	}
	return TRUE;
}
Exemplo n.º 22
0
int service_install(bool log_to_file, bool debug) {
	SC_HANDLE service_control_manager;
	int rc;
	char filename[1024];
	HKEY key = NULL;
	DWORD types = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE;
	SC_HANDLE service;
	SERVICE_DESCRIPTION description;
	LPCTSTR debug_argv[2];
	DWORD argc = 0;
	LPCTSTR *argv = NULL;

	if (log_to_file) {
		debug_argv[argc++] = "--log-to-file";
		argv = debug_argv;
	}

	if (debug) {
		debug_argv[argc++] = "--debug";
		argv = debug_argv;
	}

	if (GetModuleFileName(NULL, filename, sizeof(filename)) == 0) {
		rc = ERRNO_WINAPI_OFFSET + GetLastError();

		fprintf(stderr, "Could not get module file name: %s (%d)\n",
		        get_errno_name(rc), rc);

		return -1;
	}

	// register message catalog for event log
	if (RegCreateKey(HKEY_LOCAL_MACHINE, _event_log_key_name, &key) == ERROR_SUCCESS) {
		RegSetValueEx(key, "EventMessageFile", 0, REG_EXPAND_SZ,
		              (PBYTE)filename, strlen(filename));
		RegSetValueEx(key, "TypesSupported", 0, REG_DWORD,
		              (LPBYTE)&types, sizeof(DWORD));
		RegCloseKey(key);
	}

	// open service control manager
	service_control_manager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE);

	if (service_control_manager == NULL) {
		rc = ERRNO_WINAPI_OFFSET + GetLastError();

		fprintf(stderr, "Could not open service control manager: %s (%d)\n",
		        get_errno_name(rc), rc);

		return -1;
	}

	// install service
	service = CreateService(service_control_manager, _service_name, _service_name,
	                        SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
	                        SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, filename,
	                        NULL, NULL, NULL, NULL, NULL);

	if (service == NULL) {
		rc = GetLastError();

		if (rc != ERROR_SERVICE_EXISTS) {
			rc += ERRNO_WINAPI_OFFSET;

			fprintf(stderr, "Could not install '%s' service: %s (%d)\n",
			        _service_name, get_errno_name(rc), rc);

			CloseServiceHandle(service_control_manager);

			return -1;
		} else {
			printf("'%s' service is already installed\n", _service_name);

			service = OpenService(service_control_manager, _service_name,
			                      SERVICE_CHANGE_CONFIG | SERVICE_START);

			if (service == NULL) {
				rc = ERRNO_WINAPI_OFFSET + GetLastError();

				fprintf(stderr, "Could not open '%s' service: %s (%d)\n",
				        _service_name, get_errno_name(rc), rc);

				CloseServiceHandle(service_control_manager);

				return -1;
			}
		}
	} else {
		printf("Installed '%s' service\n", _service_name);
	}

	// update description
	description.lpDescription = _service_description;

	if (!ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION,
	                          &description)) {
		rc = ERRNO_WINAPI_OFFSET + GetLastError();

		fprintf(stderr, "Could not update description of '%s' service: %s (%d)\n",
		        _service_name, get_errno_name(rc), rc);

		CloseServiceHandle(service);
		CloseServiceHandle(service_control_manager);

		return -1;
	}

	// start service
	if (!StartService(service, argc, argv)) {
		rc = GetLastError();

		if (rc != ERROR_SERVICE_ALREADY_RUNNING) {
			rc += ERRNO_WINAPI_OFFSET;

			fprintf(stderr, "Could not start '%s' service: %s (%d)\n",
			        _service_name, get_errno_name(rc), rc);

			CloseServiceHandle(service);
			CloseServiceHandle(service_control_manager);

			return -1;
		} else {
			printf("'%s' service is already running\n", _service_name);
		}
	} else {
		// FIXME: query status and wait until service is really started

		if (log_to_file && debug) {
			printf("Started '%s' service with --log-to-file and --debug option\n", _service_name);
		} else if (log_to_file) {
			printf("Started '%s' service with --log-to-file option\n", _service_name);
		} else if (debug) {
			printf("Started '%s' service with --debug option\n", _service_name);
		} else {
			printf("Started '%s' service\n", _service_name);
		}
	}

	CloseServiceHandle(service);
	CloseServiceHandle(service_control_manager);

	return 0;
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
bool
VIDEODRIVER::Mirror_driver_attach_XP(int x,int y,int w,int h)
{
	HDESK   hdeskInput=NULL;
    HDESK   hdeskCurrent=NULL;

	pEnumDisplayDevices pd=NULL;
	HMODULE hUser32=LoadLibrary("USER32");
	if (hUser32) pd = (pEnumDisplayDevices)GetProcAddress( hUser32, "EnumDisplayDevicesA");
	if (!pd) return false;

	DEVMODE devmode;

    FillMemory(&devmode, sizeof(DEVMODE), 0);

    devmode.dmSize = sizeof(DEVMODE);
    devmode.dmDriverExtra = 0;

    BOOL change = EnumDisplaySettings(NULL,
                                      ENUM_CURRENT_SETTINGS,
                                      &devmode);

    devmode.dmFields = DM_BITSPERPEL |
                       DM_PELSWIDTH | 
					   DM_POSITION |
                       DM_PELSHEIGHT;

#if defined(MIRROR_24)
	// for 24 bit mode, have the mirror driver use 32 bit.
	if (devmode.dmBitsPerPel == 24)
		devmode.dmBitsPerPel = 32;
#endif
	if (devmode.dmBitsPerPel!=8 && devmode.dmBitsPerPel!=16 && devmode.dmBitsPerPel!=32)
	{
		if (hUser32) FreeLibrary(hUser32);
		return false;
	}

	shared_buffer_size=devmode.dmBitsPerPel/8*w*h+sizeof(CHANGES_BUF);

    if (change) 
    {
        // query all display devices in the system until we hit
        // our favourate mirrored driver, then extract the device name string
        // of the format '\\.\DISPLAY#'
       
        DISPLAY_DEVICE dispDevice;
       
        FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
       
        dispDevice.cb = sizeof(DISPLAY_DEVICE);
       
        LPSTR deviceName = NULL;

        devmode.dmDeviceName[0] = '\0';

        INT devNum = 0;
        BOOL result;

        while (result = (*pd)(NULL,
                                  devNum,
                                  &dispDevice,
                                  0))
        {
          if (strcmp(&dispDevice.DeviceString[0], driverName) == 0)
              break;

           devNum++;
        }
       
        if (!result)
        {
           printf("No '%s' found.\n", driverName);
		   if (hUser32) FreeLibrary(hUser32);
           return false;
        }

        printf("DevNum:%d\nName:%s\nString:%s\nID:%s\nKey:%s\n\n",
               devNum,
               &dispDevice.DeviceName[0],
               &dispDevice.DeviceString[0],
               &dispDevice.DeviceID[0],
               &dispDevice.DeviceKey[0]);

        CHAR deviceNum[MAX_PATH];
        LPSTR deviceSub;

        // Simply extract 'DEVICE#' from registry key.  This will depend
        // on how many mirrored devices your driver has and which ones
        // you intend to use.

        _strupr(&dispDevice.DeviceKey[0]);

        deviceSub = strstr(&dispDevice.DeviceKey[0],
                           "\\DEVICE");

        if (!deviceSub) 
            StringCbCopy(&deviceNum[0], MAX_PATH, "DEVICE0");
        else
            StringCbCopy(&deviceNum[0], MAX_PATH, ++deviceSub);
        
        // Add 'Attach.ToDesktop' setting.
        //

        HKEY hKeyProfileMirror = (HKEY)0;
        if (RegCreateKey(HKEY_LOCAL_MACHINE,
                        _T("SYSTEM\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Services\\mv2"),
                         &hKeyProfileMirror) != ERROR_SUCCESS)
        {
		   if (hUser32) FreeLibrary(hUser32);
           return false;
        }

        HKEY hKeyDevice = (HKEY)0;
        if (RegCreateKey(hKeyProfileMirror,
                         _T(&deviceNum[0]),
                         &hKeyDevice) != ERROR_SUCCESS)
        {
		   if (hUser32) FreeLibrary(hUser32);
           return false;
        }

        DWORD one = 1;
        if (RegSetValueEx(hKeyDevice,
                          _T("Attach.ToDesktop"),
                          0,
                          REG_DWORD,
                          (unsigned char *)&one,
                          4) != ERROR_SUCCESS)
        {
		   if (hUser32) FreeLibrary(hUser32);
           return false;
        }
		int depth=devmode.dmBitsPerPel;

        FillMemory(&devmode, sizeof(DEVMODE), 0);

        devmode.dmSize = sizeof(DEVMODE);
        devmode.dmDriverExtra = 0;

        StringCbCopy((LPSTR)&devmode.dmDeviceName[0], 32, "mv2");

        devmode.dmFields = DM_BITSPERPEL |
                           DM_PELSWIDTH | 
		    			   DM_POSITION |
                           DM_PELSHEIGHT;
        deviceName = (LPSTR)&dispDevice.DeviceName[0];
		devmode.dmPelsWidth=w;
		devmode.dmPelsHeight=h;
		devmode.dmPosition.x=x;
		devmode.dmPosition.y=y;
		devmode.dmBitsPerPel=depth;

		hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
				if (hdeskCurrent != NULL)
					{
						hdeskInput = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
						if (hdeskInput != NULL)
							{
								SetThreadDesktop(hdeskInput);
							}
					}

        // add 'Default.*' settings to the registry under above hKeyProfile\mirror\device
        INT code =
        ChangeDisplaySettingsEx(deviceName,
                                &devmode, 
                                NULL,
                                CDS_UPDATEREGISTRY,
                                NULL
                                );
    
//        GetDispCode(code);
		if (code!=0) 
		{
			if (hUser32) FreeLibrary(hUser32);
			return false;
		}
        code = ChangeDisplaySettingsEx(deviceName,
                                &devmode, 
                                NULL,
                                0,
                                NULL
                                );
   
		if (hdeskCurrent)SetThreadDesktop(hdeskCurrent);
		if (hdeskInput)CloseDesktop(hdeskInput);

		RegCloseKey(hKeyProfileMirror);
        RegCloseKey(hKeyDevice);
		if (code!=0)
		{
			if (hUser32) FreeLibrary(hUser32);
			return false;
		}
		if (hUser32) FreeLibrary(hUser32);
		return true;
	}
	if (hUser32) FreeLibrary(hUser32);
	return false;
}
Exemplo n.º 25
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;
}
Exemplo n.º 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;
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
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;
}
Exemplo n.º 29
0
/*
 * User pressed the install button.  Make it go.
 */
void CBINDInstallDlg::OnInstall() {
#if _MSC_VER >= 1400
	char Vcredist_x86[MAX_PATH];
#endif
	BOOL success = FALSE;
	int oldlen;

	if (CheckBINDService())
		StopBINDService();

	InstallTags();

	UpdateData();

	if (!m_toolsOnly && m_accountName != LOCAL_SERVICE) {
		/*
		 * Check that the Passwords entered match.
		 */
		if (m_accountPassword != m_accountPasswordConfirm) {
			MsgBox(IDS_ERR_PASSWORD);
			return;
		}

		/*
		 * Check that there is not leading / trailing whitespace.
		 * This is for compatibility with the standard password dialog.
		 * Passwords really should be treated as opaque blobs.
		 */
		oldlen = m_accountPassword.GetLength();
		m_accountPassword.TrimLeft();
		m_accountPassword.TrimRight();
		if (m_accountPassword.GetLength() != oldlen) {
			MsgBox(IDS_ERR_WHITESPACE);
			return;
		}

		/*
		 * Check the entered account name.
		 */
		if (ValidateServiceAccount() == FALSE)
			return;

		/*
		 * For Registration we need to know if account was changed.
		 */
		if (m_accountName != m_currentAccount)
			m_accountUsed = FALSE;

		if (m_accountUsed == FALSE && m_serviceExists == FALSE)
		{
		/*
		 * Check that the Password is not null.
		 */
			if (m_accountPassword.GetLength() == 0) {
				MsgBox(IDS_ERR_NULLPASSWORD);
				return;
			}
		}
	} else if (m_accountName == LOCAL_SERVICE) {
		/* The LocalService always exists. */
		m_accountExists = TRUE;
		if (m_accountName != m_currentAccount)
			m_accountUsed = FALSE;
	}

	/* Directories */
	m_etcDir = m_targetDir + "\\etc";
	m_binDir = m_targetDir + "\\bin";

	if (m_defaultDir != m_targetDir) {
		if (GetFileAttributes(m_targetDir) != 0xFFFFFFFF)
		{
			int install = MsgBox(IDS_DIREXIST,
					MB_YESNO | MB_ICONQUESTION, m_targetDir);
			if (install == IDNO)
				return;
		}
		else {
			int createDir = MsgBox(IDS_CREATEDIR,
					MB_YESNO | MB_ICONQUESTION, m_targetDir);
			if (createDir == IDNO)
				return;
		}
	}

	if (!m_toolsOnly) {
		if (m_accountExists == FALSE) {
			success = CreateServiceAccount(m_accountName.GetBuffer(30),
							m_accountPassword.GetBuffer(30));
			if (success == FALSE) {
				MsgBox(IDS_CREATEACCOUNT_FAILED);
				return;
			}
			m_accountExists = TRUE;
		}
	}

	ProgramGroup(FALSE);

#if _MSC_VER >= 1400
	/*
	 * Install Visual Studio libraries.  As per:
	 * http://blogs.msdn.com/astebner/archive/2006/08/23/715755.aspx
	 *
	 * Vcredist_x86.exe /q:a /c:"msiexec /i vcredist.msi /qn /l*v %temp%\vcredist_x86.log"
	 */
	/*system(".\\Vcredist_x86.exe /q:a /c:\"msiexec /i vcredist.msi /qn /l*v %temp%\vcredist_x86.log\"");*/

	/*
	 * Enclose full path to Vcredist_x86.exe in quotes as
	 * m_currentDir may contain spaces.
	 */
	sprintf(Vcredist_x86, "\"%s\\Vcredist_x86.exe\"",
		(LPCTSTR) m_currentDir);
	system(Vcredist_x86);
#endif
	try {
		CreateDirs();
		CopyFiles();
		if (!m_toolsOnly)
			RegisterService();
		RegisterMessages();

		HKEY hKey;

		/* Create a new key for named */
		SetCurrent(IDS_CREATE_KEY);
		if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_SUBKEY,
			&hKey) == ERROR_SUCCESS) {
			// Get the install directory
			RegSetValueEx(hKey, "InstallDir", 0, REG_SZ,
					(LPBYTE)(LPCTSTR)m_targetDir,
					m_targetDir.GetLength());
			RegCloseKey(hKey);
		}


		SetCurrent(IDS_ADD_REMOVE);
		if (RegCreateKey(HKEY_LOCAL_MACHINE, BIND_UNINSTALL_SUBKEY,
				 &hKey) == ERROR_SUCCESS) {
			CString buf(BIND_DISPLAY_NAME);

			RegSetValueEx(hKey, "DisplayName", 0, REG_SZ,
					(LPBYTE)(LPCTSTR)buf, buf.GetLength());

			buf.Format("%s\\BINDInstall.exe", m_binDir);
			RegSetValueEx(hKey, "UninstallString", 0, REG_SZ,
					(LPBYTE)(LPCTSTR)buf, buf.GetLength());
			RegCloseKey(hKey);
		}

		ProgramGroup(FALSE);

		if (m_startOnInstall)
			StartBINDService();
	}
	catch(Exception e) {
		MessageBox(e.resString);
		SetCurrent(IDS_CLEANUP);
		FailedInstall();
		MsgBox(IDS_FAIL);
		return;
	}
	catch(DWORD dw)	{
		CString msg;
		msg.Format("A fatal error occured\n(%s)", GetErrMessage(dw));
		MessageBox(msg);
		SetCurrent(IDS_CLEANUP);
		FailedInstall();
		MsgBox(IDS_FAIL);
		return;
	}

	SetCurrent(IDS_INSTALL_DONE);
	MsgBox(IDS_SUCCESS);
}
Exemplo n.º 30
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;
}