Пример #1
0
/**
 * Determines if the registry is disabled via the service or not.
 * 
 * @return true if prefetch is disabled
 *         false if prefetch is not disabled or an error occurred.
*/
bool IsPrefetchDisabledViaService()
{
  // We don't need to return false when we don't have MOZ_MAINTENANCE_SERVICE
  // defined.  The reason is because another product installed that has it
  // defined may have cleared our prefetch for us.  There is no known way
  // to figure out which prefetch files are associated with which apps
  // because of the prefetch hash.  So we disable all of them that start
  // with FIREFOX.
  HKEY baseKey;
  LONG retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 
                               L"SOFTWARE\\Mozilla\\MaintenanceService", 0,
                               KEY_READ | KEY_WOW64_64KEY, &baseKey);
  if (retCode != ERROR_SUCCESS) {
    return false;
  }
  DWORD disabledValue = 0;
  DWORD disabledValueSize = sizeof(DWORD);
  RegQueryValueExW(baseKey, L"FFPrefetchDisabled", 0, NULL,
                   reinterpret_cast<LPBYTE>(&disabledValue),
                   &disabledValueSize);
  RegCloseKey(baseKey);
  return disabledValue == 1;
}
Пример #2
0
static BOOL 
GetLaunchOnStartup()
{
	
    WCHAR regPath[MAX_PATH], exePath[MAX_PATH];	
    BOOL result = FALSE;
    HKEY regkey;

    if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, &regkey) == ERROR_SUCCESS) {

        if (GetRegistryValue(regkey, L"OpenVPN-GUI", regPath, MAX_PATH) &&
            GetModuleFileNameW(NULL, exePath, MAX_PATH)) {
            if (_wcsicmp(regPath, exePath) == 0)
                result = TRUE;
        }

        RegCloseKey(regkey);

    }
	
    return result;

}
Пример #3
0
BOOL IsUacSupported()
{
    HKEY hkey;
    DWORD value = 1, size = sizeof (DWORD);

    if (!IsVistaOrLater())
    {
        return FALSE;
    }

    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                      L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS)
    {
        if (RegQueryValueExW(hkey, L"EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
        {
            value = 1;
        }

        RegCloseKey (hkey);
    }

    return value != 0;
}
Пример #4
0
  /*
  * Retrieve the app model id of the firefox metro browser.
  *
  * @aPathBuffer Buffer to fill
  * @aCharLength Length of buffer to fill in characters
  */
  bool GetDefaultBrowserAppModelID(WCHAR* aIDBuffer, long aCharLength)
  {
    if (!aIDBuffer || aCharLength <= 0)
      return false;

    memset(aIDBuffer, 0, (sizeof(WCHAR)*aCharLength));
    static const WCHAR* kDefaultMetroBrowserIDPathKey = L"FirefoxURL";

    HKEY key;
    if (RegOpenKeyExW(HKEY_CLASSES_ROOT, kDefaultMetroBrowserIDPathKey,
                      0, KEY_READ, &key) != ERROR_SUCCESS) {
      return false;
    }
    DWORD len = aCharLength * sizeof(WCHAR);
    memset(aIDBuffer, 0, len);
    if (RegQueryValueExW(key, L"AppUserModelID", nullptr, nullptr,
                         (LPBYTE)aIDBuffer, &len) != ERROR_SUCCESS || !len) {
      RegCloseKey(key);
      return false;
    }
    RegCloseKey(key);
    return true;
  }
Пример #5
0
bool WinRegistryKey::exists(const std::string& name)
{
	bool exists = false;
	HKEY hKey;
#if defined(POCO_WIN32_UTF8)
	std::wstring usubKey;
	Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
	if (RegOpenKeyExW(_hRootKey, usubKey.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
	{
		std::wstring uname;
		Poco::UnicodeConverter::toUTF16(name, uname);
		exists = RegQueryValueExW(hKey, uname.c_str(), NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
		RegCloseKey(hKey);
	}
#else
	if (RegOpenKeyEx(_hRootKey, _subKey.c_str(), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		exists = RegQueryValueEx(hKey, name.c_str(), NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
		RegCloseKey(hKey);
	}
#endif
	return exists;
}
Пример #6
0
void CDlgFileAssoc::ExtUnassign(LPWSTR extName) {

	HKEY hKey;
	DWORD len = 100;
	wchar_t buf[100];

	if (RegOpenKeyExW(HKEY_CLASSES_ROOT, extName, 0, 0, &hKey) == ERROR_SUCCESS) {

		if (RegQueryValueExW(hKey, L"Nitrogen backup", NULL, NULL, (BYTE*)buf, &len) == ERROR_SUCCESS) {	

			RegSetValueExW(hKey, NULL, 0, REG_SZ, (BYTE*)buf, len);
			RegDeleteValueW(hKey, L"Nitrogen backup");
	
		} else {

			RegDeleteValueW(hKey, NULL);
	
		}
	
		RegCloseKey(hKey);
	}

}
Пример #7
0
StdCopyStrBuf GetRegistryString(const char *szSubKey, const char *szValueName)
{
	HKEY ckey;

	// Open the key
	if (RegOpenKeyExW(HKEY_CURRENT_USER, GetWideChar(szSubKey), 0, KEY_READ, &ckey)!=ERROR_SUCCESS)
		return StdCopyStrBuf();

	// Get the value
	DWORD dwValSize = 128;
	BYTE *sValue = new BYTE[dwValSize];
	while(true)
	{
		DWORD valtype;
		switch(RegQueryValueExW(ckey, GetWideChar(szValueName), NULL, &valtype,
			sValue, &dwValSize))
		{
		case ERROR_SUCCESS:
			RegCloseKey(ckey);
			if (valtype == REG_SZ)
			{
				StdCopyStrBuf nrv(reinterpret_cast<wchar_t*>(sValue));
				delete[] sValue;
				return nrv;
			} else {
		default:
				delete[] sValue;
				return StdCopyStrBuf();
			}
			break;
		case ERROR_MORE_DATA:
			delete[] sValue;
			sValue = new BYTE[dwValSize];
			break;
		}
	}
}
Пример #8
0
// Retrieve the commandline for the default mail client. It contains a
// placeholder %1 for the URL. The default key used below is the
// command line for the mailto: shell command.
static inline QString mailCommand()
{
    enum { BufferSize = sizeof(wchar_t) * MAX_PATH };

    const wchar_t mailUserKey[] = L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice";

    wchar_t command[MAX_PATH] = {0};
    // Check if user has set preference, otherwise use default.
    HKEY handle;
    QString keyName;
    if (!RegOpenKeyEx(HKEY_CURRENT_USER, mailUserKey, 0, KEY_READ, &handle)) {
        DWORD bufferSize = BufferSize;
        if (!RegQueryValueEx(handle, L"Progid", 0, 0, reinterpret_cast<unsigned char*>(command), &bufferSize))
            keyName = QString::fromWCharArray(command);
        RegCloseKey(handle);
    }
    if (keyName.isEmpty())
        keyName = QStringLiteral("mailto");
    keyName += QStringLiteral("\\Shell\\Open\\Command");
    if (debug)
        qDebug() << __FUNCTION__ << "keyName=" << keyName;
    command[0] = 0;
    if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, (const wchar_t*)keyName.utf16(), 0, KEY_READ, &handle)) {
        DWORD bufferSize = BufferSize;
        RegQueryValueEx(handle, L"", 0, 0, reinterpret_cast<unsigned char*>(command), &bufferSize);
        RegCloseKey(handle);
    }
    if (!command[0])
        return QString();
#ifndef Q_OS_WINCE
    wchar_t expandedCommand[MAX_PATH] = {0};
    return ExpandEnvironmentStrings(command, expandedCommand, MAX_PATH) ?
           QString::fromWCharArray(expandedCommand) : QString::fromWCharArray(command);
#else
    return QString();
#endif
}
Пример #9
0
void RegCopyData(HKEY hKeyIn, HKEY hKeyOut) {

	int index = 0;
	DWORD lenName = 200;
	DWORD lenData = 300;
	wchar_t bufName[200];
	BYTE bufData[300];
	DWORD typ;

	while (RegEnumValueW(hKeyIn, index, (LPWSTR)bufName, &lenName, NULL, &typ, (LPBYTE)bufData, &lenData) == ERROR_SUCCESS) {
		
		RegSetValueExW(hKeyOut, bufName, 0, typ, bufData, lenData);

		lenName = 200;
		lenData = 200;
		index++;
	}

	index = 0;
	while (RegEnumKeyExW(hKeyIn, index, (LPWSTR)bufName, &lenName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {

		HKEY hNewKeyIn;
		if (RegOpenKeyExW(hKeyIn, bufName, 0, 0, &hNewKeyIn) == ERROR_SUCCESS) {
			HKEY hNewKeyOut;
			if (RegCreateKeyEx(hKeyOut, bufName, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hNewKeyOut, NULL) == ERROR_SUCCESS) {
				RegCopyData(hNewKeyIn, hNewKeyOut);
				RegCloseKey(hNewKeyOut);
			}
			RegCloseKey(hNewKeyIn);
		}
		lenName = 200;
		index++;
	
	}


}
Пример #10
0
static VOID
ViewDlg_RestoreDefaults(HWND hwndDlg)
{
    HWND hwndTreeView = GetDlgItem(hwndDlg, IDC_VIEW_TREEVIEW);

    for (INT i = 0; i < s_ViewTreeEntryCount; ++i)
    {
        // ignore if the type is group
        VIEWTREE_ENTRY *pEntry = &s_ViewTreeEntries[i];
        if (pEntry->dwType == AETYPE_GROUP)
            continue;

        // set default value on registry
        HKEY hKey;
        if (RegOpenKeyExW(HKEY(pEntry->hkeyRoot), pEntry->szRegPath,
                          0, KEY_WRITE, &hKey) != ERROR_SUCCESS)
        {
            continue;
        }
        RegSetValueExW(hKey, pEntry->szValueName, 0, REG_DWORD,
                       LPBYTE(&pEntry->dwDefaultValue), sizeof(DWORD));
        RegCloseKey(hKey);

        // update check status
        pEntry->bChecked = (pEntry->dwCheckedValue == pEntry->dwDefaultValue);

        // update the image
        TV_ITEM Item;
        ZeroMemory(&Item, sizeof(Item));
        Item.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
        Item.hItem = pEntry->hItem;
        Item.iImage = Item.iSelectedImage = ViewTree_GetImage(pEntry);
        TreeView_SetItem(hwndTreeView, &Item);
    }

    PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
Пример #11
0
/**
 * Determines if the the system's elevation type allows
 * unprmopted elevation.  This may not 100% reflect reality since
 * a reboot is necessary to change the UAC level.
 *
 * @param isUnpromptedElevation Out parameter which specifies if unprompted
 *                              elevation is allowed.
 * @return TRUE if the value was obtained successfully.
*/
BOOL
IsUnpromptedElevation(BOOL &isUnpromptedElevation)
{
  LPCWSTR UACBaseRegKey =
    L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
  HKEY baseKey;
  LONG retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                               UACBaseRegKey, 0,
                               KEY_READ, &baseKey);
  if (retCode != ERROR_SUCCESS) {
    return FALSE;
  }

  DWORD enabled, consent, secureDesktop;
  BOOL success = GetDWORDValue(baseKey, L"EnableLUA", enabled);
  success = success &&
            GetDWORDValue(baseKey, L"ConsentPromptBehaviorAdmin", consent);
  success = success &&
            GetDWORDValue(baseKey, L"PromptOnSecureDesktop", secureDesktop);
  isUnpromptedElevation = enabled && !consent && !secureDesktop;

  RegCloseKey(baseKey);
  return success;
}
Пример #12
0
SEXP readRegistry(SEXP call, SEXP op, SEXP args, SEXP env)
{
    SEXP ans;
    HKEY hive, hkey;
    LONG res;
    const wchar_t *key;
    int maxdepth, view;
    REGSAM acc = KEY_READ;

    args = CDR(args);
    if(!isString(CAR(args)) || LENGTH(CAR(args)) != 1)
	error(_("invalid '%s' value"),  "key");
    key = filenameToWchar(STRING_ELT(CAR(args), 0), 0);
    if(!isString(CADR(args)) || LENGTH(CADR(args)) != 1)
	error(_("invalid '%s' value"),  "hive");
    maxdepth = asInteger(CADDR(args));
    if(maxdepth == NA_INTEGER || maxdepth < 1)
	error(_("invalid '%s' value"),  "maxdepth");
    hive = find_hive(CHAR(STRING_ELT(CADR(args), 0)));
    view = asInteger(CADDDR(args));
    /* Or KEY_READ with KEY_WOW64_64KEY or KEY_WOW64_32KEY to
       explicitly access the 64- or 32- bit registry view.  See
       http://msdn.microsoft.com/en-us/library/aa384129(VS.85).aspx
    */
    if(view == 2) acc |= KEY_WOW64_32KEY;
    else if(view == 3) acc |= KEY_WOW64_64KEY;

    res = RegOpenKeyExW(hive, key, 0, acc, &hkey);
    if (res == ERROR_FILE_NOT_FOUND)
	error(_("Registry key '%ls' not found"), key);
    if (res != ERROR_SUCCESS)
	error("RegOpenKeyEx error code %d: '%s'", (int) res, formatError(res));
    ans = readRegistryKey(hkey, maxdepth, view);
    RegCloseKey(hkey);
    return ans;
}
Пример #13
0
static
BOOL
GetGinaPath(
    OUT LPWSTR Path,
    IN DWORD Len)
{
    LONG Status;
    DWORD Type, Size;
    HKEY hKey;

    Status = RegOpenKeyExW(
        HKEY_LOCAL_MACHINE,
        L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
        0,
        KEY_QUERY_VALUE,
        &hKey);
    if (Status != ERROR_SUCCESS)
    {
        /* Default value */
        wcsncpy(Path, L"msgina.dll", Len);
        return TRUE;
    }

    Size = Len * sizeof(WCHAR);
    Status = RegQueryValueExW(
        hKey,
        L"GinaDLL",
        NULL,
        &Type,
        (LPBYTE)Path,
        &Size);
    if (Status != ERROR_SUCCESS || Type != REG_SZ || Size == 0)
        wcsncpy(Path, L"msgina.dll", Len);
    RegCloseKey(hKey);
    return TRUE;
}
Пример #14
0
int win32_find_msysgit_in_registry(struct win32_path *root, const HKEY hieve, const wchar_t *key)
{
	HKEY hKey;
	DWORD dwType = REG_SZ;
	DWORD dwSize = MAX_PATH;

	assert(root);

	root->len = 0;
	if (RegOpenKeyExW(hieve, key, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
		if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType, (LPBYTE)&root->path, &dwSize) == ERROR_SUCCESS) {
			// InstallLocation points to the root of the msysgit directory
			if (dwSize + 4 > MAX_PATH) {// 4 = wcslen(L"etc\\")
				giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory - path too long");
				return -1;
			}
			wcscat(root->path, L"etc\\");
			root->len = (DWORD)wcslen(root->path) + 1;
		}
	}
	RegCloseKey(hKey);

	return root->len ? 0 : GIT_ENOTFOUND;
}
Пример #15
0
BOOL CVSSMgr::GetDefaultDatabase(LPWSTR FilePathBuf,IN OUT PULONG BufLen)
{
	BOOL	bRet = FALSE;
	HKEY	hKey;
	DWORD	dwType;
	DWORD   dwValue = (*BufLen) * sizeof(WCHAR);

	LONG hr = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
						L"SOFTWARE\\Microsoft\\SourceSafe",
						0,
						KEY_READ,
						&hKey);
	if(SUCCEEDED(hr))
	{
		hr = RegQueryValueExW(hKey,L"Current Database",0,&dwType,(LPBYTE)FilePathBuf,&dwValue);
		if(SUCCEEDED(hr))
		{
			*BufLen = dwValue/sizeof(WCHAR);
			bRet = TRUE;
		}
		RegCloseKey(hKey);
	}
	return bRet;
}
Пример #16
0
static gchar *get_7z_path_entry(HKEY root_hkey, LPWSTR name)
{
	HKEY hkey;
	DWORD size, type;
	LPWSTR wpath;
	gchar *path;

	debug_print("get_7z_path_entry: read %s/Software/7-Zip/%ls\n", root_hkey == HKEY_CURRENT_USER ? "HKCU" : "HKLM", name);

	if (RegOpenKeyExW(root_hkey, L"Software\\7-Zip", 0, KEY_READ, &hkey) != ERROR_SUCCESS) {
		return NULL;
	}

	if (RegQueryValueExW(hkey, name, 0, &type, 0, &size) != ERROR_SUCCESS) {
		RegCloseKey(hkey);
		return NULL;
	}
	if (type != REG_SZ) {
		RegCloseKey(hkey);
		return NULL;
	}
	++size;
	wpath = g_malloc(size);
	if (RegQueryValueExW(hkey, name, 0, &type, (LPBYTE)wpath, &size) != ERROR_SUCCESS) {
		RegCloseKey(hkey);
		return NULL;
	}
	RegCloseKey(hkey);

	path = g_utf16_to_utf8(wpath, -1, NULL, NULL, NULL);
	g_free(wpath);

	debug_print("get_7z_path_entry: %s\n", path);

	return path;
}
Пример #17
0
static LONG installBrandingValue(MSIHANDLE hModule,
                                 const WCHAR *pwszFileName,
                                 const WCHAR *pwszSection,
                                 const WCHAR *pwszValue)
{
    LONG rc;
    WCHAR wszValue[_MAX_PATH];
    if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL,
                                 wszValue, sizeof(wszValue), pwszFileName) > 0)
    {
        HKEY hkBranding;
        WCHAR wszKey[_MAX_PATH];

        if (wcsicmp(L"General", pwszSection) != 0)
            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pwszSection);
        else
            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);

        rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszKey, 0, KEY_WRITE, &hkBranding);
        if (rc == ERROR_SUCCESS)
        {
            rc = RegSetValueExW(hkBranding,
                                pwszValue,
                                NULL,
                                REG_SZ,
                                (BYTE *)wszValue,
                                (DWORD)wcslen(wszValue));
            if (rc != ERROR_SUCCESS)
                logStringW(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc);
            RegCloseKey (hkBranding);
        }
    }
    else
        rc = ERROR_NOT_FOUND;
    return rc;
}
Пример #18
0
/***********************************************************************
 *		unregister_coclasses
 */
