📄 freeotfe4pdaregistry.c
字号:
{
DEBUGOUTLIB(DEBUGLEV_ERROR, (TEXT("Failed to open active driers key: %s\n"), REGKEY_DRIVERS_ACTIVE));
}
else
{
cntFound = 0;
dwIndex = 0;
tmpBufSize = sizeof(buffer);
while (RegEnumKeyEx(
hKey,
dwIndex,
buffer,
&tmpBufSize,
NULL,
NULL,
NULL,
NULL
) == ERROR_SUCCESS)
{
tmpEnumFullKey = calloc(
(
wcslen(REGKEY_DRIVERS_ACTIVE)+
wcslen(REGKEY_SEPARATOR)+
wcslen(buffer)+
1 // NULL terminator
),
sizeof(*tmpEnumFullKey)
);
if (tmpEnumFullKey == NULL)
{
DEBUGOUTLIB(DEBUGLEV_ERROR, (TEXT("Unable to calloc memory for registry key\n")));
}
else
{
wcscpy(tmpEnumFullKey, REGKEY_DRIVERS_ACTIVE);
wcscat(tmpEnumFullKey, REGKEY_SEPARATOR);
wcscat(tmpEnumFullKey, buffer);
if (RegDetailsGetActiveByKey(
tmpEnumFullKey,
//TRUE,
&currDetailsActive
))
{
returningDetails = FALSE;
if (currDetailsActive.Mountpoint != NULL)
{
cntFound++;
if (
(detailsActiveSize > 0) &&
(detailsActive != NULL)
)
{
// If we still have enough buffer left...
if ((DWORD)cntFound <= (detailsActiveSize / sizeof(*detailsActive)))
{
detailsActive[(cntFound-1)] = currDetailsActive;
returningDetails = TRUE;
bufferUsed += sizeof(currDetailsActive);
// If the buffer can't store any more, not
// point in continuing...
if (bufferUsed >= detailsActiveSize)
{
break;
}
}
}
}
// Free off unused structure, if it's not being returned...
if (!(returningDetails))
{
RegDetailsFree(
NULL,
NULL,
&currDetailsActive
);
}
}
SecZeroAndFreeWCHARMemory(tmpEnumFullKey);
}
// Setup ready for next...
dwIndex++;
// Reset, as changed by the call to RegEnumKeyEx(...)
tmpBufSize = sizeof(buffer);
}
RegCloseKey(hKey);
}
DEBUGOUTLIB(DEBUGLEV_EXIT, (TEXT("RegDetailsGetAllActive\n")));
return cntFound;
}
// =========================================================================
BOOL RegAssociateFileExtension(
WCHAR* FileExtension, // *Without* leading "."
WCHAR* FileType, // Short descriptor
WCHAR* FileDescription,
WCHAR* OpenCommand,
WCHAR* IconFile,
int IconID
)
{
BOOL retval;
HKEY hKey;
DWORD lpdwDisposition;
WCHAR tmpRegPath[1024];
WCHAR tmpDefaultIconID[1024];
retval = TRUE;
if (retval)
{
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_EXTN,
FileExtension
);
retval = (RegCreateKeyEx(
REGHIVE_FILEASSOC,
tmpRegPath,
0,
TEXT(""), // Class
0,
0,
NULL,
&hKey,
&lpdwDisposition
) == ERROR_SUCCESS);
if (retval)
{
retval = retval && RegistrySetString(
hKey,
NULL,
FileType
);
RegCloseKey(hKey);
}
}
if (retval)
{
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_FILETYPE,
FileType
);
retval = (RegCreateKeyEx(
REGHIVE_FILEASSOC,
tmpRegPath,
0,
TEXT(""), // Class
0,
0,
NULL,
&hKey,
&lpdwDisposition
) == ERROR_SUCCESS);
if (retval)
{
retval = retval && RegistrySetString(
hKey,
NULL,
FileDescription
);
RegCloseKey(hKey);
}
}
if (retval)
{
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_COMMAND,
FileType
);
retval = (RegCreateKeyEx(
REGHIVE_FILEASSOC,
tmpRegPath,
0,
TEXT(""), // Class
0,
0,
NULL,
&hKey,
&lpdwDisposition
) == ERROR_SUCCESS);
if (retval)
{
retval = retval && RegistrySetString(
hKey,
NULL,
OpenCommand
);
RegCloseKey(hKey);
}
}
if (retval)
{
if (IconFile != NULL)
{
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_DEFAULTICON,
FileType
);
retval = (RegCreateKeyEx(
REGHIVE_FILEASSOC,
tmpRegPath,
0,
TEXT(""), // Class
0,
0,
NULL,
&hKey,
&lpdwDisposition
) == ERROR_SUCCESS);
}
if (retval)
{
_snwprintf(
tmpDefaultIconID,
(sizeof(tmpDefaultIconID) / sizeof(tmpDefaultIconID[0])),
REGKEY_FILEASSOC_DEFAULTICON,
IconFile,
IconID
);
retval = retval && RegistrySetString(
hKey,
NULL,
tmpDefaultIconID
);
RegCloseKey(hKey);
SecZeroMemory(tmpDefaultIconID, sizeof(tmpDefaultIconID));
}
}
SecZeroMemory(tmpRegPath, sizeof(tmpRegPath));
if (!(retval))
{
RegDisassociateFileExtension(FileExtension, FileType);
}
return retval;
}
// =========================================================================
void RegDisassociateFileExtension(
WCHAR* FileExtension, // *Without* leading "."
WCHAR* FileType // Short descriptor
)
{
WCHAR tmpRegPath[1024];
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_EXTN,
FileExtension
);
if (RegDeleteKey(
REGHIVE_FILEASSOC,
tmpRegPath
) != ERROR_SUCCESS)
{
DEBUGOUTLIB(DEBUGLEV_INFO, (TEXT("Failed to %s registry key\n"), tmpRegPath));
}
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_FILETYPE,
FileType
);
if (RegDeleteKey(
REGHIVE_FILEASSOC,
tmpRegPath
) != ERROR_SUCCESS)
{
DEBUGOUTLIB(DEBUGLEV_INFO, (TEXT("Failed to %s registry key\n"), tmpRegPath));
}
}
// =========================================================================
// Either "FileExtension" or "FileType" may have NULL passed to disregard
// Returns: TRUE if *either* of the passed in parameters are set in the
// registry
BOOL RegIsFileExtensionAssociated(
WCHAR* FileExtension, // *Without* leading "."
WCHAR* FileType // Short descriptor
)
{
BOOL retval;
HKEY hKey;
WCHAR tmpRegPath[1024];
retval = FALSE;
if (!(retval))
{
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_EXTN,
FileExtension
);
if (RegOpenKeyEx(
REGHIVE_FILEASSOC,
tmpRegPath,
0,
0,
&hKey
) == ERROR_SUCCESS)
{
RegCloseKey(hKey);
retval = TRUE;
}
}
if (!(retval))
{
_snwprintf(
tmpRegPath,
(sizeof(tmpRegPath) / sizeof(tmpRegPath[0])),
REGKEY_FILEASSOC_FILETYPE,
FileType
);
if (RegOpenKeyEx(
REGHIVE_FILEASSOC,
tmpRegPath,
0,
0,
&hKey
) == ERROR_SUCCESS)
{
RegCloseKey(hKey);
retval = TRUE;
}
}
return retval;
}
// =========================================================================
// =========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -