[KMTEST]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 10 Sep 2011 14:45:47 +0000 (14:45 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 10 Sep 2011 14:45:47 +0000 (14:45 +0000)
- Load the driver from the application directory, not the current directory

svn path=/trunk/; revision=53672

rostests/kmtests/kmtest/service.c

index 9f32614..7313a1c 100644 (file)
@@ -87,19 +87,19 @@ KmtCreateService(
     assert(ServiceHandle);
     assert(ServiceName && ServicePath);
 
     assert(ServiceHandle);
     assert(ServiceName && ServicePath);
 
-    if (!GetCurrentDirectory(sizeof DriverPath / sizeof DriverPath[0], DriverPath))
+    if (!GetModuleFileName(NULL, DriverPath, sizeof DriverPath / sizeof DriverPath[0]))
         error_goto(Error, cleanup);
 
         error_goto(Error, cleanup);
 
-    if (DriverPath[wcslen(DriverPath) - 1] != L'\\')
-    {
-        DriverPath[wcslen(DriverPath) + 1] = L'\0';
-        DriverPath[wcslen(DriverPath)] = L'\\';
-    }
+    assert(wcsrchr(DriverPath, L'\\') != NULL);
+    wcsrchr(DriverPath, L'\\')[1] = L'\0';
 
     result = StringCbCat(DriverPath, sizeof DriverPath, ServicePath);
     if (FAILED(result))
         error_value_goto(Error, result, cleanup);
 
 
     result = StringCbCat(DriverPath, sizeof DriverPath, ServicePath);
     if (FAILED(result))
         error_value_goto(Error, result, cleanup);
 
+    if (GetFileAttributes(DriverPath) == INVALID_FILE_ATTRIBUTES)
+        error_goto(Error, cleanup);
+
     *ServiceHandle = CreateService(ScmHandle, ServiceName, DisplayName,
                             SERVICE_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
                             SERVICE_ERROR_NORMAL, DriverPath, NULL, NULL, NULL, NULL, NULL);
     *ServiceHandle = CreateService(ScmHandle, ServiceName, DisplayName,
                             SERVICE_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
                             SERVICE_ERROR_NORMAL, DriverPath, NULL, NULL, NULL, NULL, NULL);