Question : Writing a "hello world" driver for Windows XP

Hi there,

I've written a basic "hello world" driver (under Windows XP) but it doesn't work and I can't figure out why.

I've got a directory C:\drivers\hello in which I created 3 files : hello.c, makefile and sources (see code below). I've built the driver and I get a message saying
      2 files were compiled and
      1 executable built.
and a hello.sys file was created under
      C:\drivers\hello\objchk_wxp_x86\i386
So far, so good.

I've created in the registry a key
      HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/hello
and I've set the values
      DisplayName to hello
      ImagePath to C:\drivers\hello\objchk_wxp_x86\i386\hello.sys
      Start to 3
      Type to 1

But when I type
      net start hello
at the checked build environment command prompt, I've got a message which translates into something like
      The name of the service is not valid.

???

Thanks in advance


------ hello.c ---------
#include

void DriverUnload(PDRIVER_OBJECT pDriverObject)
{
    DbgPrint("Driver unloading\n");
}

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
    DriverObject->DriverUnload = DriverUnload;
      
    DbgPrint("Hello, World\n");
      
    return STATUS_SUCCESS;
}

------ makefile ---------
!INCLUDE $(NTMAKEENV)\makefile.def

------ sources ---------
TARGETNAME = hello
TARGETPATH = obj
TARGETTYPE = DRIVER

INCLUDES   = %BUILD%\inc
LIBS       = %BUILD%\lib

SOURCES    = hello.c

Answer : Writing a "hello world" driver for Windows XP

Simply creating the registry key often isn't enough.   The Microsoft documentation for installing services you've written say to use "InstallUtil", a tool that comes with Visual Studio.

However, if you want to install a service for another type of binary (I'm not sure if it will work with your .sys file) you can use the "SC" command.   e.g. from the command prompt enter :

sc create hello binPath= C:\drivers\hello\objchk_wxp_x86\i386\hello.sys

Note that the space after the = *is* required ... and again, I'm not sure if this will work with a driver.
Random Solutions  
 
programming4us programming4us