如何删除永远不会再次用到的设备的注册表信息

在 Microsoft Visual Studio 2012 年,在文件菜单上单击新建,然后单击项目。

在新建项目对话框中,在名称字段中,键入清理,然后双击Win32 项目。

在 Win32 应用程序向导中,单击下一步。

在应用程序类型,选择控制台应用程序,请单击,然后单击完成。

在解决方案资源管理器中,展开源代码文件,用鼠标右键单击Cleanup.cpp,然后单击查看代码。

找到下面的代码:

int _tmain(int argc, _TCHAR* argv[])

{

return 0;

}

替换为以下代码的步骤 6 中发现的代码。

//DevPhantomClnr.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

/**************************************************************************************************/

/* */

/* Copyright (c) 2007 Microsoft Corporation. All Rights Reserved */

/* */

/**************************************************************************************************/

#pragma warning( disable : 4201 ) // nonstandard extension used : nameless strut/union

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define SIZECHARS(x) (sizeof((x))/sizeof(TCHAR))

#define arraysize(p) (sizeof(p)/sizeof((p)[0]))

CONST GUID *DiskClassesToClean[2] = {

&GUID_DEVCLASS_DISKDRIVE,

&GUID_DEVCLASS_VOLUME

};

/**************************************************************************************************/

/* */

/* The user must be member of Administrator group and must have backup and restore permissions */

/* (SE_BACKUP_NAME and SE_RESTORE_NAME). No check for these is performed in this example. */

/* */

/**************************************************************************************************/

int

__cdecl

main(

IN int ArgC,

IN LPCWSTR pArgV[]

)

{

HDEVINFO DeviceInfoSet;

SP_DEVINFO_DATA DeviceInfoData;

ULONG DevicesRemoved = 0,

i,

MemberIndex,

Status,

Problem,

ulClassesToCleanIdx;

BOOL bDoRemove = TRUE;

CONFIGRET cr;

TCHAR DeviceInstanceId[MAX_DEVICE_ID_LEN];

OSVERSIONINFO osvi;

const GUID ** ClassesToClean;

//

// Parse parameters.

//

for (i = 1; i < (ULONG)ArgC; i++) {

//

// Check for help.

//

if ( (lstrcmpi(pArgV[i], L"-?") == 0) ||

(lstrcmpi(pArgV[i], L"/?") == 0) ){

printf("\nDevNodePhantomCleaner will remove phantom storage device nodes from this machine.\n\n");

printf("Usage: nDevNodePhantomCleaner \n");

printf("\tWhere /n displays but does not remove the phantom devnodes.\n");

printf("\nBackup and Restore privileges are required to run this utility.\n");

return 0;

}

//

// Check for -n, which means just list the devices that we would remove.

//

if ( (lstrcmpi(pArgV[i], L"-n") == 0) ||

(lstrcmpi(pArgV[i], L"/n") == 0) ) {

bDoRemove = FALSE;

}

}

//

// Run only on Windows XP/2003 (version 5.1) or later.

//

ZeroMemory(&osvi, sizeof(OSVERSIONINFO));

osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

if (!GetVersionEx(&osvi)) {

printf("DevNodePhantomCleaner: Unable to verify Windows version, exiting...\n");

return -1;

}

if ((osvi.dwMajorVersion == 5) &&

((osvi.dwMinorVersion == 1) || (osvi.dwMinorVersion == 2))) {

// 5.1 || 5.2

}

else if (osvi.dwMajorVersion>=6) {

//Nothing special on 6.x

}

else

{

printf("DevNodePhantomCleaner: This utility is designed to run on Windows XP/2003 and later\n");

return -1;

}

ClassesToClean = DiskClassesToClean;

ulClassesToCleanIdx = arraysize(DiskClassesToClean);

for (i=0; (i

DeviceInfoSet = SetupDiGetClassDevs(ClassesToClean[i],

NULL,

NULL,

0

);

if (INVALID_HANDLE_VALUE!=DeviceInfoSet) {

DeviceInfoData.cbSize = sizeof(DeviceInfoData);

MemberIndex = 0;

while (SetupDiEnumDeviceInfo(DeviceInfoSet,

MemberIndex++,

&DeviceInfoData

)) {

//

// Determine whether this device is a phantom.

//

cr = CM_Get_DevNode_Status(&Status,

&Problem,

DeviceInfoData.DevInst,

0

);

if ((cr == CR_NO_SUCH_DEVINST) ||

(cr == CR_NO_SUCH_VALUE)) {

//

// This is a phantom. Now get the DeviceInstanceId so we

// can display this as output, then delete the phantom if requested.

//

if (CM_Get_Device_ID(DeviceInfoData.DevInst,

DeviceInstanceId,

SIZECHARS(DeviceInstanceId),

0) == CR_SUCCESS) {

if (bDoRemove) {

printf("DevNodePhantomCleaner: %ws will be removed.\n",

DeviceInstanceId);

//

// Call DIF_REMOVE to remove the device's hardware

// and software registry keys.

//

if (SetupDiCallClassInstaller(DIF_REMOVE,

DeviceInfoSet,

&DeviceInfoData

)) {

DevicesRemoved++;

} else {

printf("DevNodePhantomCleaner: Error 0x%x removing phantom\n",

GetLastError());

}

} else {

printf("DevNodePhantomCleaner: %ws would have been removed.\n",

DeviceInstanceId);

}

}

}

}

SetupDiDestroyDeviceInfoList(DeviceInfoSet);

}

}

return DevicesRemoved;

}

在解决方案资源管理器中,清理,用鼠标右键单击,然后单击属性。

展开配置属性,展开链接器,然后单击输入。

选择附加依赖项,请单击向下箭头,然后选择编辑。

在附加依赖项对话框中,类型setupapi.lib和cfgmgr32.lib。

单击确定两次。

生成项目。

奔度导航仪的导航准确性怎么样
键盘锁住了怎么解锁 6个方面教你排查