Reputation: 77
I have a .INF with a security descriptor HKR,,Security,,"D:P(A;;GA;;;SY)(A;;GA;;;BA)".
I changed this security descriptor to remove admin rights. So that any user can open the application. The descriptor I used is "D:P(A;;GA;;;WD)(A;;GA;;;BU)(A;;GA;;;S-1-1-0)" I uninstalled the driver in Device Manager and reinstalled the modified .INF file. However, it doesn't work unless I change the device "class" and "ClassGUID" in the INF file.
I think previously installed security descriptor is not deleted even though I deleted the driver from device manager. I also used devcon to delete the driver. But it didn't delete the device class.
Only way I can make it work is to modify "Class" and "ClassGUID" of the existing .INF file.
How can I remove the device class of the previously installed driver in windows? I am using Windows 7.
Upvotes: 2
Views: 2041
Reputation: 751
Using SetupAPI, you can also just change the SDS. This doesn't directly answer your question, but it does solve the problem of not udating the security descriptor.
static GUID MY_GUID = { 0x91A3EB99, 0x5FB7, 0x4CA4, { 0x83, 0xC9, 0x8E, 0x39, 0xC1, 0x39, 0xEF, 0xE8 } };
SetClassSDS(&MY_GUID);
If you want, you can also just pass in the GUID you retrieved from SetupDiClassGuidsFromNameEx:
SetClassSDS(&cls);
This is my function used above (be sure to use the ACL you want):
void SetClassSDS(GUID* guid)
{
wprintf(L"\tGUID: {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n",
guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2],
guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
const int strSize = 256;
// This discretionary ACL:
// * Deny access to Built-in Guests
// * Deny access to Anonymous Logon
// * Allow read/write/execute to Authenticated Users
// * Allow full control to Administrators
WCHAR newStr[strSize] = L"D:(D;OICI;GA;;;BG)(D;OICI;GA;;;AN)(A;OICI;GRGWGX;;;AU)(A;OICI;GA;;;BA)";
PBYTE str = new BYTE[strSize];
DEVPROPTYPE type;
DWORD reqSize = 0;
if (SetupDiGetClassProperty(guid, &DEVPKEY_DeviceClass_SecuritySDS, &type, str, strSize, &reqSize, DICLASSPROP_INSTALLER))
{
wprintf(L"\tCurrent SDS: %s\n", str);
wprintf(L"\tDesired SDS: %s\n", newStr);
if (SetupDiSetClassProperty(guid, &DEVPKEY_DeviceClass_SecuritySDS, type,
(BYTE*)newStr, sizeof(newStr), DICLASSPROP_INSTALLER))
{
wprintf(L"\n\tSetupDiSetClassProperty succeeded\n\n");
}
else
{
wprintf(L"\tSetupDiSetClassProperty - Error code: 0x%X\n\n", GetLastError());
}
}
else
{
wprintf(L"\tSetupDiGetClassProperty - Error code: 0x%X\n\n", GetLastError());
if (reqSize > strSize)
{
wprintf(L"\tSecurity string too long\n");
}
}
wprintf(L"\n");
delete [] str;
}
You will need the following includes:
#include <initguid.h>
#include <devguid.h>
#include <devpkey.h>
#include <devpropdef.h>
#include <setupapi.h>
You will need to link to this library:
Setupapi.lib
Upvotes: 1
Reputation: 77
I was finally able to finally uninstall the device class using a small C++ program. In the following link, at the end of the site, there is a C++ code which you can delete driver completely including the ClassName Associated with the ClassGUID.
https://www.osronline.com/showthread.cfm?link=168171
I have also copied the same code below as well. I made a small MFC application to perform the uninstallation.
HDEVINFO devs = INVALID_HANDLE_VALUE;
SP_DEVINFO_LIST_DETAIL_DATA devInfoListDetail;
SP_DEVINFO_DATA devInfo;
unsigned int DeviceNo = 0;
GUID cls;
DWORD numClass = 0;
TCHAR devID[MAX_DEVICE_ID_LEN];
SP_REMOVEDEVICE_PARAMS rmdParams;
SetupDiClassGuidsFromNameEx ("ClassName", &cls, 1, &numClass,
NULL, NULL);
devs = SetupDiGetClassDevsEx (&cls, NULL, NULL,
DIGCF_PRESENT, NULL, NULL, NULL);
devInfo.cbSize = sizeof(devInfo);
while (SetupDiEnumDeviceInfo (devs, DeviceNo++, &devInfo))
{
devInfoListDetail.cbSize = sizeof(devInfoListDetail);
if (!SetupDiGetDeviceInfoListDetail (devs, &devInfoListDetail) ||
CM_Get_Device_ID_Ex(devInfo.DevInst, devID,
MAX_DEVICE_ID_LEN/* 200 */, 0,
devInfoListDetail.RemoteMachineHandle))
{
break;
}
rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE;
rmdParams.Scope = DI_REMOVEDEVICE_GLOBAL;
rmdParams.HwProfile = 0;
SetupDiSetClassInstallParams (devs, &devInfo,
&rmdParams.ClassInstallHeader,sizeof
(rmdParams));
SetupDiCallClassInstaller (DIF_REMOVE, devs, &devInfo);
}
SetupDiDestroyDeviceInfoList(devs);
DEVINST devRoot;
if(CM_Locate_DevNode_Ex(&devRoot,NULL,CM_LOCATE_DEVNODE_NORMAL,NULL) !=
CR_SUCCESS) {
goto final;
}
CM_Reenumerate_DevNode_Ex(devRoot, 0, NULL);
final:
return;
}
Upvotes: 1