Powered By Blogger
Saturday, October 25, 2008

Controlling a Stream Interface Driver

Special thanks to Bruce Eitman

/*
* Function to query the active drivre list using a search string
*/
VOID QueryDriver (const WCHAR* lpcParam)
{
DEVMGR_DEVICE_INFORMATION devmgrInfo;
devmgrInfo.dwSize=sizeof(DEVMGR_DEVICE_INFORMATION);
HANDLE hDevRes = FindFirstDevice (DeviceSearchByDeviceName, lpcParam,
&devmgrInfo);
if (INVALID_HANDLE_VALUE != hDevRes)
{
do
{
DBG_PRINT(_T("%d , %d , %s, %s, %s, %s\n"),
devmgrInfo.hDevice,
devmgrInfo.hParentDevice,
devmgrInfo.szLegacyName,
devmgrInfo.szDeviceKey,
devmgrInfo.szDeviceName,
devmgrInfo.szLegacyName );
}while (FindNextDevice(hDevRes,&devmgrInfo));
FindClose (hDevRes);
}
else
{
DWORD dwErrorCode = GetLastError();
DBG_PRINT(_T("QueryDriver , code: %d\n"),dwErrorCode);
}
return;
}


--------------------
/*
* Function to load a driver, when provided the driver registry key
*/
VOID LoadDriver (const WCHAR* lpcParam)
{
HANDLE hDriverShell = INVALID_HANDLE_VALUE;
hDriverShell = ActivateDeviceEx( lpcParam,NULL,0,NULL);

if (hDriverShell != INVALID_HANDLE_VALUE && hDriverShell != 0)
{
}
else
{
DWORD dwErrorCode = GetLastError();
DBG_PRINT(TEXT("LoadDriver: Failed to activate driver %d\n"), GetLastError() );
}
return;
}

--------------------
/*
* Function to unload a driver, when provided the diver name
*/
VOID UnloadDriver (const WCHAR* lpcParam)
{
DEVMGR_DEVICE_INFORMATION devmgrInfo;
devmgrInfo.dwSize=sizeof(DEVMGR_DEVICE_INFORMATION);
HANDLE hDevRes = FindFirstDevice (DeviceSearchByDeviceName, lpcParam,
&devmgrInfo);
if (INVALID_HANDLE_VALUE != hDevRes)
{
do
{
DeactivateDevice(devmgrInfo.hDevice);
}while (FindNextDevice(hDevRes,&devmgrInfo));
FindClose (hDevRes);
}
else
{
DWORD dwErrorCode = GetLastError();
DBG_PRINT(_T("QueryDriver , code: %d\n"),dwErrorCode);
}
return;
}

--------------------

0 comments: