📄 install.cpp
字号:
{
bResult = FALSE;
goto EXIT;
}
if (!SetupDiBuildDriverInfoList(hDevInfo, &spDevInfo, SPDIT_CLASSDRIVER))
{
fBuildList = TRUE;
bResult = FALSE;
goto EXIT;
}
memset(&spDrvInfo, 0, sizeof(SP_DRVINFO_DATA));
spDrvInfo.cbSize = sizeof(SP_DRVINFO_DATA);
if (!SetupDiEnumDriverInfo(hDevInfo, &spDevInfo, SPDIT_CLASSDRIVER , 0, &spDrvInfo))
{
bResult = FALSE;
goto EXIT;
}
if (!SetupDiSetSelectedDriver(hDevInfo, &spDevInfo, &spDrvInfo))
{
bResult = FALSE;
goto EXIT;
}
if (!SetupDiCallClassInstaller(DIF_INSTALLDEVICE, hDevInfo, &spDevInfo))
{
bResult = FALSE;
goto EXIT;
}
ZeroMemory(szDeviceID, 255);
if (!SetupDiGetDeviceInstanceId(hDevInfo, &spDevInfo, szDeviceID, 255, NULL))
{
goto EXIT;
}
EXIT:
if (fBuildList)
{
SetupDiDestroyDriverInfoList(hDevInfo, &spDevInfo, SPDIT_CLASSDRIVER);
}
if (hDevInfo != NULL)
{
SetupDiDestroyDeviceInfoList(hDevInfo);
}
return bResult;
}
/*
uninstall bootdisk driver
*/
BOOL CInstall::UnInstallBootDisk()
{
BOOL bResult = TRUE;
HDEVINFO hDevInfo = NULL;
GUID guid;
CString sFullPath;
char szPath[MAX_PATH];
char szClassName[32];
DWORD dwNameSize;
SP_DEVINFO_DATA spDevInfo;
if (1 != CheckBootDiskInstall())
{
return FALSE;
}
GetModuleFileName(NULL, szPath, MAX_PATH);
sFullPath = szPath;
sFullPath = sFullPath.Left(sFullPath.ReverseFind('\\') + 1);
sFullPath += BOOTDISK_INF;
if (m_sDeviceID.IsEmpty())
{
return FALSE;
}
if (!SetupDiGetINFClass(sFullPath, &guid, szClassName, 32, &dwNameSize))
{
return FALSE;
}
hDevInfo = SetupDiCreateDeviceInfoList(&guid, NULL);
if (hDevInfo == INVALID_HANDLE_VALUE)
{
return FALSE;
}
memset(&spDevInfo, 0, sizeof(SP_DEVINFO_DATA));
spDevInfo.cbSize = sizeof(SP_DEVINFO_DATA);
if (!SetupDiOpenDeviceInfo(hDevInfo, m_sDeviceID, NULL, DIOD_INHERIT_CLASSDRVS, &spDevInfo))
{
bResult = FALSE;
goto EXIT;
}
if (!SetupDiRemoveDevice(hDevInfo, &spDevInfo))
{
bResult = FALSE;
goto EXIT;
}
EXIT:
if (hDevInfo != NULL)
{
SetupDiDestroyDeviceInfoList(hDevInfo);
}
return bResult;
}
/*
Install bootewf.sys driver
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE.
*/
BOOL CInstall::EWFInstall()
{
BOOL bRet = TRUE;
DWORD dwRet;
DWORD dwSize;
HKEY hKey = NULL;
BYTE abBuf[256], setBuf[512];
DWORD dwRetSize;
SC_HANDLE hManager = NULL;
SC_HANDLE hService = NULL;
char szDir[MAX_PATH];
CString sDesVal,sSouVal;
OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osver))
{
return FALSE;
}
if (osver.dwMajorVersion < 5)
{
return FALSE;
}
DWORD dwWinVer = osver.dwMinorVersion;
GetModuleFileName(NULL, szDir, MAX_PATH);
sSouVal = szDir;
sSouVal = sSouVal.Left(sSouVal.ReverseFind('\\'));
sSouVal += "\\";
sSouVal += BOOTEWF_FILE;
dwRetSize = GetWindowsDirectory(szDir, MAX_PATH+1);
sDesVal = szDir;
if (sDesVal.GetLength() > 3) sDesVal += "\\";
sDesVal += BOOTEWF_PATH;
if (!CopyFile(sSouVal, sDesVal, FALSE))
{
return FALSE;
}
memset(abBuf, 0, 256);
memset(setBuf, 0, 512);
hManager = OpenSCManager(NULL, NULL, GENERIC_READ | GENERIC_WRITE);
if (hManager == NULL)
{
bRet = FALSE;
goto EXIT;
}
//open Service
hService = OpenService(hManager, BOOTEWF_NAME, SERVICE_ALL_ACCESS | GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
if (hService == NULL)
{
if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
{
bRet = FALSE;
goto EXIT;
}
}
if(hService == NULL)
{
// create service
hService = CreateService(hManager, BOOTEWF_NAME, BOOTEWF_DESCRIPTION, SERVICE_ALL_ACCESS | GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE,
SERVICE_KERNEL_DRIVER, SERVICE_BOOT_START, SERVICE_ERROR_NORMAL,
BOOTEWF_PATH, BOOTEWF_GROUP, NULL, NULL, NULL, NULL);
if (hService == NULL)
{
bRet = FALSE;
goto EXIT;
}
}else
{
if (ChangeServiceConfig(hService, SERVICE_KERNEL_DRIVER, SERVICE_BOOT_START, SERVICE_ERROR_NORMAL,
BOOTEWF_PATH, BOOTEWF_GROUP, NULL, NULL, NULL, NULL, BOOTEWF_DESCRIPTION) == FALSE)
{
if (GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE)
{
// reboot
bRet = FALSE;
goto EXIT;
}
bRet = FALSE;
goto EXIT;
}
}
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, BOOTEWF_CLASS_ID, 0, KEY_READ | KEY_WRITE, &hKey);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
if (dwWinVer == 1)
{
dwSize = 256;
dwRet = RegQueryValueEx(hKey, BOOTEWF_FILTER, NULL, NULL, abBuf, &dwSize);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
memcpy(setBuf, BOOTEWF_NAME, 7);
memcpy(&setBuf[9], abBuf, dwSize);
dwSize += 9;
}else
{
memset(setBuf, 0, 512);
memcpy(setBuf, BOOTEWF_NAME, 7);
dwSize = 9;
}
if (dwWinVer == 2)//2003 server
{
dwRet = RegSetValueEx(hKey, CDX_PFC_FILTER, 0, REG_MULTI_SZ, setBuf, dwSize);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
}else
{
dwRet = RegSetValueEx(hKey, BOOTEWF_FILTER, 0, REG_MULTI_SZ, setBuf, dwSize);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
}
EXIT:
if (hManager != NULL)
{
CloseServiceHandle(hManager);
}
if (hService != NULL)
{
CloseServiceHandle(hService);
}
if (hKey != NULL)
{
RegCloseKey(hKey);
}
return bRet;
}
/*
uninstall bootewf driver
*/
BOOL CInstall::UnInstallEWF()
{
BOOL bRet = TRUE;
DWORD dwRet;
HKEY hKey = NULL;
CString szName = "bootewf";
SC_HANDLE hManager = NULL;
SC_HANDLE hService = NULL;
char szDir[MAX_PATH];
CString sDesVal,sSouVal;
OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osver))
{
return FALSE;
}
if (osver.dwMajorVersion < 5)
{
return FALSE;
}
DWORD dwWinVer = osver.dwMinorVersion;
hManager = OpenSCManager(NULL, NULL, GENERIC_READ | GENERIC_WRITE);
if (hManager == NULL)
{
bRet = FALSE;
goto EXIT;
}
hService = OpenService(hManager, BOOTEWF_NAME, SERVICE_ALL_ACCESS | GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
if (hService == NULL)
{
if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
{
bRet = FALSE;
goto EXIT;
}
}
if(hService != NULL)
{
if (ERROR_SERVICE_MARKED_FOR_DELETE == DeleteService(hService))
{
bRet = TRUE;
goto EXIT;
}
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, BOOTEWF_CLASS_ID, 0, KEY_READ | KEY_WRITE, &hKey);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
if (dwWinVer == 1)//XP
{
BYTE abBuf[512];
DWORD dwSize = 512 - 8;
memset(abBuf, 0, 512);
dwRet = RegQueryValueEx(hKey, BOOTEWF_FILTER, NULL, 0, abBuf, &dwSize);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
DWORD j;
for(DWORD i = 0; i < dwSize; i++)
{
if (memcmp(abBuf + i, BOOTEWF_NAME, 7) == 0)
{
for (j = i + 7; j < dwSize; j++)
{
if (abBuf[j] != 0)
{
break;
}
}
CopyMemory(abBuf + i, abBuf + j, dwSize - j);
dwSize -= j - i;
}
}
dwRet = RegSetValueEx(hKey, BOOTEWF_FILTER, 0, REG_MULTI_SZ, abBuf, dwSize);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
}else if(dwWinVer == 0)//2K
{
dwRet = RegDeleteValue(hKey, BOOTEWF_FILTER);
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
}else if(dwWinVer == 2)//2003
{
dwRet = RegDeleteValue(hKey, _T("LowerFilters"));
if (dwRet != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
}
}
GetWindowsDirectory(szDir, MAX_PATH+1);
sDesVal = szDir;
if (sDesVal.GetLength() > 3) sDesVal += "\\";
sDesVal += BOOTEWF_PATH;
DeleteFile(sDesVal);
EXIT:
if (hManager != NULL)
{
CloseServiceHandle(hManager);
}
if (hService != NULL)
{
CloseServiceHandle(hService);
}
if (hKey != NULL)
{
RegCloseKey(hKey);
}
return bRet;
}
/*
Modify
SYSTEM\\CurrentControlSet\\Services\\Cdrom\\start
SYSTEM\\CurrentControlSet\\Services\\Imapi\\start
SYSTEM\\CurrentControlSet\\Services\\redbook\\start
*/
BOOL CInstall::ModifyReg(DWORD dwVal)
{
HKEY hKey = NULL;
LONG lResult;
BOOL bRet = TRUE;
OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!GetVersionEx(&osver))
{
return FALSE;
}
if (osver.dwMajorVersion < 5)
{
return FALSE;
}
BOOL fWin2K = osver.dwMinorVersion == 0 ? TRUE : FALSE;
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, REG_CDROM, &hKey);
if (lResult != ERROR_SUCCESS)
{
return FALSE;
}
lResult = RegSetValueEx(hKey, "Start", 0, REG_DWORD, (BYTE*)&dwVal, sizeof(DWORD));
if (lResult != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
RegCloseKey(hKey);
hKey = NULL;
if (!fWin2K)
{
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, REG_IMAPI, &hKey);
if (lResult != ERROR_SUCCESS)
{
return FALSE;
}
lResult = RegSetValueEx(hKey, "Start", 0, REG_DWORD, (BYTE*)&dwVal, sizeof(DWORD));
if (lResult != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
RegCloseKey(hKey);
hKey = NULL;
}
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, REG_REDBOOK, &hKey);
if (lResult != ERROR_SUCCESS)
{
return FALSE;
}
lResult = RegSetValueEx(hKey, "Start", 0, REG_DWORD, (BYTE*)&dwVal, sizeof(DWORD));
if (lResult != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
RegCloseKey(hKey);
hKey = NULL;
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, REG_PFC, &hKey);
if (lResult != ERROR_SUCCESS)
{
return FALSE;
}
lResult = RegSetValueEx(hKey, "Start", 0, REG_DWORD, (BYTE*)&dwVal, sizeof(DWORD));
if (lResult != ERROR_SUCCESS)
{
bRet = FALSE;
goto EXIT;
}
EXIT:
if (hKey != NULL)
{
RegCloseKey(hKey);
}
return bRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -