コード例 #1
0
ファイル: EWV.CPP プロジェクト: tjotala/Articles
BOOL SetTaskExpWinVer(HTASK hTask, WORD wVer)
{
    LPBYTE pTDB = LPBYTE(MAKELP(hTask, 0));
    if (!BAD_PTR(pTDB, 0xfc) &&
        pTDB[0xfa] == 'T' && pTDB[0xfb] == 'D' &&
        (pTDB[0x16] & 0x10) == 0x00) // !Win32 task
    {
        WORD wSel = MAKEWORD(pTDB[0x20], pTDB[0x21]);
        if (SetQueueExpWinVer(HGLOBAL(wSel), wVer))
        {
            pTDB[0x1a] = LOBYTE(wVer); // minor
            pTDB[0x1b] = HIBYTE(wVer); // major
            return (TRUE);
        }
    }
    return (FALSE);
}
コード例 #2
0
void CServiceControl::DeregisterApplicationLog( LPCTSTR ServiceName )
{
	TCHAR szKey[256];
	_tcscpy_s(szKey, _countof(szKey), gszAppRegKey);
	_tcscat_s(szKey, _countof(szKey), ServiceName);
	HKEY hKey = 0;
	LONG lRet = ERROR_SUCCESS;

	lRet = ::RegDeleteKey(HKEY_LOCAL_MACHINE, szKey);

	// now we have to delete the application from the "Sources" value too.
	lRet =	::RegOpenKeyEx(
		HKEY_LOCAL_MACHINE,	// handle of open key
		gszAppRegKey,		// address of name of subkey to open
		0,					// reserved
		KEY_ALL_ACCESS,		// security access mask
		&hKey				// address of handle of open key
		);

	if( lRet == ERROR_SUCCESS )
	{
		DWORD dwSize;

		// retrieve the size of the needed value
		lRet =	::RegQueryValueEx(
			hKey,			// handle of key to query
			TEXT("Sources"),// address of name of value to query
			0,				// reserved
			0,				// address of buffer for value type
			0,				// address of data buffer
			&dwSize			// address of data buffer size
			);

		if( lRet == ERROR_SUCCESS ) {
			DWORD dwType;

			DWORD dwAllocSize = dwSize + 2 * sizeof(TCHAR); // need to ensure that value is NULL-terminated
			LPBYTE Buffer = LPBYTE(::GlobalAlloc(GPTR, dwAllocSize));
			LPBYTE NewBuffer = LPBYTE(::GlobalAlloc(GPTR, dwAllocSize));

			lRet =	::RegQueryValueEx(
				hKey,			// handle of key to query
				TEXT("Sources"),// address of name of value to query
				0,				// reserved
				&dwType,		// address of buffer for value type
				Buffer,			// address of data buffer
				&dwSize			// address of data buffer size
				);
			if( lRet == ERROR_SUCCESS ) {

				// check whether this service is already a known source
				register LPTSTR p = LPTSTR(Buffer);
				register LPTSTR pNew = LPTSTR(NewBuffer);

				// check that value is terminated with 2 zeroes.
				int tchar_count = dwSize / sizeof(TCHAR);
				if (tchar_count < 2 || p[tchar_count - 1] != 0 || p[tchar_count - 2] != 0)
					dwSize += 2 * sizeof(TCHAR);

				BOOL bNeedSave = FALSE;	// assume the value is already correct
				for(; *p; p += _tcslen(p)+1) {
					// except ourself: copy the source string into the destination
					if( _tcscmp(p, ServiceName) != 0 ) {
						_tcsncpy(pNew, p, dwSize/sizeof(TCHAR) - (pNew - LPTSTR(NewBuffer)));
						pNew += _tcslen(pNew)+1;
					} else {
						bNeedSave = TRUE;		// *this* application found
						dwSize -= sizeof(TCHAR)*(_tcslen(p)+1);	// new size of value
					}
				}
				if( bNeedSave ) {
					// OK - now store the modified value back into the
					// registry.
					lRet =	::RegSetValueEx(
						hKey,			// handle of key to set value for
						TEXT("Sources"),// address of value to set
						0,				// reserved
						dwType,			// flag for value type
						NewBuffer,		// address of value data
						dwSize			// size of value data
						);
				}
			}

			::GlobalFree(HGLOBAL(Buffer));
			::GlobalFree(HGLOBAL(NewBuffer));
		}

		::RegCloseKey(hKey);
	}
}
コード例 #3
0
void CServiceControl::RegisterApplicationLog( LPCTSTR ServiceName, LPCTSTR lpszFileName )
{
	DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
	TCHAR szKey[256];
	_tcscpy_s(szKey, _countof(szKey), gszAppRegKey);
	_tcscat_s(szKey, _countof(szKey), ServiceName);

	HKEY hKey = 0;
	LONG lRet = ERROR_SUCCESS;

	// Create a key for that application and insert values for
	// "EventMessageFile" and "TypesSupported"
	if( ::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) == ERROR_SUCCESS ) {
		lRet =	::RegSetValueEx(
			hKey,						// handle of key to set value for
			TEXT("EventMessageFile"),	// address of value to set
			0,							// reserved
			REG_EXPAND_SZ,				// flag for value type
			(CONST BYTE*)lpszFileName,	// address of value data
			sizeof(TCHAR)*(_tcslen(lpszFileName) + 1)	// size of value data
			);

		// Set the supported types flags.
		lRet =	::RegSetValueEx(
			hKey,					// handle of key to set value for
			TEXT("TypesSupported"),	// address of value to set
			0,						// reserved
			REG_DWORD,				// flag for value type
			(CONST BYTE*)&dwTypes,	// address of value data
			sizeof(DWORD)			// size of value data
			);
		::RegCloseKey(hKey);
	}

	// Add the service to the "Sources" value

	lRet =	::RegOpenKeyEx(
		HKEY_LOCAL_MACHINE,	// handle of open key
		gszAppRegKey,		// address of name of subkey to open
		0,					// reserved
		KEY_ALL_ACCESS,		// security access mask
		&hKey				// address of handle of open key
		);
	if( lRet == ERROR_SUCCESS ) {
		DWORD dwSize;

		// retrieve the size of the needed value
		lRet =	::RegQueryValueEx(
			hKey,			// handle of key to query
			TEXT("Sources"),// address of name of value to query
			0,				// reserved
			0,				// address of buffer for value type
			0,				// address of data buffer
			&dwSize			// address of data buffer size
			);

		if( lRet == ERROR_SUCCESS ) {
			DWORD dwType;

			DWORD  dwAllocSize = dwSize + sizeof(TCHAR)*(_tcslen(ServiceName)+1)
						+ 2*sizeof(TCHAR); // RegQueryValueEx may return non null-terminated string

			LPBYTE Buffer = LPBYTE(::GlobalAlloc(GPTR, dwAllocSize)); // note: allocated mem is zeroed

			lRet =	::RegQueryValueEx(
				hKey,			// handle of key to query
				TEXT("Sources"),// address of name of value to query
				0,				// reserved
				&dwType,		// address of buffer for value type
				Buffer,			// address of data buffer
				&dwSize			// address of data buffer size
				);
			if( lRet == ERROR_SUCCESS ) {

				register LPTSTR p = LPTSTR(Buffer);

				// check that value is terminated with 2 zeroes. Also need prevent growth of key-size.
				// note: allocated buf was zeroed
				int tchar_count = dwSize / sizeof(TCHAR);
				DWORD dwNewSize = dwSize + sizeof(TCHAR)*(_tcslen(ServiceName)+1);
				if (tchar_count < 2 || p[tchar_count - 1] != 0 || p[tchar_count - 2] != 0)
					dwNewSize += 2 * sizeof(TCHAR);

				// check whether this service is already a known source
				for(; *p; p += _tcslen(p)+1 ) {
					if( _tcscmp(p, ServiceName) == 0 )
						break;
				}
				if( ! * p ) {
					// We're standing at the end of the stringarray
					// and the service does still not exist in the "Sources".
					// Now insert it at this point.
					// Note that we have already enough memory allocated
					// (see GlobalAlloc() above). We also don't need to append
					// an additional '\0'. This is done in GlobalAlloc() above
					// too.
					_tcsncpy(p, ServiceName, dwNewSize/sizeof(TCHAR) - (p - (LPTSTR)Buffer));

					// OK - now store the modified value back into the
					// registry.
					lRet =	::RegSetValueEx(
						hKey,			// handle of key to set value for
						TEXT("Sources"),// address of value to set
						0,				// reserved
						dwType,			// flag for value type
						Buffer,			// address of value data
						dwNewSize		// size of value data
						);
				}
			}

			::GlobalFree(HGLOBAL(Buffer));
		}

		::RegCloseKey(hKey);
	}
}
コード例 #4
0
ファイル: eventlog.cpp プロジェクト: tigtigtig/ndas4windows
BOOL CEventLog::DeregisterFromApplicationLog(LPCTSTR szSourceName)
{
	TCHAR szKey[260];
	HKEY hKey = 0;
	LONG lRet = ERROR_SUCCESS;
	HRESULT hr;

	hr = StringCchPrintf(
		szKey, 
		260, 
		_T("%s\\%s"), 
		REGSTR_PATH_APPLICATION_EVENTLOG, 
		szSourceName);

	lRet = ::RegDeleteKey(HKEY_LOCAL_MACHINE, szKey);

	// now we have to delete the application from the "Sources" value too.
	lRet =	::RegOpenKeyEx( 
		HKEY_LOCAL_MACHINE,	// handle of open key 
		REGSTR_PATH_APPLICATION_EVENTLOG, // address of name of subkey to open 
		0,					// reserved 
		KEY_ALL_ACCESS,		// security access mask 
		&hKey				// address of handle of open key 
		);
	if ( lRet == ERROR_SUCCESS ) {
		DWORD dwSize;

		// retrieve the size of the needed value
		lRet =	::RegQueryValueEx(
			hKey,			// handle of key to query 
			TEXT("Sources"),// address of name of value to query 
			0,				// reserved 
			0,				// address of buffer for value type 
			0,				// address of data buffer 
			&dwSize			// address of data buffer size 
			);

		if ( lRet == ERROR_SUCCESS ) {
			DWORD dwType;
			LPBYTE Buffer = LPBYTE(::GlobalAlloc(GPTR, dwSize));
			LPBYTE NewBuffer = LPBYTE(::GlobalAlloc(GPTR, dwSize));

			lRet =	::RegQueryValueEx(
				hKey,			// handle of key to query 
				TEXT("Sources"),// address of name of value to query 
				0,				// reserved 
				&dwType,		// address of buffer for value type 
				Buffer,			// address of data buffer 
				&dwSize			// address of data buffer size 
				);
			if ( lRet == ERROR_SUCCESS ) {
				XTLASSERT(dwType == REG_MULTI_SZ);

				// check whether this service is already a known source
				register LPTSTR p = LPTSTR(Buffer);
				register LPTSTR pNew = LPTSTR(NewBuffer);
				BOOL bNeedSave = FALSE;	// assume the value is already correct
				for (; *p; p += _tcslen(p)+1) {
					// except ourself: copy the source string into the destination
					if ( _tcscmp(p, szSourceName) != 0 ) {
						StringCbCopy(pNew, dwSize, p);
						pNew += _tcslen(pNew)+1;
					} else {
						bNeedSave = TRUE;		// *this* application found
						dwSize -= (DWORD) _tcslen(p)+1;	// new size of value
					}
				}
				if ( bNeedSave ) {
					// OK - now store the modified value back into the
					// registry.
					lRet =	::RegSetValueEx(
						hKey,			// handle of key to set value for
						TEXT("Sources"),// address of value to set
						0,				// reserved
						dwType,			// flag for value type
						NewBuffer,		// address of value data
						dwSize			// size of value data
						);
				}
			}

			::GlobalFree(HGLOBAL(Buffer));
			::GlobalFree(HGLOBAL(NewBuffer));
		}

		::RegCloseKey(hKey);
	}
	return TRUE;
}
コード例 #5
0
ファイル: eventlog.cpp プロジェクト: tigtigtig/ndas4windows
BOOL CEventLog::RegisterToApplicationLog(
	LPCTSTR szSourceName, 
	LPCTSTR szFileName, 
	DWORD dwTypes)
{
	TCHAR szKey[260];
	HKEY hKey = 0;
	LONG lRet = ERROR_SUCCESS;
	HRESULT hr;

	hr = ::StringCchPrintf(
		szKey, 
		260, 
		_T("%s\\%s"), 
		REGSTR_PATH_APPLICATION_EVENTLOG, 
		szSourceName);

	// Create a key for that application and insert values for
	// "EventMessageFile" and "TypesSupported"
	if ( ::RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) == ERROR_SUCCESS )
	{
		lRet = ::RegSetValueEx(
			hKey,						// handle of key to set value for
			TEXT("EventMessageFile"),	// address of value to set
			0,							// reserved
			REG_EXPAND_SZ,				// flag for value type
			(CONST BYTE*)szFileName,	// address of value data
			(DWORD) _tcslen(szFileName) + 1	// size of value data
			);

		// Set the supported types flags.
		lRet = ::RegSetValueEx(
			hKey,					// handle of key to set value for
			TEXT("TypesSupported"),	// address of value to set
			0,						// reserved
			REG_DWORD,				// flag for value type
			(CONST BYTE*)&dwTypes,	// address of value data
			sizeof(DWORD)			// size of value data
			);
		::RegCloseKey(hKey);
	}

	// Add the service to the "Sources" value

	lRet =	::RegOpenKeyEx( 
		HKEY_LOCAL_MACHINE,	// handle of open key 
		REGSTR_PATH_APPLICATION_EVENTLOG, // address of name of subkey to open 
		0,					// reserved 
		KEY_ALL_ACCESS,		// security access mask 
		&hKey				// address of handle of open key 
		);
	if ( lRet == ERROR_SUCCESS ) {
		DWORD dwSize;

		// retrieve the size of the needed value
		lRet =	::RegQueryValueEx(
			hKey,			// handle of key to query 
			TEXT("Sources"),// address of name of value to query 
			0,				// reserved 
			0,				// address of buffer for value type 
			0,				// address of data buffer 
			&dwSize			// address of data buffer size 
			);

		if ( lRet == ERROR_SUCCESS ) {
			DWORD dwType;
			DWORD dwNewSize = dwSize+_tcslen(szSourceName)+1;
			LPBYTE Buffer = LPBYTE(::GlobalAlloc(GPTR, dwNewSize));

			lRet =	::RegQueryValueEx(
				hKey,			// handle of key to query 
				TEXT("Sources"),// address of name of value to query 
				0,				// reserved 
				&dwType,		// address of buffer for value type 
				Buffer,			// address of data buffer 
				&dwSize			// address of data buffer size 
				);
			if ( lRet == ERROR_SUCCESS ) {
				XTLASSERT(dwType == REG_MULTI_SZ);

				// check whether this service is already a known source
				register LPTSTR p = LPTSTR(Buffer);
				for (; *p; p += _tcslen(p)+1 ) {
					if ( _tcscmp(p, szSourceName) == 0 )
						break;
				}
				if ( ! * p ) {
					// We're standing at the end of the stringarray
					// and the service does still not exist in the "Sources".
					// Now insert it at this point.
					// Note that we have already enough memory allocated
					// (see GlobalAlloc() above). We also don't need to append
					// an additional '\0'. This is done in GlobalAlloc() above
					// too.
					StringCbCopy(p, dwNewSize, szSourceName);

					// OK - now store the modified value back into the
					// registry.
					lRet =	::RegSetValueEx(
						hKey,			// handle of key to set value for
						TEXT("Sources"),// address of value to set
						0,				// reserved
						dwType,			// flag for value type
						Buffer,			// address of value data
						dwNewSize		// size of value data
						);
				}
			}

			::GlobalFree(HGLOBAL(Buffer));
		}

		::RegCloseKey(hKey);
	}

	return TRUE;
}
コード例 #6
0
ファイル: Preinst.cpp プロジェクト: csowter/winuac2
BOOL
InitializeOptions
(
    IN      LPSTR   lpCmdLine
)
{
    BOOL Success1 = FALSE;
    BOOL Success2 = FALSE;

    DWORD ArgC = 0;

    LPTSTR * ArgV = CommandLineToArgv(lpCmdLine, &ArgC);

    if (ArgV)
    {
        for (DWORD i=0; i<ArgC; i++)
        {
            if (_stricmp(ArgV[i], "/s")==0)
            {
                OptionSilent = TRUE;
            }
            else if (_stricmp(ArgV[i],"/silent")==0)
            {
                OptionSilent = TRUE;
            }
            else if (_stricmp(ArgV[i],"/path")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    strcpy(InfPath, ArgV[i+1]);

                    Success1 = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/path:relative")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    GetCurrentDirectory(MAX_PATH, InfPath);
                    strcat(InfPath, "\\");
                    strcat(InfPath, ArgV[i+1]);

                    Success1 = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/ddinstall")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    strcpy(DDInstallSection, ArgV[i+1]);

                    Success2 = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/os")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    strcpy(ExpectedOsVersion, ArgV[i+1]);

                    OptionOsVersionCheck = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/buildnumber")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    ExpectedOsBuildNumber = atoi(ArgV[i+1]);

                    OptionOsBuildNumberCheck = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/sp")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    ExpectedOsServicePack = atoi(ArgV[i+1]);

                    OptionOsServicePackCheck = TRUE;
                    i++;
                }
            }
        }

        GlobalFree(HGLOBAL(ArgV));
    }

    return (Success1 && Success2);
}