Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: map Pin
ratprita29-Dec-09 18:08
ratprita29-Dec-09 18:08 
GeneralRe: map Pin
Tim Craig29-Dec-09 18:11
Tim Craig29-Dec-09 18:11 
GeneralRe: map Pin
KingsGambit29-Dec-09 18:23
KingsGambit29-Dec-09 18:23 
QuestionRe: map Pin
CPallini29-Dec-09 21:18
mveCPallini29-Dec-09 21:18 
AnswerRe: map Pin
ratprita29-Dec-09 21:23
ratprita29-Dec-09 21:23 
GeneralRe: map Pin
CPallini29-Dec-09 22:11
mveCPallini29-Dec-09 22:11 
JokeRe: map Pin
Maxwell Chen29-Dec-09 21:23
Maxwell Chen29-Dec-09 21:23 
QuestionTrouble loading a driver Pin
Mattzimmerer29-Dec-09 13:05
Mattzimmerer29-Dec-09 13:05 
I'm trying to write an exe to load my driver into the kernel, I'm getting an error ERROR_PATH_NOT_FOUND. I know my sys file is in the at this path, what am I missing?

// Loader.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <stdio.h> 

bool LoadDriver();



int _tmain(int argc, _TCHAR* argv[])
{
	bool status;
	status = LoadDriver();


	if (status)
		printf("Driver load Succeeded!\n");
	else
		printf("Driver load Failed!\n");

	return 0;
}

bool LoadDriver()
{
	wchar_t PATH[1024] = L"C:\\DLOADER\\DLOADER\\Debug\\target.sys";
	wchar_t DRIVERNAME[1024] = L"target.sys";
	printf("PATH: %ls\n", PATH);
	printf("DRIVERNAME: %ls\n", DRIVERNAME);
	SC_HANDLE sh = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!sh)
		return false;

	SC_HANDLE rh = CreateService(sh,
		DRIVERNAME,
		DRIVERNAME,
		SERVICE_ALL_ACCESS,
		SERVICE_KERNEL_DRIVER,
		SERVICE_DEMAND_START,
		SERVICE_ERROR_NORMAL,
		PATH,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL);

	if(!rh)
	{
		printf("CreateService Failed(error%i)\n",GetLastError());
		if (GetLastError() == ERROR_SERVICE_EXISTS)
		{
			// service exists
			rh = OpenService(sh,
				DRIVERNAME,
				SERVICE_ALL_ACCESS);
			if(!rh)
			{
				printf("OpenService Failed(error%i)\n",GetLastError());
				CloseServiceHandle(sh);
				return false;
			}
			else
				printf("OpenService Success\n");
		}
		else
		{
			CloseServiceHandle(sh);
			return false;
		}
	}
	// start the drivers
	if(rh)
	{
		if(0 == StartService(rh, 0, NULL))
		{
			printf("StartService Failed(error%i)\n",GetLastError());
			if(ERROR_SERVICE_ALREADY_RUNNING == GetLastError())
			{
				// no real problem
			}
			else
			{
				CloseServiceHandle(sh);
				CloseServiceHandle(rh);
				return false;
			}
		}
		else
			printf("StartService Success\n");
		CloseServiceHandle(sh);
		CloseServiceHandle(rh);
	}
	return true;
}


Here is the output:
PATH: C:\DLOADER\DLOADER\Debug\target.sys
DRIVERNAME: target.sys
CreateService Failed(error1073)
OpenService Success
StartService Failed(error3)
Driver load Failed!



Any help would be appreciated!


Ohh and heres what those error codes are:
ERROR_SERVICE_EXISTS = 1073
ERROR_PATH_NOT_FOUND = 3
AnswerRe: Trouble loading a driver Pin
Maxwell Chen29-Dec-09 19:06
Maxwell Chen29-Dec-09 19:06 
GeneralRe: Trouble loading a driver Pin
Mattzimmerer30-Dec-09 0:48
Mattzimmerer30-Dec-09 0:48 
Question[Message Deleted] Pin
noalias___29-Dec-09 12:55
noalias___29-Dec-09 12:55 
AnswerRe: library link error Pin
Chris Losinger29-Dec-09 12:59
professionalChris Losinger29-Dec-09 12:59 
GeneralRe: library link error Pin
noalias___29-Dec-09 13:16
noalias___29-Dec-09 13:16 
Questionstreambuf out_waiting replacement Pin
ajucker29-Dec-09 6:51
ajucker29-Dec-09 6:51 
QuestionHow can I return a deque from a function? Pin
DanYELL29-Dec-09 5:11
DanYELL29-Dec-09 5:11 
AnswerRe: How can I return a deque from a function? Pin
CPallini29-Dec-09 5:20
mveCPallini29-Dec-09 5:20 
QuestionSaving function pointers in Map Pin
Chanchalgaud29-Dec-09 3:29
Chanchalgaud29-Dec-09 3:29 
AnswerRe: Saving function pointers in Map Pin
Richard MacCutchan29-Dec-09 4:44
mveRichard MacCutchan29-Dec-09 4:44 
AnswerRe: Saving function pointers in Map Pin
Abhi Lahare29-Dec-09 4:58
Abhi Lahare29-Dec-09 4:58 
QuestionAnyway to stop a CView from being closed? Pin
Paul Belikian29-Dec-09 3:25
Paul Belikian29-Dec-09 3:25 
AnswerRe: Anyway to stop a CView from being closed? Pin
David Crow29-Dec-09 3:31
David Crow29-Dec-09 3:31 
GeneralRe: Anyway to stop a CView from being closed? Pin
Paul Belikian29-Dec-09 4:14
Paul Belikian29-Dec-09 4:14 
QuestionRe: Anyway to stop a CView from being closed? Pin
David Crow29-Dec-09 4:21
David Crow29-Dec-09 4:21 
AnswerRe: Anyway to stop a CView from being closed? Pin
Paul Belikian29-Dec-09 6:08
Paul Belikian29-Dec-09 6:08 
GeneralRe: Anyway to stop a CView from being closed? Pin
JudyL_MD29-Dec-09 16:50
JudyL_MD29-Dec-09 16:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.