Hi!
I am a newbie to writing drivers. So i started with a NT style KernelMode
Driver. I followed some MS articles on how to load this driver using SCM.
I followed the following code sequence…
bool CDriverInstall::InstallDriver ()
{
SC_HANDLE hSCMService = NULL;
SERVICE_STATUS status;
DWORD dwError = 0;
::CloseServiceHandle (m_hSCMHandle);
m_hSCMHandle = ::OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
// Create the service.
hSCMService = ::CreateService (
m_hSCMHandle, // Handle To SCM
m_strDriverName, // Name of service to start
m_strDriverName, // Display name
SERVICE_ALL_ACCESS, // Access rights
SERVICE_KERNEL_DRIVER,// Type of service
SERVICE_DEMAND_START, // Mode of start
// SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL, // Severity of error failure
m_strDriverFilePath, // Binary path name
NULL, // Load ordering group
NULL, // Tag identifier
NULL, // Dependencies
NULL, // LocalSystem account
NULL // Password
);
if (NULL == hSCMService)
{
TRACE (_T (“Failed to create service - %s in SCM\n”), m_strDriverName);
return false;
}
if (0 == ::StartService (hSCMService, 0, NULL))
{
dwError = ::GetLastError ();
if (dwError == ERROR_PATH_NOT_FOUND)
{
TRACE (_T (“Path not found\n”));
}
if (dwError == ERROR_INVALID_HANDLE)
{
TRACE (_T (“Invalid handle\n”));
}
if (dwError == ERROR_SERVICE_DISABLED)
{
TRACE (_T (“Service Disabled\n”));
}
if (dwError == ERROR_ACCESS_DENIED)
{
TRACE (_T (“Access denied\n”));
}
}
Sleep (1000);
int nTries = 0;
while (true)
{
if (::QueryServiceStatus (hSCMService, &status))
{
if (status.dwCurrentState == SERVICE_RUNNING)
{
break;
}
nTries++;
Sleep (1000);
if (nTries > 5)
{
break;
}
}
else
{
break;
}
}
// Query the service status.
if (::QueryServiceStatus (hSCMService, &status))
{
if (status.dwServiceType == SERVICE_KERNEL_DRIVER)
{
TRACE (_T(“Service is Kernel Mode Driver\n”));
}
if (status.dwCurrentState == SERVICE_RUNNING)
{
TRACE (_T (“Service is running\n”));
}
if (status.dwCurrentState == SERVICE_STOPPED)
{
TRACE (_T (“Service is stopped\n”));
}
if (status.dwCurrentState == SERVICE_START_PENDING)
{
TRACE (_T (“Service is starting\n”));
}
}
// Make sure that service handle is closed.
::CloseServiceHandle (hSCMService);
return true;
}
But evry time i try this piece of code to start my driver, the call to
StartService API returns with an error and GetLastError gives me error code
2. That says, file does not exist.
I am working with Admin previleges on the machine.
Could someone please help me in getting over this hump of StartService? Any
help will be much appreciated.
Thanks!
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com