December 2001/Hiding Directories in Windows 95/98/ME
Example 4: Loading the device driver and logging on as Guest
BOOL LoadTheVxD(void)
{
DWORD dwErrorCode;
char *UserInfo[2] = {{"Guest"}, {"Test"}};
char cPath[MAX_PATH], *cPathTmp;
strcpy(cPath, GetCommandLine());
cPathTmp = cPath;
cPathTmp++;
for(i=strlen(cPathTmp); cPathTmp[i] != '\\'; i--)
;
cPathTmp[++i]=0;
strcat(cPathTmp, "Protector.dat");
strcpy(cPath, cPathTmp);
// Dynamically load and prepare to call CVXDSAMP
// The CREATE_NEW flag is not necessary
hCVxD = CreateFile("\\\\.\\PROTECT.VXD", 0,0,0,
CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
if ( hCVxD == INVALID_HANDLE_VALUE )
{
dwErrorCode = GetLastError();
if ( dwErrorCode == ERROR_NOT_SUPPORTED )
{
MessageBox(NULL, "Unable to open VxD,\nDevice does not support
DeviceIOCTL", "Protector Login", MB_OK);
}
else
{
MessageBox(NULL,"Unable to open VxD\n", "Protector Login", MB_OK);
}
return FALSE;
}
else
{
if(!DeviceIoControl(hCVxD, FILE_MEM_OPEN,
(LPVOID)cPath, 4,
(LPVOID)RetInfo, sizeof(RetInfo),
&cbBytesReturned, NULL)){
MessageBox(NULL, "Unable to open file Protector.dat!",
"Protector Login", MB_OK);
CloseHandle(hCVxD);
return FALSE;
}
if(!DeviceIoControl(hCVxD, CHANGE_USER,
(LPVOID)UserInfo, sizeof(UserInfo),
(LPVOID)RetInfo, sizeof(RetInfo),
&cbBytesReturned, NULL)){
MessageBox(NULL, "Unable to logon the user!", "Protector
Login", MB_OK);
CloseHandle(hCVxD);
return FALSE;
}
DeviceIoControl(hCVxD, INSTALL_HOOK,
(LPVOID)NULL, 0,
(LPVOID)RetInfo, sizeof(RetInfo),
&cbBytesReturned, NULL);
}
return(TRUE);
}