static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
{
    LONG res = ERROR_SUCCESS;
    HKEY coclass_key;

    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
			KEY_READ | KEY_WRITE, &coclass_key);
    if (res == ERROR_FILE_NOT_FOUND) return S_OK;
    if (res != ERROR_SUCCESS) goto error_return;

    for (; res == ERROR_SUCCESS && list->clsid; ++list) {
	WCHAR buf[39];

	StringFromGUID2(list->clsid, buf, 39);
	res = RegDeleteTreeW(coclass_key, buf);
	if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
	if (res != ERROR_SUCCESS) goto error_close_coclass_key;

	if (list->progid) {
	    res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
	    if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
	    if (res != ERROR_SUCCESS) goto error_close_coclass_key;
	}

	if (list->viprogid) {
	    res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
	    if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
	    if (res != ERROR_SUCCESS) goto error_close_coclass_key;
	}
    }

error_close_coclass_key:
    RegCloseKey(coclass_key);
error_return:
    return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
}
Пример #19
0
static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
    LPENUMGUID iface,
    IEnumGUID **ppenum)
{
    CATID_IEnumGUIDImpl *This = (CATID_IEnumGUIDImpl *)iface;
    CATID_IEnumGUIDImpl *new_this;

    TRACE("\n");

    if (ppenum == NULL) return E_POINTER;

    new_this = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CATID_IEnumGUIDImpl));
    if (new_this == NULL) return E_OUTOFMEMORY;

    new_this->lpVtbl = This->lpVtbl;
    new_this->ref = 1;
    lstrcpyW(new_this->keyname, This->keyname);
    /* FIXME: could we more efficiently use DuplicateHandle? */
    RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
    new_this->next_index = This->next_index;

    *ppenum = (LPENUMGUID)new_this;
    return S_OK;
}
Пример #20
0
 static lstring contents(const string& name) {
   lstring part = name.split("/"), result;
   HKEY handle, rootKey = root(part.take(0));
   part.remove();
   string path = part.merge("\\");
   if(RegOpenKeyExW(rootKey, utf16_t(path), 0, NWR_FLAGS | KEY_READ, &handle) == ERROR_SUCCESS) {
     DWORD folders, nodes;
     RegQueryInfoKey(handle, nullptr, nullptr, nullptr, &folders, nullptr, nullptr, &nodes, nullptr, nullptr, nullptr, nullptr);
     for(unsigned n = 0; n < folders; n++) {
       wchar_t name[NWR_SIZE] = L"";
       DWORD size = NWR_SIZE * sizeof(wchar_t);
       RegEnumKeyEx(handle, n, (wchar_t*)&name, &size, nullptr, nullptr, nullptr, nullptr);
       result.append({(const char*)utf8_t(name), "/"});
     }
     for(unsigned n = 0; n < nodes; n++) {
       wchar_t name[NWR_SIZE] = L"";
       DWORD size = NWR_SIZE * sizeof(wchar_t);
       RegEnumValueW(handle, n, (wchar_t*)&name, &size, nullptr, nullptr, nullptr, nullptr);
       result.append((const char*)utf8_t(name));
     }
     RegCloseKey(handle);
   }
   return result;
 }
