コード例 #1
0
ファイル: environment.c プロジェクト: Strongc/reactos
BOOL
CreateUserEnvironment(
    IN PWLSESSION Session)
{
    HKEY hKeyCurrentUser;
    LONG lError;

    TRACE("WL: CreateUserEnvironment called\n");

    /* Impersonate the new user */
    ImpersonateLoggedOnUser(Session->UserToken);

    /* Open the new users HKCU key */
    lError = RegOpenCurrentUser(KEY_CREATE_SUB_KEY,
                                &hKeyCurrentUser);
    if (lError == ERROR_SUCCESS)
    {
        BuildVolatileEnvironment(Session,
                                 hKeyCurrentUser);
        RegCloseKey(hKeyCurrentUser);
    }

    /* Revert the impersonation */
    RevertToSelf();

    TRACE("WL: CreateUserEnvironment done\n");

    return TRUE;
}
コード例 #2
0
void
RegistryMonitor::initialiseObjectNameMap()
{
	HKEY hTestKey;
	wchar_t szTemp[256];

	DWORD dwError = RegOpenCurrentUser(KEY_READ , &hTestKey);
	if (dwError == ERROR_SUCCESS )
	{
		NTSTATUS status;
		DWORD RequiredLength;
		PPUBLIC_OBJECT_TYPE_INFORMATION t;

		typedef DWORD (WINAPI *pNtQueryObject)(HANDLE,DWORD,VOID*,DWORD,VOID*);
		pNtQueryObject NtQueryObject = (pNtQueryObject)GetProcAddress(GetModuleHandle(L"ntdll.dll"), (LPCSTR)"NtQueryObject");
		
		status = NtQueryObject(hTestKey, 1, NULL,0,&RequiredLength);

		if(status == STATUS_INFO_LENGTH_MISMATCH)
		{
			t = (PPUBLIC_OBJECT_TYPE_INFORMATION)VirtualAlloc(NULL, RequiredLength, MEM_COMMIT, PAGE_READWRITE);
			if(status != NtQueryObject(hTestKey, 1,t,RequiredLength,&RequiredLength))
			{
				ZeroMemory(szTemp, 256);
				CopyMemory(&szTemp, t->TypeName.Buffer, RequiredLength);

				// Dont change the order of these ... _Classes should be inserted first
				// Small bug but who cares
				wstring temp2 = szTemp;
				temp2 += L"_CLASSES";
				wstring name2 = L"HKCR";
				objectNameMap.push_back(ObjectPair(temp2, name2));
				wstring temp1 = szTemp;
				wstring name1 = L"HKCU";
				objectNameMap.push_back(ObjectPair(temp1, name1));
				wstring temp3 = L"\\REGISTRY\\MACHINE";
				wstring name3 = L"HKLM";
				objectNameMap.push_back(ObjectPair(temp3, name3));
				wstring temp4 = L"\\REGISTRY\\USER";
				wstring name4 = L"HKU";
				objectNameMap.push_back(ObjectPair(temp4, name4));
				wstring temp5 = L"\\Registry\\Machine";
				wstring name5 = L"HKLM";
				objectNameMap.push_back(ObjectPair(temp5, name5));

			}
			VirtualFree(t, 0, MEM_RELEASE);
		}
	}
}
コード例 #3
0
ファイル: vgRegTree.cpp プロジェクト: kimmyungwon/videogear
void RegTree::InitPrefixs( void )
{
	HKEY key;
	wstring path;

	RegOpenCurrentUser(KEY_READ, &key);
	ResolveKey(key, path);
	m_currentUserPrefix = path;

	Real_RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Classes", 0, KEY_READ, &key);
	ResolveKey(key, path);
	m_classesRootPrefix = path;

	Real_RegOpenKeyExW(HKEY_CURRENT_CONFIG, L"Software", 0, KEY_READ, &key);
	ResolveKey(key, path);
	m_currentConfigSoftwarePrefix = path;

	Real_RegOpenKeyExW(HKEY_CURRENT_CONFIG, L"System", 0, KEY_READ, &key);
	ResolveKey(key, path);
	m_currentConfigSystemPrefix = path;
}
コード例 #4
0
ファイル: LyricsDlg.cpp プロジェクト: Feoggou/gen_ym10
HANDLE CLyricsDlg::OpenLyricsFile(HWND hDlg)
{
	//first, we get a key to the current user:
	HKEY hKey;
	char strError[30];
	
	if (0 != RegOpenCurrentUser(KEY_WRITE | KEY_READ, &hKey))
	{
		sprintf_s(strError, 30, "Error 0x%x.", GetLastError());
		MessageBoxA(genDll.m_hWinamp, strError, "Fatal Error!", MB_ICONERROR);
#ifdef _DEBUG
			DebugBreak();
#endif
		return INVALID_HANDLE_VALUE;
	}

	if (0 != RegOpenKeyEx(hKey, L"Volatile Environment", 0, KEY_READ, &hKey))
	{
		sprintf_s(strError, 30, "Error 0x%x.", GetLastError());
		MessageBoxA(genDll.m_hWinamp, strError, "Fatal Error!", MB_ICONERROR);
#ifdef _DEBUG
			DebugBreak();
#endif
		return INVALID_HANDLE_VALUE;
	}

	DWORD dwType;
	DWORD dwSize;
	wchar_t str[MAX_PATH];
	if (ERROR_SUCCESS != RegQueryValueEx(hKey, L"APPDATA", 0, &dwType, (LPBYTE)str, &dwSize))
//	if (ERROR_SUCCESS != RegGeValue(hKey, 0, L"APPDATA", RRF_RT_REG_SZ, &dwType, str, &dwSize))
	{
		sprintf_s(strError, 30, "Error 0x%x.", GetLastError());
		MessageBoxA(genDll.m_hWinamp, strError, "Fatal Error!", MB_ICONERROR);
#ifdef _DEBUG
			DebugBreak();
#endif
		return INVALID_HANDLE_VALUE;
	}

	RegCloseKey(hKey);

	//create or open the directory:
	wstring wsPath = str;
	wsPath += L"\\Winamp";
	CreateDirectory(wsPath.data(), 0);
	wsPath += L"\\Plugins";
	CreateDirectory(wsPath.data(), 0);
	wsPath += L"\\Feoggou App";
	CreateDirectory(wsPath.data(), 0);
	wstring wsPath2 = wsPath;
	wsPath += L"\\*.lyr";

	//filename: 1.lyr, 2.lyr, ...

	//if the file does not exist, we create it. but we must make sure that that lyric does not exist.
	//file format:
	//HEADER:				'LYR'
	//						artist[30]
	//						album[30]
	//						song[30]
	//						.............
	//BODY:					sec (word)
	//						text len(byte)
	//						text (char*)

	//Get the data from the dialog. at least "Song" must be specified.
	char sSong[30], sArtist[30], sAlbum[30];
	GetDlgItemTextA(hDlg, IDC_SONGNAME, sSong, 30);
	GetDlgItemTextA(hDlg, IDC_ARTISTNAME, sArtist, 30);
	GetDlgItemTextA(hDlg, IDC_ALBUMNAME, sAlbum, 30);

	if (strlen(sSong) == 0)
	{
		MessageBoxA(hDlg, "Trebuie să specifici numele melodiei în caseta \"Melodie:\". ", "Salvare versuri", MB_ICONEXCLAMATION);
		return INVALID_HANDLE_VALUE;
	}
	
	if (strlen(sArtist) == 0)
	{
		int nResult = MessageBoxA(hDlg, "Este o idee bună să specifici numele artistului, dacă îl știi. Vrei să te întorci să îl scrii?", "Lipsește numele artistului", MB_ICONEXCLAMATION | MB_YESNO);
		if (nResult == IDYES) return INVALID_HANDLE_VALUE;
	}

	if (strlen(sAlbum) == 0)
	{
		int nResult = MessageBoxA(hDlg, "Este o idee bună să specifici numele albumului, dacă îl știi. Vrei să te întorci să îl scrii?", "Lipsește numele albumului", MB_ICONEXCLAMATION | MB_YESNO);
		if (nResult == IDYES) return INVALID_HANDLE_VALUE;
	}

	WIN32_FIND_DATA f_data;
	BOOL bResult =0;
	memset(&f_data, 0, sizeof(f_data));
	int fileNr = 0;
	HANDLE hSearch = FindFirstFile(wsPath.data(), &f_data);
	while (hSearch != INVALID_HANDLE_VALUE)
	{
		//make sure it is <number>.lyr
		wstring wsFileName = f_data.cFileName;
		wsFileName = wsFileName.erase(wsFileName.length() - 4, 4);
		fileNr = _wtoi(wsFileName.c_str());
		if (fileNr == 0) {FindNextFile(hSearch, &f_data); continue;}
		//we open the file:
		wstring sfn = wsPath2;
		sfn += '\\';
		sfn += f_data.cFileName;
		HANDLE hFile = CreateFile(sfn.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
		if (hFile == INVALID_HANDLE_VALUE) 
		{
			sprintf_s(strError, 30, "Error 0x%x has occured.", GetLastError());
			MessageBoxA(genDll.m_hWinamp, strError, "Error!", MB_ICONERROR);
#ifdef _DEBUG
			DebugBreak();
#endif
			bResult = FindNextFile(hSearch, &f_data);
			if (bResult == 0 && GetLastError() == ERROR_NO_MORE_FILES) break;
			continue;
		}

		//we read the content
		char song[30] = "", artist[30] = "", album[30] = "", sLyr[3] = "";
		DWORD dwRead;
		ReadFile(hFile, sLyr, 3, &dwRead, 0);
		if (sLyr[0] != 'L' && sLyr[1] != 'Y' && sLyr[2] != 'R')
		{
			CloseHandle(hFile);
			bResult = FindNextFile(hSearch, &f_data);
			if (bResult == 0 && GetLastError() == ERROR_NO_MORE_FILES) break;
			continue;
		}

		ReadFile(hFile, artist, 30, &dwRead, 0);
		ReadFile(hFile, album, 30, &dwRead, 0);
		ReadFile(hFile, song, 30, &dwRead, 0);
		//now, how to check: first, song name: both must have it. check non-case sensitive.
		if (_stricmp(song, sSong) != 0)
		{
			CloseHandle(hFile);
			bResult = FindNextFile(hSearch, &f_data);
			if (bResult == 0 && GetLastError() == ERROR_NO_MORE_FILES) break;
			continue;
		}
		//otherwise, at least album or artist must exist and differ.
		bool art_dif = false, alb_dif = false;
		if (strlen(artist) == 0 || strlen(sArtist) == 0) art_dif = true;
		if (strlen(album) == 0 || strlen(sAlbum) == 0) alb_dif = true;

		if (!art_dif && !alb_dif)
		{
			string mesaj = "Un fișier de versuri cu același nume de melodie există deja.\n";
			if (strlen(artist)) {mesaj += "Numele artistului: "; mesaj += artist; mesaj += '\n';}
			if (strlen(album)) {mesaj += "Numele albumului: "; mesaj += album; mesaj += '\n';}
			mesaj += "Vrei să îl înlocuiești?";
			int nResult = MessageBoxA(hDlg, mesaj.data(), "Versuri deja existente", MB_ICONINFORMATION | MB_YESNO);
			CloseHandle(hFile);
			if (nResult == IDYES)
			{
				fileNr--;
				break;
			}
			else return INVALID_HANDLE_VALUE;
		}
		CloseHandle(hFile);

		bResult = FindNextFile(hSearch, &f_data);
		if (bResult == 0 && GetLastError() == ERROR_NO_MORE_FILES) break;
	}
	FindClose(hSearch);

	fileNr++;
	wchar_t file_name[10];
	_itow_s(fileNr, file_name, 10, 10);
	wsPath2 += L"\\";
	wsPath2 += file_name;
	wsPath2 += L".lyr";

	//we create the file
	HANDLE hNewFile = CreateFile(wsPath2.c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

	DWORD dwWritten;
	WriteFile(hNewFile, "LYR", 3, &dwWritten, 0);
	WriteFile(hNewFile, sArtist, 30, &dwWritten, 0);
	WriteFile(hNewFile, sAlbum, 30, &dwWritten, 0);
	WriteFile(hNewFile, sSong, 30, &dwWritten, 0);

	return hNewFile;
}
コード例 #5
0
ファイル: sas.c プロジェクト: Moteesh/reactos
BOOL
SetDefaultLanguage(
    IN PWLSESSION Session)
{
    BOOL ret = FALSE;
    BOOL UserProfile;
    LONG rc;
    HKEY UserKey, hKey = NULL;
    LPCWSTR SubKey, ValueName;
    DWORD dwType, dwSize;
    LPWSTR Value = NULL;
    UNICODE_STRING ValueString;
    NTSTATUS Status;
    LCID Lcid;

    UserProfile = (Session && Session->UserToken);

    if (UserProfile && !ImpersonateLoggedOnUser(Session->UserToken))
    {
        ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
        return FALSE;
        // FIXME: ... or use the default language of the system??
        // UserProfile = FALSE;
    }

    if (UserProfile)
    {
        rc = RegOpenCurrentUser(MAXIMUM_ALLOWED, &UserKey);
        if (rc != ERROR_SUCCESS)
        {
            TRACE("RegOpenCurrentUser() failed with error %lu\n", rc);
            goto cleanup;
        }

        SubKey = L"Control Panel\\International";
        ValueName = L"Locale";
    }
    else
    {
        UserKey = NULL;
        SubKey = L"System\\CurrentControlSet\\Control\\Nls\\Language";
        ValueName = L"Default";
    }

    rc = RegOpenKeyExW(UserKey ? UserKey : HKEY_LOCAL_MACHINE,
                       SubKey,
                       0,
                       KEY_READ,
                       &hKey);

    if (UserKey)
        RegCloseKey(UserKey);

    if (rc != ERROR_SUCCESS)
    {
        TRACE("RegOpenKeyEx() failed with error %lu\n", rc);
        goto cleanup;
    }

    rc = RegQueryValueExW(hKey,
                          ValueName,
                          NULL,
                          &dwType,
                          NULL,
                          &dwSize);
    if (rc != ERROR_SUCCESS)
    {
        TRACE("RegQueryValueEx() failed with error %lu\n", rc);
        goto cleanup;
    }
    else if (dwType != REG_SZ)
    {
        TRACE("Wrong type for %S\\%S registry entry (got 0x%lx, expected 0x%x)\n",
            SubKey, ValueName, dwType, REG_SZ);
        goto cleanup;
    }

    Value = HeapAlloc(GetProcessHeap(), 0, dwSize);
    if (!Value)
    {
        TRACE("HeapAlloc() failed\n");
        goto cleanup;
    }
    rc = RegQueryValueExW(hKey,
                          ValueName,
                          NULL,
                          NULL,
                          (LPBYTE)Value,
                          &dwSize);
    if (rc != ERROR_SUCCESS)
    {
        TRACE("RegQueryValueEx() failed with error %lu\n", rc);
        goto cleanup;
    }

    /* Convert Value to a Lcid */
    ValueString.Length = ValueString.MaximumLength = (USHORT)dwSize;
    ValueString.Buffer = Value;
    Status = RtlUnicodeStringToInteger(&ValueString, 16, (PULONG)&Lcid);
    if (!NT_SUCCESS(Status))
    {
        TRACE("RtlUnicodeStringToInteger() failed with status 0x%08lx\n", Status);
        goto cleanup;
    }

    TRACE("%s language is 0x%08lx\n",
        UserProfile ? "User" : "System", Lcid);
    Status = NtSetDefaultLocale(UserProfile, Lcid);
    if (!NT_SUCCESS(Status))
    {
        TRACE("NtSetDefaultLocale() failed with status 0x%08lx\n", Status);
        goto cleanup;
    }

    ret = TRUE;

cleanup:
    if (Value)
        HeapFree(GetProcessHeap(), 0, Value);

    if (hKey)
        RegCloseKey(hKey);

    if (UserProfile)
        RevertToSelf();

    return ret;
}
コード例 #6
0
ファイル: screensaver.c プロジェクト: GYGit/reactos
VOID
StartScreenSaver(
    IN PWLSESSION Session)
{
    HKEY hKey = NULL, hCurrentUser = NULL;
    WCHAR szApplicationName[MAX_PATH];
    WCHAR szCommandLine[MAX_PATH + 3];
    DWORD bufferSize = sizeof(szApplicationName) - sizeof(WCHAR);
    DWORD dwType;
    STARTUPINFOW StartupInfo;
    PROCESS_INFORMATION ProcessInformation;
    HANDLE HandleArray[2];
    LONG rc;
    DWORD Status;
    BOOL ret = FALSE;

    if (!ImpersonateLoggedOnUser(Session->UserToken))
    {
        ERR("WL: ImpersonateLoggedOnUser() failed with error %lu\n", GetLastError());
        goto cleanup;
    }

    rc = RegOpenCurrentUser(KEY_READ,
                            &hCurrentUser);
    if (rc != ERROR_SUCCESS)
    {
        ERR("WL: RegOpenCurrentUser error %lu\n", rc);
        goto cleanup;
    }

    rc = RegOpenKeyExW(hCurrentUser,
                       L"Control Panel\\Desktop",
                       0,
                       KEY_QUERY_VALUE,
                       &hKey);
    if (rc != ERROR_SUCCESS)
    {
        ERR("WL: RegOpenKeyEx error %lu\n", rc);
        goto cleanup;
    }

    rc = RegQueryValueExW(hKey,
                          L"SCRNSAVE.EXE",
                          0,
                          &dwType,
                          (LPBYTE)szApplicationName,
                          &bufferSize);
    if (rc != ERROR_SUCCESS || dwType != REG_SZ)
    {
        if (rc != ERROR_FILE_NOT_FOUND)
            ERR("WL: RegQueryValueEx error %lu\n", rc);
        goto cleanup;
    }

    if (bufferSize == 0)
    {
        ERR("WL: Buffer size is NULL!\n");
        goto cleanup;
    }

    szApplicationName[bufferSize / sizeof(WCHAR)] = 0; /* Terminate the string */

    if (wcslen(szApplicationName) == 0)
    {
        ERR("WL: Application Name length is zero!\n");
        goto cleanup;
    }

    wsprintfW(szCommandLine, L"%s /s", szApplicationName);
    TRACE("WL: Executing %S\n", szCommandLine);

    ZeroMemory(&StartupInfo, sizeof(STARTUPINFOW));
    ZeroMemory(&ProcessInformation, sizeof(PROCESS_INFORMATION));
    StartupInfo.cb = sizeof(STARTUPINFOW);
    StartupInfo.dwFlags = STARTF_SCRNSAVER;

    /* FIXME: run the screen saver on the screen saver desktop */
    ret = CreateProcessW(szApplicationName,
                         szCommandLine,
                         NULL,
                         NULL,
                         FALSE,
                         0,
                         NULL,
                         NULL,
                         &StartupInfo,
                         &ProcessInformation);
    if (!ret)
    {
        ERR("WL: Unable to start %S, error %lu\n", szApplicationName, GetLastError());
        goto cleanup;
    }

    CloseHandle(ProcessInformation.hThread);

    SystemParametersInfoW(SPI_SETSCREENSAVERRUNNING, TRUE, NULL, 0);

    CallNotificationDlls(Session, StartScreenSaverHandler);

    /* Wait the end of the process or some other activity */
    ResetEvent(Session->hUserActivity);
    HandleArray[0] = ProcessInformation.hProcess;
    HandleArray[1] = Session->hUserActivity;
    Status = WaitForMultipleObjects(2, HandleArray, FALSE, INFINITE);
    if (Status == WAIT_OBJECT_0 + 1)
    {
        /* Kill the screen saver */
        TerminateProcess(ProcessInformation.hProcess, 0);
    }

    SetEvent(Session->hEndOfScreenSaver);

    CloseHandle(ProcessInformation.hProcess);

    CallNotificationDlls(Session, StopScreenSaverHandler);

cleanup:
    RevertToSelf();
    if (hKey)
        RegCloseKey(hKey);

    if (hCurrentUser)
        RegCloseKey(hCurrentUser);

    if (!ret)
    {
        PostMessageW(Session->SASWindow, WLX_WM_SAS, WLX_SAS_TYPE_SCRNSVR_ACTIVITY, 0);
#ifndef USE_GETLASTINPUTINFO
        InterlockedExchange((LONG*)&Session->LastActivity, GetTickCount());
#endif
    }
}