- wcsncpy(ProfilePath, DriverRegistryPath->Buffer, AfterControlSet - DriverRegistryPath->Buffer);
- wcscpy(ProfilePath + (AfterControlSet - DriverRegistryPath->Buffer), Insert1);
- wcscat(ProfilePath, AfterControlSet);
- wcscat(ProfilePath, Insert2);
-
- Valid = NT_SUCCESS(RtlCheckRegistryKey(RTL_REGISTRY_ABSOLUTE, ProfilePath));
+ /* Build device path */
+ wcsncpy(DeviceRegistryPath->Buffer,
+ DriverRegistryPath->Buffer,
+ AfterControlSet.Buffer - DriverRegistryPath->Buffer);
+ DeviceRegistryPath->Length = (AfterControlSet.Buffer - DriverRegistryPath->Buffer) * sizeof(WCHAR);
+ RtlAppendUnicodeToString(DeviceRegistryPath, Insert1);
+ RtlAppendUnicodeStringToString(DeviceRegistryPath, &AfterControlSet);
+ RtlAppendUnicodeToString(DeviceRegistryPath, Insert2);
+
+ /* Check if registry key exists */
+ Valid = NT_SUCCESS(RtlCheckRegistryKey(RTL_REGISTRY_ABSOLUTE, DriverRegistryPath->Buffer));
+
+ if(!Valid)
+ ExFreePoolWithTag(DeviceRegistryPath->Buffer, TAG_VIDEO_PORT);