Пример #21
0
void searchCurrentJavaRegistry(LauncherProperties * props, BOOL access64key) {
    DWORD i=0;
    WCHAR ** keys = JAVA_REGISTRY_KEYS;
    DWORD k=0;
    WCHAR * buffer = newpWCHAR(MAX_LEN_VALUE_NAME);
    HKEY rootKeys [2] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER};
    DWORD rootKeysNumber = sizeof(rootKeys)/sizeof(HKEY);
    DWORD keysNumber = sizeof(JAVA_REGISTRY_KEYS)/sizeof(WCHAR*);
    DWORD status = ERROR_OK;
    
    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "Search java in CurrentVersion values...", 1);
    
    
    for ( k = 0; k < rootKeysNumber; k++) {
        for(i=0; i < keysNumber;i++) {
            if(isTerminated(props)) {
                return;
            }
            else {
                
                WCHAR * value = getStringValue(rootKeys[k], keys[i], CURRENT_VERSION, access64key);
                if(value!=NULL) {
                    WCHAR *javaHome = getStringValuePC(rootKeys[k], keys[i], value, JAVA_HOME, access64key);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... ", 0);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, (rootKeys[k]==HKEY_LOCAL_MACHINE) ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER", 0);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0);
                    writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, keys[i], 0);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0);
                    writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, CURRENT_VERSION, 0);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "->", 0);
                    writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, value, 0);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "[", 0);
                    writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, JAVA_HOME, 0);
                    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "] = ", 0);
                    writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, javaHome, 1);
                    
                    FREE(value);
                    trySetCompatibleJava(javaHome, props);
                    FREE(javaHome);
                    if(props->java!=NULL) {
                        FREE(buffer);
                        return;
                    }
                }
            }
        }
    }
    
    
    // we found no CurrentVersion java... just search for other possible keys
    writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "Search java in other values...", 1);
    
    
    for(k=0;k<rootKeysNumber;k++) {
        for(i=0;i<keysNumber;i++) {
            HKEY  hkey = 0;
            DWORD   index  = 0 ;
            if (RegOpenKeyExW(rootKeys[k], keys[i], 0, KEY_READ | ((access64key && IsWow64) ? KEY_WOW64_64KEY : 0), &hkey) == ERROR_SUCCESS) {
                DWORD number = 0;
                if (RegQueryInfoKeyW(hkey, NULL, NULL, NULL, &number, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
                    DWORD err = 0;
                    do {
                        
                        DWORD size = MAX_LEN_VALUE_NAME;
                        buffer[0]  = 0;
                        err = RegEnumKeyExW(hkey, index, buffer, &size, NULL, NULL, NULL, NULL);
                        if (err == ERROR_SUCCESS) {
                            WCHAR  * javaHome = getJavaHomeValue(keys[i], buffer, access64key);
                            status = ERROR_OK;
                            
                            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, (rootKeys[k]==HKEY_LOCAL_MACHINE) ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER", 0);
                            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0);
                            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, keys[i], 0);
                            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0);
                            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, buffer, 0);
                            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "[", 0);
                            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, JAVA_HOME, 0);
                            writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "] = ", 0);
                            writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, javaHome, 1);
                            
                            trySetCompatibleJava(javaHome, props);
                            FREE(javaHome);
                            if(props->java!=NULL) {
                                i = keysNumber; // to the end of cycles
                                k = rootKeysNumber;
                                break;
                            }
                            
                        }
                        index++;
                    } while (err == ERROR_SUCCESS);
                }
            }
            if (hkey != 0) {
                RegCloseKey(hkey);
            }
        }
    }
    FREE(buffer);
    return;
}
Пример #22
0
INT
SockLoadHelperDll(
    PWSTR TransportName,
    PWINSOCK_MAPPING Mapping,
    PHELPER_DATA *HelperDllData)
{
    PHELPER_DATA        HelperData;
    PWSTR               HelperDllName;
    PWSTR               FullHelperDllName;
    PWSTR               HelperKey;
    HKEY                KeyHandle;
    ULONG               DataSize;
    LONG                Status;

    /* Allocate space for the Helper Structure and TransportName */
    HelperData = HeapAlloc(GlobalHeap, 0, sizeof(*HelperData) + (wcslen(TransportName) + 1) * sizeof(WCHAR));

    /* Check for error */
    if (HelperData == NULL) {
        ERR("Buffer allocation failed\n");
        return WSAEINVAL;
    }

    /* Allocate Space for the Helper DLL Key */
    HelperKey = HeapAlloc(GlobalHeap, 0, (54 + wcslen(TransportName)) * sizeof(WCHAR));

    /* Check for error */
    if (HelperKey == NULL) {
        ERR("Buffer allocation failed\n");
        HeapFree(GlobalHeap, 0, HelperData);
        return WSAEINVAL;
    }

    /* Generate the right key name */
    wcscpy(HelperKey, L"System\\CurrentControlSet\\Services\\");
    wcscat(HelperKey, TransportName);
    wcscat(HelperKey, L"\\Parameters\\Winsock");

    /* Open the Key */
    Status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, HelperKey, 0, KEY_READ, &KeyHandle);

    HeapFree(GlobalHeap, 0, HelperKey);

    /* Check for error */
    if (Status) {
        ERR("Error reading helper DLL parameters\n");
        HeapFree(GlobalHeap, 0, HelperData);
        return WSAEINVAL;
    }

    /* Read Size of SockAddr Structures */
    DataSize = sizeof(HelperData->MinWSAddressLength);
    HelperData->MinWSAddressLength = 16;
    RegQueryValueExW (KeyHandle,
                      L"MinSockaddrLength",
                      NULL,
                      NULL,
                      (LPBYTE)&HelperData->MinWSAddressLength,
                      &DataSize);
    DataSize = sizeof(HelperData->MinWSAddressLength);
    HelperData->MaxWSAddressLength = 16;
    RegQueryValueExW (KeyHandle,
                      L"MaxSockaddrLength",
                      NULL,
                      NULL,
                      (LPBYTE)&HelperData->MaxWSAddressLength,
                      &DataSize);

    /* Size of TDI Structures */
    HelperData->MinTDIAddressLength = HelperData->MinWSAddressLength + 6;
    HelperData->MaxTDIAddressLength = HelperData->MaxWSAddressLength + 6;

    /* Read Delayed Acceptance Setting */
    DataSize = sizeof(DWORD);
    HelperData->UseDelayedAcceptance = FALSE;
    RegQueryValueExW (KeyHandle,
                      L"UseDelayedAcceptance",
                      NULL,
                      NULL,
                      (LPBYTE)&HelperData->UseDelayedAcceptance,
                      &DataSize);

    /* Allocate Space for the Helper DLL Names */
    HelperDllName = HeapAlloc(GlobalHeap, 0, 512);

    /* Check for error */
    if (HelperDllName == NULL) {
        ERR("Buffer allocation failed\n");
        HeapFree(GlobalHeap, 0, HelperData);
        return WSAEINVAL;
    }

    FullHelperDllName = HeapAlloc(GlobalHeap, 0, 512);

    /* Check for error */
    if (FullHelperDllName == NULL) {
        ERR("Buffer allocation failed\n");
        HeapFree(GlobalHeap, 0, HelperDllName);
        HeapFree(GlobalHeap, 0, HelperData);
        return WSAEINVAL;
    }

    /* Get the name of the Helper DLL*/
    DataSize = 512;
    Status = RegQueryValueExW (KeyHandle,
                               L"HelperDllName",
                               NULL,
                               NULL,
                               (LPBYTE)HelperDllName,
                               &DataSize);

    /* Check for error */
    if (Status) {
        ERR("Error reading helper DLL parameters\n");
        HeapFree(GlobalHeap, 0, FullHelperDllName);
        HeapFree(GlobalHeap, 0, HelperDllName);
        HeapFree(GlobalHeap, 0, HelperData);
        return WSAEINVAL;
    }

    /* Get the Full name, expanding Environment Strings */
    ExpandEnvironmentStringsW (HelperDllName,
                               FullHelperDllName,
                               256);

    /* Load the DLL */
    HelperData->hInstance = LoadLibraryW(FullHelperDllName);

    HeapFree(GlobalHeap, 0, HelperDllName);
    HeapFree(GlobalHeap, 0, FullHelperDllName);

    if (HelperData->hInstance == NULL) {
        ERR("Error loading helper DLL\n");
        HeapFree(GlobalHeap, 0, HelperData);
        return WSAEINVAL;
    }

    /* Close Key */
    RegCloseKey(KeyHandle);

    /* Get the Pointers to the Helper Routines */
    HelperData->WSHOpenSocket =	(PWSH_OPEN_SOCKET)
									GetProcAddress(HelperData->hInstance,
									"WSHOpenSocket");
    HelperData->WSHOpenSocket2 = (PWSH_OPEN_SOCKET2)
									GetProcAddress(HelperData->hInstance,
									"WSHOpenSocket2");
    HelperData->WSHJoinLeaf = (PWSH_JOIN_LEAF)
								GetProcAddress(HelperData->hInstance,
								"WSHJoinLeaf");
    HelperData->WSHNotify = (PWSH_NOTIFY)
								GetProcAddress(HelperData->hInstance, "WSHNotify");
    HelperData->WSHGetSocketInformation = (PWSH_GET_SOCKET_INFORMATION)
											GetProcAddress(HelperData->hInstance,
											"WSHGetSocketInformation");
    HelperData->WSHSetSocketInformation = (PWSH_SET_SOCKET_INFORMATION)
											GetProcAddress(HelperData->hInstance,
											"WSHSetSocketInformation");
    HelperData->WSHGetSockaddrType = (PWSH_GET_SOCKADDR_TYPE)
										GetProcAddress(HelperData->hInstance,
										"WSHGetSockaddrType");
    HelperData->WSHGetWildcardSockaddr = (PWSH_GET_WILDCARD_SOCKADDR)
											GetProcAddress(HelperData->hInstance,
											"WSHGetWildcardSockaddr");
    HelperData->WSHGetBroadcastSockaddr = (PWSH_GET_BROADCAST_SOCKADDR)
											GetProcAddress(HelperData->hInstance,
											"WSHGetBroadcastSockaddr");
    HelperData->WSHAddressToString = (PWSH_ADDRESS_TO_STRING)
										GetProcAddress(HelperData->hInstance,
										"WSHAddressToString");
    HelperData->WSHStringToAddress = (PWSH_STRING_TO_ADDRESS)
										GetProcAddress(HelperData->hInstance,
										"WSHStringToAddress");
    HelperData->WSHIoctl = (PWSH_IOCTL)
							GetProcAddress(HelperData->hInstance,
							"WSHIoctl");

    /* Save the Mapping Structure and transport name */
    HelperData->Mapping = Mapping;
    wcscpy(HelperData->TransportName, TransportName);

    /* Increment Reference Count */
    HelperData->RefCount = 1;

    /* Add it to our list */
    InsertHeadList(&SockHelpersListHead, &HelperData->Helpers);

    /* Return Pointers */
    *HelperDllData = HelperData;
    return 0;
}
Пример #23
0
static DWORD scmdatabase_load_services(struct scmdatabase *db)
{
    DWORD err;
    int i;

    for (i = 0; TRUE; i++)
    {
        WCHAR szName[MAX_SERVICE_NAME];
        struct service_entry *entry;
        HKEY hServiceKey;

        err = RegEnumKeyW(db->root_key, i, szName, MAX_SERVICE_NAME);
        if (err == ERROR_NO_MORE_ITEMS)
            break;

        if (err != 0)
        {
            WINE_ERR("Error %d reading key %d name - skipping\n", err, i);
            continue;
        }

        err = service_create(szName, &entry);
        if (err != ERROR_SUCCESS)
            break;

        WINE_TRACE("Loading service %s\n", wine_dbgstr_w(szName));
        err = RegOpenKeyExW(db->root_key, szName, 0, KEY_READ, &hServiceKey);
        if (err == ERROR_SUCCESS)
        {
            err = load_service_config(hServiceKey, entry);
            RegCloseKey(hServiceKey);
        }

        if (err != ERROR_SUCCESS)
        {
            WINE_ERR("Error %d reading registry key for service %s - skipping\n", err, wine_dbgstr_w(szName));
            free_service_entry(entry);
            continue;
        }

        if (entry->config.dwServiceType == 0)
        {
            /* Maybe an application only wrote some configuration in the service key. Continue silently */
            WINE_TRACE("Even the service type not set for service %s - skipping\n", wine_dbgstr_w(szName));
            free_service_entry(entry);
            continue;
        }

        if (!validate_service_config(entry))
        {
            WINE_ERR("Invalid configuration of service %s - skipping\n", wine_dbgstr_w(szName));
            free_service_entry(entry);
            continue;
        }

        entry->status.dwServiceType = entry->config.dwServiceType;
        entry->db = db;

        list_add_tail(&db->services, &entry->entry);
    }
    return ERROR_SUCCESS;
}
Пример #24
0
INT
SockLoadTransportMapping(
    PWSTR TransportName,
    PWINSOCK_MAPPING *Mapping)
{
    PWSTR               TransportKey;
    HKEY                KeyHandle;
    ULONG               MappingSize;
    LONG                Status;

    TRACE("TransportName %ws\n", TransportName);

    /* Allocate a Buffer */
    TransportKey = HeapAlloc(GlobalHeap, 0, (54 + wcslen(TransportName)) * sizeof(WCHAR));

    /* Check for error */
    if (TransportKey == NULL) {
        ERR("Buffer allocation failed\n");
        return WSAEINVAL;
    }

    /* Generate the right key name */
    wcscpy(TransportKey, L"System\\CurrentControlSet\\Services\\");
    wcscat(TransportKey, TransportName);
    wcscat(TransportKey, L"\\Parameters\\Winsock");

    /* Open the Key */
    Status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TransportKey, 0, KEY_READ, &KeyHandle);

    /* We don't need the Transport Key anymore */
    HeapFree(GlobalHeap, 0, TransportKey);

    /* Check for error */
    if (Status) {
        ERR("Error reading transport mapping registry\n");
        return WSAEINVAL;
    }

    /* Find out how much space we need for the Mapping */
    Status = RegQueryValueExW(KeyHandle, L"Mapping", NULL, NULL, NULL, &MappingSize);

    /* Check for error */
    if (Status) {
        ERR("Error reading transport mapping registry\n");
        return WSAEINVAL;
    }

    /* Allocate Memory for the Mapping */
    *Mapping = HeapAlloc(GlobalHeap, 0, MappingSize);

    /* Check for error */
    if (*Mapping == NULL) {
        ERR("Buffer allocation failed\n");
        return WSAEINVAL;
    }

    /* Read the Mapping */
    Status = RegQueryValueExW(KeyHandle, L"Mapping", NULL, NULL, (LPBYTE)*Mapping, &MappingSize);

    /* Check for error */
    if (Status) {
        ERR("Error reading transport mapping registry\n");
        HeapFree(GlobalHeap, 0, *Mapping);
        return WSAEINVAL;
    }

    /* Close key and return */
    RegCloseKey(KeyHandle);
    return 0;
}
Пример #25
0
INT
SockLoadTransportList(
    PWSTR *TransportList)
{
    ULONG	TransportListSize;
    HKEY	KeyHandle;
    LONG	Status;

    TRACE("Called\n");

    /* Open the Transports Key */
    Status = RegOpenKeyExW (HKEY_LOCAL_MACHINE,
                            L"SYSTEM\\CurrentControlSet\\Services\\Winsock\\Parameters",
                            0,
                            KEY_READ,
                            &KeyHandle);

    /* Check for error */
    if (Status) {
        ERR("Error reading transport list registry\n");
        return WSAEINVAL;
    }

    /* Get the Transport List Size */
    Status = RegQueryValueExW(KeyHandle,
                              L"Transports",
                              NULL,
                              NULL,
                              NULL,
                              &TransportListSize);

    /* Check for error */
    if (Status) {
        ERR("Error reading transport list registry\n");
        return WSAEINVAL;
    }

    /* Allocate Memory for the Transport List */
    *TransportList = HeapAlloc(GlobalHeap, 0, TransportListSize);

    /* Check for error */
    if (*TransportList == NULL) {
        ERR("Buffer allocation failed\n");
        return WSAEINVAL;
    }

    /* Get the Transports */
    Status = RegQueryValueExW (KeyHandle,
                               L"Transports",
                               NULL,
                               NULL,
                               (LPBYTE)*TransportList,
                               &TransportListSize);

    /* Check for error */
    if (Status) {
        ERR("Error reading transport list registry\n");
        HeapFree(GlobalHeap, 0, *TransportList);
        return WSAEINVAL;
    }

    /* Close key and return */
    RegCloseKey(KeyHandle);
    return 0;
}
Пример #26
0
static HRESULT DEVENUM_RegisterLegacyAmFilters(void)
{
    HKEY hkeyFilter = NULL;
    DWORD dwFilterSubkeys, i;
    LONG lRet;
    IFilterMapper2 *pMapper = NULL;
    HRESULT hr;

    hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
                           &IID_IFilterMapper2, (void **) &pMapper);
    if (SUCCEEDED(hr))
    {
        lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilterKeyName, 0, KEY_READ, &hkeyFilter);
        hr = HRESULT_FROM_WIN32(lRet);
    }

    if (SUCCEEDED(hr))
    {
        lRet = RegQueryInfoKeyW(hkeyFilter, NULL, NULL, NULL, &dwFilterSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        hr = HRESULT_FROM_WIN32(lRet);
    }

    if (SUCCEEDED(hr))
    {
        for (i = 0; i < dwFilterSubkeys; i++)
        {
            WCHAR wszFilterSubkeyName[64];
            DWORD cName = sizeof(wszFilterSubkeyName) / sizeof(WCHAR);
            HKEY hkeyCategoryBaseKey;
            WCHAR wszRegKey[MAX_PATH];
            HKEY hkeyInstance = NULL;

            if (RegEnumKeyExW(hkeyFilter, i, wszFilterSubkeyName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;

            hr = DEVENUM_GetCategoryKey(&CLSID_LegacyAmFilterCategory, &hkeyCategoryBaseKey, wszRegKey, MAX_PATH);
            if (FAILED(hr)) continue;

            strcatW(wszRegKey, wszRegSeparator);
            strcatW(wszRegKey, wszFilterSubkeyName);

            if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszRegKey, 0, KEY_READ, &hkeyInstance) == ERROR_SUCCESS)
            {
                RegCloseKey(hkeyInstance);
            }
            else
            {
                /* Filter is registered the IFilterMapper(1)-way in HKCR\Filter. Needs to be added to
                 * legacy am filter category. */
                HKEY hkeyFilterClass = NULL;
                REGFILTER2 rgf2;
                CLSID clsidFilter;
                WCHAR wszFilterName[MAX_PATH];
                DWORD Type;
                DWORD cbData;
                HRESULT res;
                IMoniker *pMoniker = NULL;

                TRACE("Registering %s\n", debugstr_w(wszFilterSubkeyName));

                strcpyW(wszRegKey, clsid_keyname);
                strcatW(wszRegKey, wszRegSeparator);
                strcatW(wszRegKey, wszFilterSubkeyName);

                if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszRegKey, 0, KEY_READ, &hkeyFilterClass) != ERROR_SUCCESS)
                    continue;

                rgf2.dwVersion = 1;
                rgf2.dwMerit = 0;
                rgf2.u.s.cPins = 0;
                rgf2.u.s.rgPins = NULL;

                cbData = sizeof(wszFilterName);
                if (RegQueryValueExW(hkeyFilterClass, NULL, NULL, &Type, (LPBYTE)wszFilterName, &cbData) != ERROR_SUCCESS ||
                    Type != REG_SZ)
                    goto cleanup;

                cbData = sizeof(rgf2.dwMerit);
                if (RegQueryValueExW(hkeyFilterClass, wszMeritName, NULL, &Type, (LPBYTE)&rgf2.dwMerit, &cbData) != ERROR_SUCCESS ||
                    Type != REG_DWORD)
                    goto cleanup;

                DEVENUM_ReadPins(hkeyFilterClass, &rgf2);

                res = CLSIDFromString(wszFilterSubkeyName, &clsidFilter);
                if (FAILED(res)) goto cleanup;

                IFilterMapper2_RegisterFilter(pMapper, &clsidFilter, wszFilterName, &pMoniker, NULL, NULL, &rgf2);

                if (pMoniker)
                    IMoniker_Release(pMoniker);

                cleanup:

                if (hkeyFilterClass) RegCloseKey(hkeyFilterClass);

                if (rgf2.u.s.rgPins)
                {
                    UINT iPin;

                    for (iPin = 0; iPin < rgf2.u.s.cPins; iPin++)
                    {
                        CoTaskMemFree(rgf2.u.s.rgPins[iPin].strName);

                        if (rgf2.u.s.rgPins[iPin].lpMediaType)
                        {
                            UINT iType;

                            for (iType = 0; iType < rgf2.u.s.rgPins[iPin].nMediaTypes; iType++)
                            {
                                CoTaskMemFree((void*)rgf2.u.s.rgPins[iPin].lpMediaType[iType].clsMajorType);
                                CoTaskMemFree((void*)rgf2.u.s.rgPins[iPin].lpMediaType[iType].clsMinorType);
                            }

                            CoTaskMemFree((void*)rgf2.u.s.rgPins[iPin].lpMediaType);
                        }
                    }

                    CoTaskMemFree((void*)rgf2.u.s.rgPins);
                }
            }
        }
    }

    if (hkeyFilter) RegCloseKey(hkeyFilter);

    if (pMapper)
        IFilterMapper2_Release(pMapper);

    return S_OK;
}
Пример #27
0
static void DEVENUM_ReadPins(HKEY hkeyFilterClass, REGFILTER2 *rgf2)
{
    HKEY hkeyPins = NULL;
    DWORD dwPinsSubkeys, i;
    REGFILTERPINS *rgPins = NULL;

    if (RegOpenKeyExW(hkeyFilterClass, wszPins, 0, KEY_READ, &hkeyPins) != ERROR_SUCCESS)
        return ;

    if (RegQueryInfoKeyW(hkeyPins, NULL, NULL, NULL, &dwPinsSubkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
                != ERROR_SUCCESS)
    {
        RegCloseKey(hkeyPins);
        return ;
    }

    if (dwPinsSubkeys)
    {
        rgPins = CoTaskMemAlloc(sizeof(REGFILTERPINS) * dwPinsSubkeys);
        if (!rgPins)
        {
            RegCloseKey(hkeyPins);
            return ;
        }
    }

    for (i = 0; i < dwPinsSubkeys; i++)
    {
        HKEY hkeyPinKey = NULL;
        WCHAR wszPinName[MAX_PATH];
        DWORD cName = sizeof(wszPinName) / sizeof(WCHAR);
        DWORD Type, cbData;
        REGFILTERPINS *rgPin = &rgPins[rgf2->u.s.cPins];
        LONG lRet;

        rgPin->strName = NULL;
        rgPin->clsConnectsToFilter = &GUID_NULL;
        rgPin->strConnectsToPin = NULL;
        rgPin->nMediaTypes = 0;
        rgPin->lpMediaType = NULL;

        if (RegEnumKeyExW(hkeyPins, i, wszPinName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;

        if (RegOpenKeyExW(hkeyPins, wszPinName, 0, KEY_READ, &hkeyPinKey) != ERROR_SUCCESS) continue;

        rgPin->strName = CoTaskMemAlloc((strlenW(wszPinName) + 1) * sizeof(WCHAR));
        if (!rgPin->strName) goto error_cleanup;

        strcpyW(rgPin->strName, wszPinName);

        cbData = sizeof(rgPin->bMany);
        lRet = RegQueryValueExW(hkeyPinKey, wszAllowedMany, NULL, &Type, (LPBYTE)&rgPin->bMany, &cbData);
        if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
            goto error_cleanup;

        cbData = sizeof(rgPin->bZero);
        lRet = RegQueryValueExW(hkeyPinKey, wszAllowedZero, NULL, &Type, (LPBYTE)&rgPin->bZero, &cbData);
        if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
            goto error_cleanup;

        cbData = sizeof(rgPin->bOutput);
        lRet = RegQueryValueExW(hkeyPinKey, wszDirection, NULL, &Type, (LPBYTE)&rgPin->bOutput, &cbData);
        if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
            goto error_cleanup;

        cbData = sizeof(rgPin->bRendered);
        lRet = RegQueryValueExW(hkeyPinKey, wszIsRendered, NULL, &Type, (LPBYTE)&rgPin->bRendered, &cbData);
        if (lRet != ERROR_SUCCESS || Type != REG_DWORD)
            goto error_cleanup;

        DEVENUM_ReadPinTypes(hkeyPinKey, rgPin);

        ++rgf2->u.s.cPins;
        continue;

        error_cleanup:

        RegCloseKey(hkeyPinKey);
        if (rgPin->strName) CoTaskMemFree(rgPin->strName);
    }

    RegCloseKey(hkeyPins);

    if (rgPins && !rgf2->u.s.cPins)
    {
        CoTaskMemFree(rgPins);
        rgPins = NULL;
    }

    rgf2->u.s.rgPins = rgPins;
}
Пример #28
0
static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey, REGFILTERPINS *rgPin)
{
    HKEY hkeyTypes = NULL;
    DWORD dwMajorTypes, i;
    REGPINTYPES *lpMediaType = NULL;
    DWORD dwMediaTypeSize = 0;

    if (RegOpenKeyExW(hkeyPinKey, wszTypes, 0, KEY_READ, &hkeyTypes) != ERROR_SUCCESS)
        return ;

    if (RegQueryInfoKeyW(hkeyTypes, NULL, NULL, NULL, &dwMajorTypes, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
                != ERROR_SUCCESS)
    {
        RegCloseKey(hkeyTypes);
        return ;
    }

    for (i = 0; i < dwMajorTypes; i++)
    {
        HKEY hkeyMajorType = NULL;
        WCHAR wszMajorTypeName[64];
        DWORD cName = sizeof(wszMajorTypeName) / sizeof(WCHAR);
        DWORD dwMinorTypes, i1;

        if (RegEnumKeyExW(hkeyTypes, i, wszMajorTypeName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;

        if (RegOpenKeyExW(hkeyTypes, wszMajorTypeName, 0, KEY_READ, &hkeyMajorType) != ERROR_SUCCESS) continue;

        if (RegQueryInfoKeyW(hkeyMajorType, NULL, NULL, NULL, &dwMinorTypes, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
                    != ERROR_SUCCESS)
        {
            RegCloseKey(hkeyMajorType);
            continue;
        }

        for (i1 = 0; i1 < dwMinorTypes; i1++)
        {
            WCHAR wszMinorTypeName[64];
            CLSID *clsMajorType = NULL, *clsMinorType = NULL;
            HRESULT hr;

            cName = sizeof(wszMinorTypeName) / sizeof(WCHAR);
            if (RegEnumKeyExW(hkeyMajorType, i1, wszMinorTypeName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;

            clsMinorType = CoTaskMemAlloc(sizeof(CLSID));
            if (!clsMinorType) continue;

            clsMajorType = CoTaskMemAlloc(sizeof(CLSID));
            if (!clsMajorType) goto error_cleanup_types;

            hr = CLSIDFromString(wszMinorTypeName, clsMinorType);
            if (FAILED(hr)) goto error_cleanup_types;

            hr = CLSIDFromString(wszMajorTypeName, clsMajorType);
            if (FAILED(hr)) goto error_cleanup_types;

            if (rgPin->nMediaTypes == dwMediaTypeSize)
            {
                DWORD dwNewSize = dwMediaTypeSize + (dwMediaTypeSize < 2 ? 1 : dwMediaTypeSize / 2);
                REGPINTYPES *lpNewMediaType;

                lpNewMediaType = CoTaskMemRealloc(lpMediaType, sizeof(REGPINTYPES) * dwNewSize);
                if (!lpNewMediaType) goto error_cleanup_types;

                lpMediaType = lpNewMediaType;
                dwMediaTypeSize = dwNewSize;
             }

            lpMediaType[rgPin->nMediaTypes].clsMajorType = clsMajorType;
            lpMediaType[rgPin->nMediaTypes].clsMinorType = clsMinorType;
            rgPin->nMediaTypes++;
            continue;

            error_cleanup_types:

            if (clsMajorType) CoTaskMemFree(clsMajorType);
            if (clsMinorType) CoTaskMemFree(clsMinorType);
        }

        RegCloseKey(hkeyMajorType);
    }

    RegCloseKey(hkeyTypes);

    if (lpMediaType && !rgPin->nMediaTypes)
    {
        CoTaskMemFree(lpMediaType);
        lpMediaType = NULL;
    }

    rgPin->lpMediaType = lpMediaType;
}
Пример #29
0
// read font linking information from registry, and store in std::map
void initWindows(){
	LONG l_ret;

	const wchar_t *Fonts = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";

	HKEY key_ft;
	l_ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Fonts, 0, KEY_QUERY_VALUE, &key_ft);
	if (l_ret != ERROR_SUCCESS){
	    ofLogError("ofTrueTypeFont") << "initWindows(): couldn't find fonts registery key";
        return;
	}

	DWORD value_count;
	DWORD max_data_len;
	wchar_t value_name[2048];
	BYTE *value_data;


	// get font_file_name -> font_face mapping from the "Fonts" registry key

	l_ret = RegQueryInfoKeyW(key_ft, NULL, NULL, NULL, NULL, NULL, NULL, &value_count, NULL, &max_data_len, NULL, NULL);
	if(l_ret != ERROR_SUCCESS){
	    ofLogError("ofTrueTypeFont") << "initWindows(): couldn't query registery for fonts";
        return;
	}

	// no font installed
	if (value_count == 0){
	    ofLogError("ofTrueTypeFont") << "initWindows(): couldn't find any fonts in registery";
        return;
	}

	// max_data_len is in BYTE
	value_data = static_cast<BYTE *>(HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, max_data_len));
	if(value_data == NULL) return;

	char value_name_char[2048];
	char value_data_char[2048];
	/*char ppidl[2048];
	char fontsPath[2048];
    SHGetKnownFolderIDList(FOLDERID_Fonts, 0, NULL, &ppidl);
    SHGetPathFromIDList(ppidl,&fontsPath);*/
    string fontsDir = getenv ("windir");
    fontsDir += "\\Fonts\\";
	for (DWORD i = 0; i < value_count; ++i)
	{
			DWORD name_len = 2048;
			DWORD data_len = max_data_len;

			l_ret = RegEnumValueW(key_ft, i, value_name, &name_len, NULL, NULL, value_data, &data_len);
			if(l_ret != ERROR_SUCCESS){
			     ofLogError("ofTrueTypeFont") << "initWindows(): couldn't read registry key for font type";
			     continue;
			}

            wcstombs(value_name_char,value_name,2048);
			wcstombs(value_data_char,reinterpret_cast<wchar_t *>(value_data),2048);
			string curr_face = value_name_char;
			string font_file = value_data_char;
			curr_face = curr_face.substr(0, curr_face.find('(') - 1);
			fonts_table[curr_face] = fontsDir + font_file;
	}


	HeapFree(GetProcessHeap(), 0, value_data);

	l_ret = RegCloseKey(key_ft);
}
Пример #30
0
static DWORD WINAPI
RunSetupThreadProc(
	IN LPVOID lpParameter)
{
	PROCESS_INFORMATION ProcessInformation;
	STARTUPINFOW StartupInfo;
	WCHAR Shell[MAX_PATH];
	WCHAR CommandLine[MAX_PATH];
	BOOL Result;
	DWORD dwError;
	HKEY hKey;
	DWORD dwType;
	DWORD dwSize;
	DWORD dwExitCode;

	TRACE("RunSetup() called\n");

	/* Open key */
	dwError = RegOpenKeyExW(
		HKEY_LOCAL_MACHINE,
		L"SYSTEM\\Setup",
		0,
		KEY_QUERY_VALUE,
		&hKey);
	if (dwError != ERROR_SUCCESS)
		return FALSE;

	/* Read key */
	dwSize = (sizeof(Shell) / sizeof(Shell[0])) - 1;
	dwError = RegQueryValueExW(
		hKey,
		L"CmdLine",
		NULL,
		&dwType,
		(LPBYTE)Shell,
		&dwSize);
	RegCloseKey(hKey);
	if (dwError != ERROR_SUCCESS)
		return FALSE;

	/* Finish string */
	Shell[dwSize / sizeof(WCHAR)] = UNICODE_NULL;

	/* Expand string (if applicable) */
	if (dwType == REG_EXPAND_SZ)
		ExpandEnvironmentStringsW(Shell, CommandLine, MAX_PATH);
	else if (dwType == REG_SZ)
		wcscpy(CommandLine, Shell);
	else
		return FALSE;

	TRACE("Should run '%s' now\n", debugstr_w(CommandLine));

	/* Start process */
	StartupInfo.cb = sizeof(StartupInfo);
	StartupInfo.lpReserved = NULL;
	StartupInfo.lpDesktop = NULL;
	StartupInfo.lpTitle = NULL;
	StartupInfo.dwFlags = 0;
	StartupInfo.cbReserved2 = 0;
	StartupInfo.lpReserved2 = 0;
	Result = CreateProcessW(
		NULL,
		CommandLine,
		NULL,
		NULL,
		FALSE,
		DETACHED_PROCESS,
		NULL,
		NULL,
		&StartupInfo,
		&ProcessInformation);
	if (!Result)
	{
		TRACE("Failed to run setup process\n");
		return FALSE;
	}

	/* Wait for process termination */
	WaitForSingleObject(ProcessInformation.hProcess, INFINITE);

	GetExitCodeProcess(ProcessInformation.hProcess, &dwExitCode);

	/* Close handles */
	CloseHandle(ProcessInformation.hThread);
	CloseHandle(ProcessInformation.hProcess);

	TRACE ("RunSetup() done\n");

	return TRUE;
}