HOWTO: IntelliMouse: How To Add an Application to the Exceptions List During InstallationID: Q237614
|
This article describes how to add an application to the Exceptions for Universal Scrolling list (exceptions list) during installation.
Code to enumerate HKEY_CURRENT_USER\Control Panel\Microsoft Input Devices\Mouse\Exceptions:
// ExList.cpp
// Sample code for adding an exception to the IntelliPoint Universal Scrolling Exceptions list.
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
//
// CONSTANTS
//
#define BUFFER_LENGTH 256
#define UNISCROLL_SUBKEY "Control Panel\\Microsoft Input Devices\\Mouse\\Exceptions"
#define REG_UNISCROLL_FILENAME "Filename"
#define REG_UNISCROLL_FILEVER "Version"
#define REG_UNISCROLL_FILEDESC "Description"
#define FIRST_ISV_KEY 1000
#define FIRST_USER_KEY 2000
#define HIDDEN_EXCEPTION_VERSION_MASK 0x7FFFFFFF
DWORD WINAPI AddException(
LPTSTR szExeName, //File name of .exe to add.
LPTSTR szDesc, //Size of description. buffer
SHORT sMajorVer, //Major version of product.
SHORT sMinorVer); //Minor version of product.
int main(int argc, char* argv[])
{
AddException( "Test.exe", "Description of Sample App", 1, 2);
return 0;
}
/****************************************************************************
FUNCTION: AddException()
PURPOSE: This function adds the .exe pointed at to the exception list
PARAMETERS:
RETURNS: ERROR_SUCCESS
other errors returned from the registry
COMMENTS:
****************************************************************************/
DWORD WINAPI AddException(
LPTSTR szExeName, //File name of .exe to add.
LPTSTR szDesc, //Size of description. buffer
SHORT sMajorVer, //Major version of product.
SHORT sMinorVer) //Minor version of product.
{
TCHAR szKeyBuf[BUFFER_LENGTH];
DWORD dwBufLength = sizeof(szKeyBuf);
int iLastKey = FIRST_ISV_KEY;
int iCurKey;
int iEnumIndex = 0;
TCHAR szNewKey[BUFFER_LENGTH];
DWORD dwFileVer;
DWORD dwRetVal;
DWORD dwResult;
HKEY hKey;
//
//Check to see where to insert this into the list.
//
//Open base mouse key.
if (ERROR_SUCCESS == RegOpenKeyEx( (HKEY)HKEY_CURRENT_USER,
UNISCROLL_SUBKEY,
0,
KEY_READ,
&hKey ))
{
//Loop through all exception keys.
while (ERROR_SUCCESS == RegEnumKeyEx( hKey,
iEnumIndex++,
szKeyBuf,
&dwBufLength,
NULL,
NULL,
NULL,
NULL ))
{
//NOTE: To be thorough, you could check here for the existence of
//your .exe already in this list.
iCurKey = _ttoi(szKeyBuf);
//If not user range
if (FIRST_USER_KEY > iCurKey)
{
//Keep track of the last key (for appending).
iLastKey = max( iCurKey, iLastKey );
}
//Reset BufLength.
dwBufLength = sizeof(szKeyBuf);
}//End of while().
RegCloseKey(hKey);
}//end if (RegOpenKeyEx())
//
//Build the necessary strings.
//
//Build our version number.
dwFileVer = MAKELONG( sMinorVer, (HIDDEN_EXCEPTION_VERSION_MASK & sMajorVer) );
//Build our reg key string.
_tcscpy( szNewKey, UNISCROLL_SUBKEY );
_tcscpy( &szNewKey[_tcslen(szNewKey)], "\\" );
//Set our key to number of past last key in this list.
_itot( iLastKey + 1, &szNewKey[_tcslen(szNewKey)], 10);
//
//Add it to the list.
//
if (ERROR_SUCCESS == (dwRetVal = RegCreateKeyEx( (HKEY)HKEY_CURRENT_USER,
szNewKey,
0,
0,
REG_OPTION_NON_VOLATILE,
KEY_SET_VALUE,
0,
&hKey,
&dwResult)))
{
dwRetVal = RegSetValueEx( hKey,
REG_UNISCROLL_FILENAME,
0,
REG_SZ,
(LPBYTE)szExeName,
_tcslen(szExeName));
if (ERROR_SUCCESS == dwRetVal)
{
dwRetVal = RegSetValueEx( hKey,
REG_UNISCROLL_FILEDESC,
0,
REG_SZ,
(LPBYTE)szDesc,
_tcslen(szDesc));
}
if (ERROR_SUCCESS == dwRetVal)
{
dwRetVal = RegSetValueEx( hKey,
REG_UNISCROLL_FILEVER,
0,
REG_DWORD,
(LPBYTE)&dwFileVer,
sizeof(dwFileVer));
}
//Close key.
RegCloseKey(hKey);
}//End of reg stuff.
return dwRetVal;
}
Additional query words: exception
Keywords : kbhw kbDSupport
Version : WINDOWS:1.0,2.2,2.2a,2.2c
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: August 8, 1999