关于fnwar3plugin.dll.dll关于卸载浩方,卸载魔兽,重装系统,修复注册表的问题。我都有尝试,都没有成功

如果您有什么建议或想投稿,请联系 QQ:
frmMain.frm
VERSION <font color="#.00Begin VB.Form frmMain
BorderStyle
<font color="#
'Fixed Single
"Usb卸载程序"
ClientHeight
<font color="#45
ClientLeft
<font color="#
<font color="#5
ClientWidth
<font color="#25
<font color="#
<font color="#
ScaleHeight
<font color="#45
ScaleWidth
<font color="#25
StartUpPosition =
<font color="#
Begin VB.CommandButton cmdAbout
"关于(&#038;A)"
<font color="#5
<font color="#50
<font color="#
<font color="#90
<font color="#05
Begin VB.CommandButton cmdExit
-<font color="#
"退出(&#038;C)"
<font color="#5
<font color="#50
<font color="#
<font color="#90
<font color="#05
Begin VB.CommandButton cmdUnLoad
"卸载(&#038;U)"
-<font color="#
<font color="#5
<font color="#00
<font color="#
<font color="#90
<font color="#05
Begin VB.TextBox txtUsbDrive
<font color="#5
<font color="#30
<font color="#
<font color="#0
<font color="#25
Begin VB.Label lblMsg
-<font color="#
"输入USB盘符:"
<font color="#0
<font color="#0
<font color="#
<font color="#0
<font color="#80
EndEndAttribute VB_Name = "frmMain"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Sub cmdAbout_Click()
Shell "explorer /s , http://blog.csdn.net/chenhui530/"
MsgBox "欢迎大家使用我编写的卸载USB程序,如果您在使用中发现有什么BUG或者是好的建" &#038; vbNewLine &#038; "议可以到我的博客上留言反映情况。地址是: http://blog.csdn.net/chenhui530/", vbInformation, "关于"End SubPrivate Sub cmdExit_Click()
Unload MeEnd SubPrivate Sub cmdUnLoad_Click()
Dim lngLenPath As Long, blnIsUsb As Boolean, strPath As String
lngLenPath = Len(txtUsbDrive.Text)
If lngLenPath <= <font color="# And Dir(txtUsbDrive.Text, <font color="# or <font color="# or <font color="# or vbDirectory)
If lngLenPath = <font color="# Then
If GetDriveBusType(txtUsbDrive.Text)
"Usb" Then
MsgBox "只能解锁USB设备分区!!", vbCritical, "错误"
txtUsbDrive.SetFocus
strPath = txtUsbDrive.Text &#038; "\"
ElseIf lngLenPath = <font color="# Then
If GetDriveBusType(txtUsbDrive.Text &#038; ":")
"Usb" Then
Box "只能解锁USB设备分区!!", vbCritical, "错误"
txtUsbDrive.SetFocus
strPath = txtUsbDrive.Text &#038; ":\"
If GetDriveBusType(Left(txtUsbDrive.Text, <font color="#))
"Usb" Then
MsgBox "只能解锁USB设备分区!!", vbCritical, "错误"
txtUsbDrive.SetFocus
strPath = txtUsbDrive.Text
blnIsUsb = True
MsgBox "您输入的USB盘符不要求!!", vbCritical, "错误"
txtUsbDrive.SetFocus
Me.cmdUnLoad.Enabled = False
Me.cmdExit.Enabled = False
'这里只检测本进程因为在获取驱动器类型的时候会打开一个句柄但是WINDOWS没有自己关闭所以用这个来
'解除锁定,当然你也可以使用CloseLoackFiles函数来检测所有进程
If CloseLockFileHandle(Left(strPath, <font color="#), GetCurrentProcessId) Then
If blnIsUsb Then
If RemoveUsbDrive("\\.\" &#038; Left(strPath, <font color="#), True) Then
MsgBox "卸载UBS设备成功!!", , "提示"
MsgBox "但卸载UBS设备失败!!", vbCritical, "提示"
MsgBox "发现有锁定文件还没解锁!!", vbCritical, "提示"
Me.cmdUnLoad.Enabled = True
Me.cmdExit.Enabled = TrueEnd Sub
modGetDriveType.bas
Attribute VB_Name = "modGetDriveType"Option Explicit'**************************************'此模块来自于网络'**************************************'判断驱动器的类型Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As LongPrivate Const DRIVE_UNKNOWN = <font color="#
'驱动器类型无法确定Private Const DRIVE_NO_ROOT_DIR = <font color="#
'驱动器根目录不存在Private Const DRIVE_REMOVABLE = <font color="#
'软盘驱动器或可移动盘Private Const DRIVE_FIXED = <font color="#
'硬盘驱动器Private Const DRIVE_REMOTE = <font color="#
'Network 驱动器Private Const DRIVE_CDROM = <font color="#
'光盘驱动器Private Const DRIVE_RAMDISK = <font color="#
'RAM 存储器'*************************************************************************************' CreateFile获取设备句柄'参数'lpFileName
文件名'dwDesiredAccess
访问方式'dwShareMode
共享方式'ATTRIBUTES lpSecurityAttributes
安全描述符指针'dwCreationDisposition
创建方式'dwFlagsAndAttributes
文件属性及标志' hTemplateFile
模板文件的句柄'CreateFile这个函数用处很多,这里我们用它「打开」设备驱动程序,得到设备的句柄。'操作完成後用CloseHandle关闭设备句柄。'与普通文件名有所不同,设备驱动的「文件名」形式固定为「\\.\DeviceName」(注意在C程序中该字符串写法为「\\\\.\\DeviceName」)'DeviceName必须与设备驱动程序内规定的设备名称一致。'一般地,调用CreateFile获得设备句柄时,访问方式参数设置为0或GENERIC_READ|GENERIC_WRITE'共享方式参数设置为FILE_SHARE_READ|FILE_SHARE_WRITE,创建方式参数设置为OPEN_EXISTING,其它参数设置为0或NULL。Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long<font color="
#000000">) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Const GENERIC_READ = &#038;H
'允许对设备进行读访问Private Const FILE_SHARE_READ = &#038;H1
'允许读取共享Private Const OPEN_EXISTING = <font color="#
'文件必须已经存在。由设备提出要求Private Const FILE_SHARE_WRITE = &#038;H2
'允许对文件进行共享访问'************************************************************************************'DeviceIoControl说明'用途
实现对设备的访问—获取信息,发送命令,交换数据等。'参数'hDevice
设备句柄'dwIoControlCode
控制码'lpInBuffer
输入数据缓冲区指针'nInBufferSize
输入数据缓冲区长度'lpOutBuffer
输出数据缓冲区指针'nOutBufferSize
输出数据缓冲区长度'lpBytesReturned
输出数据实际长度单元长度'lpOverlapped
重叠操作结构指针Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As LongPrivate Type SECURITY_ATTRIBUTES
nLength As Long
'结构体的大小
lpSecurityDescriptor As Long
'安全描述符(一个C-Style的字符串)。
bInheritHandle As Long
'所创建出来的东西是可以被其他的子进程使用的End Type'查询存储设备还是适配器属性Private Enum STORAGE_PROPERTY_ID
StorageDeviceProperty = <font color="#
'查询设备属性
StorageAdapterProperty
'查询适配器属性End Enum'查询存储设备属性的类型Private Enum STORAGE_QUERY_TYPE
PropertyStandardQuery = <font color="#
PropertyExistsQuery
'测试是否支持
PropertyMaskQuery
'读取指定的描述
PropertyQueryMaxDefined
'验证数据End Enum'查询属性输入的数据结构Private Type STORAGE_PROPERTY_QUERY
PropertyId As STORAGE_PROPERTY_ID
'设备/适配器
QueryType As STORAGE_QUERY_TYPE
AdditionalParameters(<font color="#) As Byte
'额外的数据(仅定义了象徵性的1个字节)End TypePrivate Type OVERLAPPED
Internal As Long
'保留给操作系统使用。用于保存系统状态,当GetOverLappedRseult的返回值中没有设置ERROR_IO_PENDING时,本域为有效。
InternalHigh As Long
'成员保留给操作系统使用。用于保存异步传输数据的长度。当GetOverLappedRseult返回TRUE时,本域为有效。
offset As Long
'指定开始进行异步传输的文件的一个位置。该位置是距离文件开头处的偏移值。在调用ReadFile或WriteFile之前,必须设置此分量。
OffsetHigh As Long
'指定开始异步传输处的字节偏移的高位字部分。
hEvent As Long
'指向一个事件的句柄,当传输完后将其设置为信号状态。End Type'存储设备的总线类型Private Enum STORAGE_BUS_TYPE
BusTypeUnknown = <font color="#
BusTypeScsi
BusTypeAtapi
BusTypeAta
BusType1394
BusTypeSsa
BusTypeFibre
BusTypeUsb
BusTypeRAID
BusTypeMaxReserved = &#038;H7FEnd Enum'查询属性输出的数据结构Private Type STORAGE_DEVICE_DESCRIPTOR
Version As Long
Size As Long
DeviceType As Byte
DeviceTypeModifier As Byte
'SCSI-2额外的设备类型
RemovableMedia <font color=
"#0000FF">As Byte
'是否可移动
CommandQueueing As Byte
'是否支持命令队列
VendorIdOffset As Long
'厂家设定值的偏移
ProductIdOffset As Long
'产品ID的偏移
ProductRevisionOffset As Long
'产品版本的偏移
SerialNumberOffset As Long
'序列号的偏移
BusType As STORAGE_BUS_TYPE
RawPropertiesLength As Long
'额外的属性数据长度
RawDeviceProperties(<font color="#) As Byte
'额外的属性数据(仅定义了象徵性的1个字节)End Type'计算控制码
IOCTL_STORAGE_QUERY_PROPERTYPrivate Const IOCTL_STORAGE_BASE As Long = &#038;H2DPrivate Const METHOD_BUFFERED = <font color="#Private Const FILE_ANY_ACCESS = <font color="#'获取磁盘属性Private Function GetDisksProperty(ByVal hDevice As Long, utDevDesc As STORAGE_DEVICE_DESCRIPTOR) As Boolean
Dim ut As OVERLAPPED
Dim utQuery As STORAGE_PROPERTY_QUERY
Dim lOutBytes As Long
With utQuery
.PropertyId = StorageDeviceProperty
.QueryType = PropertyStandardQuery
GetDisksProperty = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, utQuery, LenB(utQuery), utDevDesc, LenB(utDevDesc), lOutBytes, ut)End FunctionPrivate Function CTL_CODE(ByVal lDeviceType As Long, ByVal lFunction As Long, ByVal lMethod As Long, ByVal lAccess As Long) As Long
CTL_CODE = (lDeviceType * <font color="# ^ <font color="#&#038;) or (lAccess * <font color="# ^ <font color="#&#038;) or (lFunction * <font color="# ^ <font color="#) or (lMethod)End Function'获取设备属性信息,希望得到系统中所安装的各种固定的和可移动的硬盘、优盘和CD/DVD-ROM/R/W的接口类型、序列号、产品ID等信息。Private Function IOCTL_STORAGE_QUERY_PROPERTY() As Long
IOCTL_STORAGE_QUERY_PROPERTY = CTL_CODE(IOCTL_STORAGE_BASE, &#038;H500, METHOD_BUFFERED, FILE_ANY_ACCESS)End Function'获取驱动器总线类型Public Function GetDriveBusType(ByVal strDriveLetter As String) As String
Dim hDevice As Long
Dim utDevDesc As STORAGE_DEVICE_DESCRIPTOR
hDevice = CreateFile("\\.\" &#038; strDriveLetter, GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, ByVal <font color="#&#038;, OPEN_EXISTING, <font color="#, <font color="#)
If hDevice
-<font color="# Then
utDevDesc.Size = LenB(utDevDesc)
Call GetDisksProperty(hDevice, utDevDesc)
Select Case utDevDesc.BusType
Case BusType1394
GetDriveBusType = "1394"
Case BusTypeAta
GetDriveBusType = "Ata"
Case BusTypeAtapi
GetDriveBusType = "Atapi"
Case BusTypeFibre
GetDriveBusType = "Fibre"
Case BusTypeRAID
GetDriveBusType = "RAID"
Case BusTypeScsi
GetDriveBusType = "Scsi"
Case BusTypeSsa
GetDriveBusType = "Ssa"
Case BusTypeUsb
GetDriveBusType = "Usb"
Case BusTypeUnknown
GetDriveBusType = "未知"
<font color="#0000FF"
>Case Else
End Select
Call CloseHandle(hDevice)
End IfEnd Function
modLockFileInfo.bas
Attribute VB_Name = "modLockFileInfo"Option ExplicitPrivate Declare Function NtQueryInformationProcess Lib "NTDLL.DLL" (ByVal ProcessHandle As Long, _
ByVal ProcessInformationClass As PROCESSINFOCLASS, _
ByVal ProcessInformation As Long, _
ByVal ProcessInformationLength As Long, _
ByRef ReturnLength As Long) As LongPrivate Enum PROCESSINFOCLASS
ProcessBasicInformation = <font color="#
ProcessQuotaLimits
ProcessIoCounters
ProcessVmCounters
ProcessTimes
ProcessBasePriority
ProcessRaisePriority
ProcessDebugPort
ProcessExceptionPort
ProcessAccessToken
ProcessLdtInformation
ProcessLdtSize
ProcessDefaultHardErrorMode
ProcessIoPortHandlers
ProcessPooledUsageAndLimits
ProcessWorkingSetWatch
ProcessUserModeIOPL
ProcessEnableAlignmentFaultFixup
ProcessPriorityClass
ProcessWx86Information
ProcessHandleCount
ProcessAffinityMask
ProcessPriorityBoost
ProcessDeviceMap
ProcessSessionInformation
ProcessForegroundInformation
ProcessWow64Information
ProcessImageFileName
ProcessLUIDDeviceMapsEnabled
ProcessBreakOnTermination
ProcessDebugObjectHandle
ProcessDebugFlags
ProcessHandleTracing
ProcessIoPriority
ProcessExecuteFlags
ProcessResourceManagement
ProcessCookie
ProcessImageInformation
MaxProcessInfoClassEnd EnumPrivate Type PROCESS_BASIC_INFORMATION
ExitStatus As Long 'NTSTATUS
PebBaseAddress As Long 'PPEB
AffinityMask As Long 'ULONG_PTR
BasePriority As Long 'KPRIORITY
UniqueProcessId As Long 'ULONG_PTR
InheritedFromUniqueProcessId As Long 'ULONG_PTREnd TypePrivate Type FILE_NAME_INFORMATION
FileNameLength As Long
FileName(<font color="#) As ByteEnd TypePrivate Type NM_INFO
Info As FILE_NAME_INFORMATION
strName(<font color="#9) As ByteEnd TypePrivate Enum FileInformationClass
FileDirectoryInformation = <font color="#
FileFullDirectoryInformation = <font color="#
FileBothDirectoryInformation = <font color="#
FileBasicInformation = <font color="#
FileStandardInformation = <font color="#
FileInternalInformation = <font color="#
FileEaInformation = <font color="#
FileAccessInformation = <font color="#
FileNameInformation = <font color="#
FileRenameInformation = <font color="#
FileLinkInformation = <font color="#
FileNamesInformation = <font color="#
FileDispositionInformation = <font color="#
FilePositionInformation = <font color="#
FileFullEaInformation = <font color="#
FileModeInformation = <font color="#
FileAlignmentInformation = <font color="#
FileAllInformation = <font color="#
FileAllocationInformation = <font color="#
FileEndOfFileInformation = <font color="#
FileAlternateNameInformation = <font color="#
FileStreamInformation = <font color="#
FilePipeInformation = <font color="#
FilePipeLocalInformation = <font color="#
FilePipeRemoteInformation = <font color="#
FileMailslotQueryInformation = <font color="#
FileMailslotSetInformation = <font color="#
FileCompressionInformation = <font color="#
FileObjectIdInformation = <font color="#
FileCompletionInformation = <font color="#
FileMoveClusterInformation = <font color="#
FileQuotaInformation = <font color="#
FileReparsePointInformation = <font color="#
FileNetworkOpenInformation = <font color="#
FileAttributeTagInformation = <font color="#
FileTrackingInformation = <font color="#
FileMaximumInformationEnd EnumPrivate Declare Function NtQuerySystemInformation <
font color="#0000FF">Lib "NTDLL.DLL" (ByVal SystemInformationClass As SYSTEM_INFORMATION_CLASS, _
ByVal pSystemInformation As Long, _
ByVal SystemInformationLength As Long, _
ByRef ReturnLength As Long) As Long
Private Enum SYSTEM_INFORMATION_CLASS
SystemBasicInformation
SystemProcessorInformation
'// obsolete...delete
SystemPerformanceInformation
SystemTimeOfDayInformation
SystemPathInformation
SystemProcessInformation
SystemCallCountInformation
SystemDeviceInformation
SystemProcessorPerformanceInformation
SystemFlagsInformation
SystemCallTimeInformation
SystemModuleInformation
SystemLocksInformation
SystemStackTraceInformation
SystemPagedPoolInformation
SystemNonPagedPoolInformation
SystemHandleInformation
SystemObjectInformation
SystemPageFileInformation
SystemVdmInstemulInformation
SystemVdmBopInformation
SystemFileCacheInformation
SystemPoolTagInformation
SystemInterruptInformation
SystemDpcBehaviorInformation
SystemFullMemoryInformation
SystemLoadGdiDriverInformation
SystemUnloadGdiDriverInformation
SystemTimeAdjustmentInformation
SystemSummaryMemoryInformation
SystemMirrorMemoryInformation
SystemPerformanceTraceInformation
SystemObsolete0
SystemExceptionInformation
SystemCrashDumpStateInformation
SystemKernelDebuggerInformation
SystemContextSwitchInformation
SystemRegistryQuotaInformation
SystemExtendServiceTableInformation
SystemPrioritySeperation
SystemVerifierAddDriverInformation
SystemVerifierRemoveDriverInformation
SystemProcessorIdleInformation
SystemLegacyDriverInformation
SystemCurrentTimeZoneInformation
SystemLookasideInformation
SystemTimeSlipNotification
SystemSessionCreate
SystemSessionDetach
SystemSessionInformation
SystemRangeStartInformation
SystemVerifierInformation
SystemVerifierThunkExtend
SystemSessionProcessInformation
SystemLoadGdiDriverInSystemSpace
SystemNumaProcessorMap
SystemPrefetcherInformation
SystemExtendedProcessInformation
SystemRecommendedSharedDataAlignment
SystemComPlusPackage
SystemNumaAvailableMemory
SystemProcessorPowerInformation
SystemEmulationBasicInformation
SystemEmulationProcessorInformation
SystemExtendedHandleInformation
SystemLostDelayedWriteInformation
SystemBigPoolInformation
SystemSessionPoolTagInformation
SystemSessionMappedViewInformation
SystemHotpatchInformation
SystemObjectSecurityMode
SystemWatchdogTimerHandler
SystemWatchdogTimerInformation
SystemLogicalProcessorInformation
SystemWow64SharedInformation
SystemRegisterFirmwareTableInformationHandler
SystemFirmwareTableInformation
SystemModuleInformationEx
SystemVerifierTriageInformation
SystemSuperfetchInformation
SystemMemoryListInformation
SystemFileCacheInformationEx
MaxSystemInfoClass
'// MaxSystemInfoClass should always be the last enumEnd EnumPrivate Type SYSTEM_HANDLE
UniqueProcessId As Integer
CreatorBackTraceIndex As Integer
ObjectTypeIndex As Byte
HandleAttributes As Byte
HandleValue As Integer
pObject As Long
GrantedAccess As LongEnd TypePrivate Const STATUS_INFO_LENGTH_MISMATCH = &#038;HC0000004Private Enum SYSTEM_HANDLE_TYPE
OB_TYPE_UNKNOWN = <font color="#
OB_TYPE_TYPE = <font color="#
OB_TYPE_DIRECTORY
OB_TYPE_SYMBOLIC_LINK
OB_TYPE_TOKEN
OB_TYPE_PROCESS
OB_TYPE_THREAD
OB_TYPE_UNKNOWN_7
OB_TYPE_EVENT
OB_TYPE_EVENT_PAIR
OB_TYPE_MUTANT
OB_TYPE_UNKNOWN_11
OB_TYPE_SEMAPHORE
OB_TYPE_TIMER
OB_TYPE_PROFILE
OB_TYPE_WINDOW_STATION
OB_TYPE_DESKTOP
OB_TYPE_SECTION
OB_TYPE_KEY
OB_TYPE_PORT
OB_TYPE_WAITABLE_PORT
OB_TYPE_UNKNOWN_21
OB_TYPE_UNKNOWN_22
OB_TYPE_UNKNOWN_23
OB_TYPE_UNKNOWN_24
OB_TYPE_IO_COMPLETION
OB_TYPE_FILEEnd Enum'typedef struct _SYSTEM_HANDLE_INFORMATION'{'
SYSTEM_HANDLE
aSH[];'} SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION;Private Type SYSTEM_HANDLE_INFORMATION
uCount As Long
aSH() As SYSTEM_HANDLEEnd TypePrivate Declare Function NtDuplicateObject Lib "NTDLL.DLL" (ByVal SourceProcessHandle As Long, _
ByVal SourceHandle As Long, _
ByVal TargetProcessHandle As Long, _
ByRef TargetHandle As Long, _
ByVal DesiredAccess As Long, _
ByVal HandleAttributes As Long, _
ByVal Options As Long) As LongPrivate Const DUPLICATE_CLOSE_SOURCE = <fo
nt color="#800080">&#038;H1Private Const DUPLICATE_SAME_ACCESS = &#038;H2Private Const DUPLICATE_SAME_ATTRIBUTES = &#038;H4Private Declare Function NtOpenProcess Lib "NTDLL.DLL" (ByRef ProcessHandle As Long, _
ByVal AccessMask As Long, _
ByRef ObjectAttributes As OBJECT_ATTRIBUTES, _
ByRef ClientID As CLIENT_ID) As LongPrivate Type OBJECT_ATTRIBUTES
Length As Long
RootDirectory As Long
ObjectName As Long
Attributes As Long
SecurityDescriptor As Long
SecurityQualityOfService As LongEnd TypePrivate Type CLIENT_ID
UniqueProcess As Long
UniqueThread
As LongEnd TypePrivate Type IO_STATUS_BLOCK
Status As Long
uInformation As LongEnd TypePrivate Const PROCESS_Create_THREAD = &#038;H2Private Const PROCESS_VM_WRITE = &#038;H20Private Const PROCESS_VM_OPERATION = &#038;H8Private Const PROCESS_QUERY_INFORMATION As Long = (&#038;H400)Private Const STANDARD_RIGHTS_REQUIRED As Long = &#038;HF0000Private Const SYNCHRONIZE As Long = &#038;H100000Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED or SYNCHRONIZE or &#038;HFFF)Private Const PROCESS_DUP_HANDLE As Long = (&#038;H40)Private Declare Function NtClose Lib "NTDLL.DLL" (ByVal ObjectHandle As Long) As LongPrivate Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, _
ByRef Source As Any, _
ByVal Length As Long)
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long'typedef struct _OBJECT_NAME_INFORMATION'{'
UNICODE_STRING
N'} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;'typedef enum _OBJECT_INFORMATION_CLASS'{'
ObjectBasicInformation,
ObjectNameInformation,
ObjectTypeInformation,
ObjectAllTypesInformation,
ObjectHandleInformation
Y'} OBJECT_INFORMATION_CLASS;Private Enum OBJECT_INFORMATION_CLASS
ObjectBasicInformation = <font color="#
ObjectNameInformation
ObjectTypeInformation
ObjectAllTypesInformation
ObjectHandleInformationEnd Enum''typedef struct _UNICODE_STRING'{'
USHORT MaximumL'
PWSTR B'} UNICODE_STRING, *PUNICODE_STRING;Private Type UNICODE_STRING
uLength As Integer
uMaximumLength As Integer
pBuffer(<font color="#) As ByteEnd TypePrivate Type O
BJECT_NAME_INFORMATION
pName As UNICODE_STRINGEnd TypePrivate Const STATUS_INFO_LEN_MISMATCH = &#038;HC0000004Private Const HEAP_ZERO_MEMORY = &#038;H8Public Declare Function GetCurrentProcessId Lib "kernel32" () As LongPrivate Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As LongPrivate Declare Function GetProcessHeap Lib "kernel32" () As LongPrivate Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As LongPrivate Declare Function HeapReAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any, ByVal dwBytes As Long) As LongPrivate Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long'Private Declare Function NtQueryObject Lib "NTDLL.DLL" (ByVal ObjectHandle As Long, _'
ByVal ObjectInformationClass As OBJECT_INFORMATION_CLASS, _'
ObjectInformation As Any, ByVal ObjectInformationLength As Long, _'
ReturnLength As Long) As LongPrivate Declare Function NtQueryObject Lib "NTDLL.DLL" (ByVal ObjectHandle As Long, _
ByVal ObjectInformationClass As OBJECT_INFORMATION_CLASS, _
ByVal ObjectInformation As Long, ByVal ObjectInformationLength As Long, _
ReturnLength As Long) As LongPrivate Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As LongPrivate Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpTargetPath As String, ByVal ucchMax As Long) As LongPrivate Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPrivate Declare Function lstrcpyW Lib "kernel32" (ByVal lpString1 As String, ByVal lpString2 As Long) As LongPublic Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As LongPrivate Declare Function CreateRemoteThread <font co
lor="#0000FF">Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Any, ByVal dwStackSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPrivate Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long'Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As LongPrivate Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPrivate Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As LongPrivate Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As LongPrivate Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As LongPrivate Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As LongPrivate Declare Function GetFileType Lib "kernel32" (ByVal hFile As Long) As LongPrivate Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPrivate Function NT_SUCCESS(ByVal nStatus As Long) As Boolean
NT_SUCCESS = (nStatus >= <font color="#)End FunctionPublic Function GetFileFullPath(ByVal hFile As Long) As String
Dim hHeap As Long, dwSize As Long, objName As UNICODE_STRING, pName As Long
Dim ntStatus As Long, i As Long, lngNameSize As Long, strDrives As String, strArray() As String
Dim dwDriversSize As Long, strDrive As String, strTmp As String, strTemp As String
On Error GoTo ErrHandle
hHeap = GetProcessHeap
pName = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, &#038;H1000)
ntStatus = NtQueryObject(hFile, ObjectNameInformation, pName, &#038;H1000, dwSize)
If (NT_SUCCESS(ntStatus)) Then
i = <font color="#
Do While (ntStatus = STATUS_INFO_LEN_MISMATCH)
pName = HeapReAlloc(hHeap, HEAP_ZERO_MEMORY, pName, &#038;H1000 * i)
ntStatus = NtQueryObject(hFile, ObjectNameInformation, pName, &#038;H1000, ByVal <font color="#)
i = i + <font color="#
HeapFree hHeap, <fon
t color="#, pName
strTemp = String(<font color="#2, Chr(<font color="#))
lstrcpyW strTemp, pName + Len(objName)
strTemp = StrConv(strTemp, vbFromUnicode)
strTemp = Left(strTemp, InStr(strTemp, Chr(<font color="#)) - <font color="#)
strDrives = String(<font color="#2, Chr(<font color="#))
dwDriversSize = GetLogicalDriveStrings(<font color="#2, strDrives)
If dwDriversSize Then
strArray = Split(strDrives, Chr(<font color="#))
For i = <font color="# To UBound(strArray)
If strArray(i)
strDrive = Left(strArray(i), <font color="#)
strTmp = String(<font color="#0, Chr(<font color="#))
Call QueryDosDevice(strDrive, strTmp, <font color="#6)
strTmp = Left(strTmp, InStr(strTmp, Chr(<font color="#)) - <font color="#)
If InStr(LCase(strTemp), LCase(strTmp)) = <font color="# Then
GetFileFullPath = strDrive &#038; Mid(strTemp, Len(strTmp) + <font color="#, Len(strTemp) - Len(strTmp))
Exit Function
End IfErrHandle:End FunctionPublic Function CloseLockFileHandle(ByVal strFileName As String, ByVal dwProcessId As Long) As Boolean
Dim ntStatus As Long
Dim objCid As CLIENT_ID
Dim objOa As OBJECT_ATTRIBUTES
Dim lngHandles As Long
Dim i As Long
Dim objInfo As SYSTEM_HANDLE_INFORMATION, lngType As Long
Dim hProcess As Long, hProcessToDup As Long, hFileHandle As Long
Dim hFile As Long
'Dim objIo As IO_STATUS_BLOCK, objFn As FILE_NAME_INFORMATION, objN As NM_INFO
Dim bytBytes() As Byte, strSubPath As String, strTmp As String
Dim blnIsOk As Boolean
strSubPath = Mid(strFileName, <font color="#, Len(strFileName) - <font color="#)
hFile = CreateFile("NUL", &#038;H, <font color="#, ByVal <font color="#&#038;, <font color="#, <font color="#, <font color="#)
If hFile = -<font color="# Then
CloseLockFileHandle = False
Exit Function
objOa.Length = Len(objOa)
objCid.UniqueProcess = dwProcessId
ntStatus = <font color="#
Dim bytBuf() As Byte
Dim nSize As Long
nSize = <font color="#
ReDim bytBuf(nSize)
ntStatus = NtQuerySystemInformation(SystemHandleInformation, VarPtr(bytBuf(<font color="#)), nSize, <font color="#&#038;)
If (Not NT_SUCCESS(ntStatus)) Then
If (ntStatus
STATUS_INFO_LENGTH_MISMATCH) Then
Erase bytBuf
Exit Function
nSize = nSize * <font color="#
ReDim bytBuf(nSize)
lngHandles = <font color="#
CopyMemory objInfo.uCount, bytBuf(<font color="#), <font color="#
lngHandles = objInfo.uCount
ReDim objInfo.aSH(lngHandles - <font color="#)
Call CopyMemory(objInfo.aSH(<font color="#), bytBuf(<font color="#), Len(objInfo.aSH(<font color="#)) * lngHandles)
For i = <font color="# To </font
>lngHandles - <font color="#
If objInfo.aSH(i).HandleValue = hFile And objInfo.aSH(i).UniqueProcessId = GetCurrentProcessId Then
lngType = objInfo.aSH(i).ObjectTypeIndex
NtClose hFile
blnIsOk = True
For i = <font color="# To lngHandles - <font color="#
If objInfo.aSH(i).ObjectTypeIndex = lngType And objInfo.aSH(i).UniqueProcessId = dwProcessId Then
ntStatus = NtOpenProcess(hProcessToDup, PROCESS_DUP_HANDLE, objOa, objCid)
If hProcessToDup
<font color="# Then
ntStatus = NtDuplicateObject(hProcessToDup, objInfo.aSH(i).HandleValue, GetCurrentProcess, hFileHandle, <font color="#, <font color="#, DUPLICATE_SAME_ATTRIBUTES)
If (NT_SUCCESS(ntStatus)) Then
'这里如果直接调用NtQueryObject可能会挂起解决方法是用线程去处理当线程处理时间超过一定时间就把它干掉
'由于VB对多线程支持很差,其实应该说是对CreateThread支持很差,什么原因不要问我,相信网上也写有不少
'文件是关于它的,这里我选择了另一个函数也可以建立线程但是它是建立远程线程的,不过它却很稳定正好解决了
'我们这里的问题它就是CreateRemoteThread,^_^还记得我说过它很强大吧~~哈哈。
ntStatus = MyGetFileType(hFileHandle)
If ntStatus Then
strTmp = GetFileFullPath(hFileHandle)
NtClose hFileHandle
If InStr(LCase(strTmp), LCase(strFileName)) Then
If Not CloseRemoteHandle(dwProcessId, objInfo.aSH(i).HandleValue, strFileName) Then
blnIsOk = False
CloseLockFileHandle = blnIsOkEnd Function'检测所有进程Public Function CloseLoackFiles(ByVal strFileName As String) As Boolean
Dim ntStatus As Long
Dim objCid As CLIENT_ID
Dim objOa As OBJECT_ATTRIBUTES
Dim lngHandles As Long
Dim i As Long
Dim objInfo As SYSTEM_HANDLE_INFORMATION, lngType As Long
Dim hProcess As Long, hProcessToDup As Long, hFileHandle As Long
Dim hFile As Long, blnIsOk As Boolean, strProcessName As String
'Dim objIo As IO_STATUS_BLOCK, objFn As FILE_NAME_INFORMATION, objN As NM_INFO
Dim bytBytes() As Byte, strSubPath As String, strTmp As String
strSubPath = Mid(strFileName, <font color="#, Len(strFileName) - <font color="#)
hFile = CreateFile("NUL", &#038;H, <font color="#, ByVal <font color="#&#038;, <font color="#, <font color="#, <font color="#)
If hFile = -<font color="# Then
CloseLoackFiles = False
Exit Function
objOa.Length = Len(objOa)
ntStatus = <font color="#
Dim bytBuf() As Byte
Dim nSize As Long
nSize = <font color="#
ReDim bytBuf(nSize)
ntStatus = NtQuerySystemInformation(SystemHandleInformation, VarPtr(bytBuf(<font color="#)), nSize, <font color="#&#038;)
If (Not NT_SUCCESS(ntStatus)) Then
If (ntStatus
STATUS_INFO_LENGTH_MISMATCH) Then
Erase bytBuf
Exit Function
nSize = nSize * <font color="#
ReDim bytBuf(nSize)
lngHandles = <font color="#
CopyMemory objInfo.uCount, bytBuf(<font color="#), <font color="#80
lngHandles = objInfo.uCount
ReDim objInfo.aSH(lngHandles - <font color="#)
Call CopyMemory(objInfo.aSH(<font color="#), bytBuf(<font color="#), Len(objInfo.aSH(<font color="#)) * lngHandles)
For i = <font color="# To lngHandles - <font color="#
If objInfo.aSH(i).HandleValue = hFile And objInfo.aSH(i).UniqueProcessId = GetCurrentProcessId Then
lngType = objInfo.aSH(i).ObjectTypeIndex
NtClose hFile
blnIsOk = True
For i = <font color="# To lngHandles - <font color="#
If objInfo.aSH(i).ObjectTypeIndex = lngType Then
objCid.UniqueProcess = objInfo.aSH(i).UniqueProcessId
ntStatus = NtOpenProcess(hProcessToDup, PROCESS_DUP_HANDLE, objOa, objCid)
If hProcessToDup
<font color="# Then
ntStatus = NtDuplicateObject(hProcessToDup, objInfo.aSH(i).HandleValue, GetCurrentProcess, hFileHandle, <font color="#, <font color="#, DUPLICATE_SAME_ATTRIBUTES)
If (NT_SUCCESS(ntStatus)) Then
'这里如果直接调用NtQueryObject可能会挂起解决方法是用线程去处理当线程处理时间超过一定时间就把它干掉
'由于VB对多线程支持很差,其实应该说是对CreateThread支持很差,什么原因不要问我,相信网上也写有不少
'文件是关于它的,这里我选择了另一个函数也可以建立线程但是它是建立远程线程的,不过它却很稳定正好解决了
'我们这里的问题它就是CreateRemoteThread,^_^还记得我说过它很强大吧~~哈哈。
ntStatus = MyGetFileType(hFileHandle)
If ntStatus Then
strTmp = GetFileFullPath(hFileHandle)
strTmp = ""
NtClose hFileHandle
If InStr(LCase(strTmp), LCase(strFileName)) Then
If Not CloseRemoteHandle(objInfo.aSH(i).UniqueProcessId, objInfo.aSH(i).HandleValue, strTmp) Then
blnIsOk = False
CloseLoackFiles = blnIsOkEnd FunctionPrivate Function GetProcessCommandLine(ByVal dwProcessId As Long) As String
Dim objCid As CLIENT_ID
Dim objOa As OBJECT_ATTRIBUTES
Dim ntStatus As Long, hKernel As Long, strName As String
Dim hProcess As Long, dwAddr As Long, dwRead As Long
objOa.Length = Len(objOa)
objCid.UniqueProcess = dwProcessId
ntStatus = NtOpenProcess(hProcess, &#038;H10, objOa, objCid)
If hProcess = <font color="# Then
GetProcessCommandLine = ""
Exit Function
hKernel = GetModuleHandle("kernel32")
dwAddr = GetProcAddress(hKernel, "GetCommandLineA")
CopyMemory dwAddr, ByVal dwAddr + <font color="#, <font color="#
If ReadProcessMemory(hProcess, ByVal dwAddr, dwAddr, <font color="#, dwRead) Then
strName = String(<font color="#0, Chr(<font color="#))
If ReadProcessMemory(hProcess, ByVal dwAddr, ByVal strName, <font color="#0, dwRead) Then
strName = Left(strName, InStr(strName, Chr(<font color="#)) - <font color="#)
NtClose hProcess
GetProcessCommandLine = strName
Exit Function
NtClose hProcessEnd Function'解锁指定进程的锁定文件Public Function CloseRemoteHandle(ByVal dwProcessId, ByVal hHandle As Long, Optional ByVal <f
ont color="#000000">strLockFile As String = "") As Boolean
Dim hMyProcess
As Long, hRemProcess As Long, blnResult As Long, hMyHandle As Long
Dim objCid As CLIENT_ID
Dim objOa As OBJECT_ATTRIBUTES
Dim ntStatus As Long, strProcessName As String, hProcess As Long, strMsg As String
objCid.UniqueProcess = dwProcessId
objOa.Length = Len(objOa)
hMyProcess = GetCurrentProcess()
ntStatus = NtOpenProcess(hRemProcess, PROCESS_DUP_HANDLE, objOa, objCid)
If hRemProcess Then
ntStatus = NtDuplicateObject(hRemProcess, hHandle, GetCurrentProcess, hMyHandle, <font color="#, <font color="#, DUPLICATE_CLOSE_SOURCE or DUPLICATE_SAME_ACCESS)
If (NT_SUCCESS(ntStatus)) Then
'If DuplicateHandle(hRemProcess, hMyProcess, hHandle, hMyHandle, 0, 0, DUPLICATE_CLOSE_SOURCE or DUPLICATE_SAME_ACCESS) Then
blnResult = NtClose(hMyHandle)
If blnResult >= <font color="# Then
strProcessName = GetProcessCommandLine(dwProcessId)
'If InStr(LCase(strProcessName), LCase(strLockFile)) Then
If InStr(LCase(strProcessName), "explorer.exe") = <font color="# And dwProcessId
GetCurrentProcessId Then
objCid.UniqueProcess = dwProcessId
ntStatus = NtOpenProcess(hProcess, <font color="#, objOa, objCid)
If hProcess
<font color="# Then TerminateProcess hProcess, <font color="#
Call NtClose(hRemProcess)
CloseRemoteHandle = blnResult >= <font color="#End Function'解锁指定进程的锁定文件Public Function CloseRemoteHandleEx(ByVal dwProcessId, ByVal hHandle As Long, Optional ByVal strLockFile As String = "") As Boolean
Dim hRemProcess As Long, hThread As Long, lngResult As Long, pfnThreadRtn As Long, hKernel As Long
Dim objCid As CLIENT_ID
Dim objOa As OBJECT_ATTRIBUTES, strMsg As String
Dim ntStatus As Long, strProcessName As String, hProcess As Long
objCid.UniqueProcess = dwProcessId
objOa.Length = Len(objOa)
ntStatus = NtOpenProcess(hRemProcess, PROCESS_QUERY_INFORMATION or PROCESS_Create_THREAD or PROCESS_VM_OPERATION or PROCESS_VM_WRITE, objOa, objCid)'
hMyProcess = OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_Create_THREAD or PROCESS_VM_OPERATION or PROCESS_VM_WRITE, 0, dwProcessId)
If hRemProcess = <font color="# Then
CloseRemoteHandleEx = False
Exit Function
hKernel = GetModuleHandle("kernel32")
If hKernel = <font color="# Then
CloseRemoteHandleEx = False
Exit Function
pfnThreadRtn = GetProcAddress(hKernel, "CloseHandle")
If pfnThreadRtn = <font color="# Then
FreeLibrary hKernel
CloseRemoteHandleEx = False
Exit Function
hThread = CreateRemoteThread(hRemProcess, ByVal <font color="#&#038;, <font color="#&#038;, ByVal pfnThreadRtn, ByVal hHandle, <font color="#, <font color="#&#038;)
If hThread = <font color="# Then
FreeLibrary hKernel
CloseRemoteHandleEx = False
Exit Function
GetExitCodeThread hThread, lngResult
CloseRemoteHandleEx = CBool(lngResult)
strProcessName = GetP
rocessCommandLine(dwProcessId)
If InStr(strProcessName, strLockFile) Then
objCid.UniqueProcess = dwProcessId
ntStatus = NtOpenProcess(hProcess, <font color="#, objOa, objCid)
If hProcess
<font color="# Then TerminateProcess hProcess, <font color="#
NtClose hThread
NtClose hRemProcess
FreeLibrary hKernelEnd FunctionPrivate Function MyGetFileType(ByVal hFile As Long) As Long
Dim hRemProcess As Long, hThread As Long, lngResult As Long, pfnThreadRtn As Long, hKernel As Long
Dim dwEax As Long, dwTimeOut As Long
hRemProcess = GetCurrentProcess
hKernel = GetModuleHandle("kernel32")
If hKernel = <font color="# Then
MyGetFileType = <font color="#
Exit Function
pfnThreadRtn = GetProcAddress(hKernel, "GetFileType")
If pfnThreadRtn = <font color="# Then
FreeLibrary hKernel
MyGetFileType = <font color="#
Exit Function
hThread = CreateRemoteThread(hRemProcess, ByVal <font color="#&#038;, <font color="#&#038;, ByVal pfnThreadRtn, ByVal hFile, <font color="#, ByVal <font color="#&#038;)
dwEax = WaitForSingleObject(hThread, <font color="#0)
If dwEax = &#038;H102 Then
Call GetExitCodeThread(hThread, dwTimeOut)
Call TerminateThread(hThread, dwTimeOut)
NtClose hThread
MyGetFileType = <font color="#
Exit Function
If hThread = <font color="# Then
FreeLibrary hKernel
MyGetFileType = False
Exit Function
GetExitCodeThread hThread, lngResult
MyGetFileType = lngResult
NtClose hThread
NtClose hRemProcess
FreeLibrary hKernelEnd Function
modRemoveUsbDrive.bas
Attribute VB_Name = "modRemoveUsbDrive"Option Explicit'***********************************************************'此模块是通过转换C++代码而来'*********************************************************************Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(<font color="# To <font color="#) As ByteEnd Type'typedef struct _SP_DEVICE_INTERFACE_DETAIL_DATA_A {'
DevicePath[ANYSIZE_ARRAY];'} SP_DEVICE_INTERFACE_DETAIL_DATA_A, *PSP_DEVICE_INTERFACE_DETAIL_DATA_A;Private Type SP_DEVICE_INTERFACE_DETAIL_DATA
cbSize As Long
strDevicePath As String * <font color="#0End TypePrivate Type SP_DEVICE_INTERFACE_DATA
cbSize As Long 'taille de la structure en octets
InterfaceClassGuid As GUID 'GUID de la classe d'interface
flags As Long 'options
Reserved As Long 'réservéEnd TypePrivate Type SP_DEVINFO_DATA
cbSize As Long 'taille de la structure en octets
ClassGuid As GUID 'GUID de la classe d'installation
DevInst As Long 'handle utilisable par certaine fonction CM_xxx
Reserved As Long 'réservéEnd Type''typedef struct _STORAGE_DEVICE_NUMBER {'
// The FILE_DEVICE_XXX type for this device.'
DEVICE_TYPE DeviceT'
// The number of this device'
// If the device is partitionable, the partition number of the device.'
// Otherwise -1'
PartitionN'} STORAGE_DEVICE_NUMBER, *PSTORAGE_DEVICE_NUMBER;Private Type STORAGE_DEVICE_NUMBER
dwDeviceType As Long
dwDeviceNumber As Long
dwPartitionNumber As LongEnd <font co
lor="#000000">Type'typedef enum
_PNP_VETO_TYPE {'
PNP_VetoTypeUnknown,
// Name is unspecified'
PNP_VetoLegacyDevice,
// Name is an Instance Path'
PNP_VetoPendingClose,
// Name is an Instance Path'
PNP_VetoWindowsApp,
// Name is a Module'
PNP_VetoWindowsService,
// Name is a Service'
PNP_VetoOutstandingOpen,
// Name is an Instance Path'
PNP_VetoDevice,
// Name is an Instance Path'
PNP_VetoDriver,
// Name is a Driver Service Name'
PNP_VetoIllegalDeviceRequest,
// Name is an Instance Path'
PNP_VetoInsufficientPower,
// Name is unspecified'
PNP_VetoNonDisableable,
// Name is an Instance Path'
PNP_VetoLegacyDriver,
// Name is a Service'
PNP_VetoInsufficientRights
// Name is unspecified'}
PNP_VETO_TYPE, *PPNP_VETO_TYPE;Private Enum PNP_VETO_TYPE
PNP_VetoTypeUnknown
PNP_VetoLegacyDevice
PNP_VetoPendingClose
PNP_VetoWindowsApp
PNP_VetoWindowsService
PNP_VetoOutstandingOpen
PNP_VetoDevice
PNP_VetoDriver
PNP_VetoIllegalDeviceRequest
PNP_VetoInsufficientPower
PNP_VetoNonDisableable
PNP_VetoLegacyDriver
PNP_VetoInsufficientRightsEnd Enum'Private Const DIGCF_DEFAULT = &#038;H1
' only valid with DIGCF_DEVICEINTERFACEPrivate Const DIGCF_PRESENT = &#038;H2'Private Const DIGCF_ALLCLASSES = &#038;H4'Private Const DIGCF_PROFILE = &#038;H8Private Const DIGCF_DEVICEINTERFACE = &#038;H10Private Const GENERIC_READ = &#038;H
'允许对设备进行读访问Private Const FILE_SHARE_READ = &#038;H1
'允许读取共享Private Const OPEN_EXISTING = <font color="#
'文件必须已经存在。由设备提出要求Private Const FILE_SHARE_WRITE = &#038;H2
'允许对文件进行共享访问Private Const IOCTL_STORAGE_BASE As Long = &#038;H2DPrivate Const METHOD_BUFFERED = <font color="#Private Const FILE_ANY_ACCESS = <font color="#Private Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByVal ClassGuid As Long, ByVal Enumerator As Long, ByVal HwndParent As Long, ByVal flags As Long) As LongPrivate Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As GUID, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As LongPrivate Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, DeviceInterfaceDetailData As Any, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, DeviceInfoData As Any) As LongPrivate Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As LongPrivate Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As LongPrivate Declare Function CM_Get_Parent Lib "cfgmgr32.dll" (pdwDevInst As Long, B
yVal dwDevInst As Long, ByVal ulFlags As Long) As LongPrivate Declare Function CM_Request_Device_EjectW Lib "setupapi.dll" (ByVal dwDevInst As Long, ByVal pVetoType As Long, ByVal pszVetoName As String, ByVal ulNameLength As Long, ByVal ulFlags As Long) As LongPrivate Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As Any) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As LongPrivate Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpTargetPath As String, ByVal ucchMax As Long) As LongPrivate Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Function CTL_CODE(ByVal lDeviceType As Long, ByVal lFunction As Long, ByVal lMethod As Long, ByVal lAccess As Long) As Long
CTL_CODE = (lDeviceType * <font color="# ^ <font color="#&#038;) or (lAccess * <font color="# ^ <font color="#&#038;) or (lFunction * <font color="# ^ <font color="#) or (lMethod)End Function'获取设备属性信息,希望得到系统中所安装的各种固定的和可移动的硬盘、优盘和CD/DVD-ROM/R/W的接口类型、序列号、产品ID等信息。Private Function IOCTL_STORAGE_GET_DEVICE_NUMBER() As Long '2953344
IOCTL_STORAGE_GET_DEVICE_NUMBER = CTL_CODE(IOCTL_STORAGE_BASE, &#038;H420, METHOD_BUFFERED, FILE_ANY_ACCESS)End FunctionPrivate Function GetDrivesDevInstByDeviceNumber(ByVal lngDeviceNumber As Long, ByVal uDriveType As Long, ByVal szDosDeviceName As String) As Long
Dim objGuid As GUID, hDevInfo As Long, dwIndex As Long, lngRes As Long, dwSize As Long
Dim objSpdid As SP_DEVICE_INTERFACE_DATA, objSpdd As SP_DEVINFO_DATA, objPspdidd As SP_DEVICE_INTERFACE_DETAIL_DATA
Dim hDrive As Long, objSdn <font color="
#0000FF">As STORAGE_DEVICE_NUMBER, dwBytesReturned As Long
Dim dwReturn As Long
With objGuid
.Data2 = &#038;HB6BF
.Data3 = &#038;H11D0&#038;
.Data4(<font color="#) = &#038;H94&#038;
.Data4(<font color="#) = &#038;HF2&#038;
.Data4(<font color="#) = &#038;H0&#038;
.Data4(<font color="#) = &#038;HA0&#038;
.Data4(<font color="#) = &#038;HC9&#038;
.Data4(<font color="#) = &#038;H1E&#038;
.Data4(<font color="#) = &#038;HFB&#038;
.Data4(<font color="#) = &#038;H8B&#038;
Select Case uDriveType
Case <font color="#
If InStr(szDosDeviceName, "\Floppy") Then
.Data1 = &#038;H53F56311
.Data1 = &#038;H53F56307
Case <font color="#
.Data1 = &#038;H53F56307
Case <font color="#
.Data1 = &#038;H53F56308
End Select
'Get device interface info set handle for all devices attached to system
hDevInfo = SetupDiGetClassDevs(VarPtr(objGuid), <font color="#, <font color="#, DIGCF_PRESENT or DIGCF_DEVICEINTERFACE)
If hDevInfo = -<font color="# Then
GetDrivesDevInstByDeviceNumber = <font color="#
Exit Function
objSpdid.cbSize = Len(objSpdid)
Do While <font color="#
lngRes = SetupDiEnumDeviceInterfaces(hDevInfo, <font color="#, objGuid, dwIndex, objSpdid)
If lngRes = <font color="# Then Exit Do
dwSize = <font color="#
Call SetupDiGetDeviceInterfaceDetail(hDevInfo, objSpdid, ByVal <font color="#&#038;, <font color="#, dwSize, ByVal <font color="#&#038;)
<font color="# And dwSize <= <font color="#24 Then
objPspdidd.cbSize = <font color="# 'Len(objPspdidd) '这里十分注意这里必须是5不能用'Len(objPspdidd)
objSpdd.cbSize = Len(objSpdd)
lngRes = SetupDiGetDeviceInterfaceDetail(hDevInfo, objSpdid, objPspdidd, ByVal dwSize, dwReturn, objSpdd)
If lngRes > <font color="# Then
hDrive = CreateFile(objPspdidd.strDevicePath, <font color="#, FILE_SHARE_READ or FILE_SHARE_WRITE, ByVal <font color="#&#038;, OPEN_EXISTING, <font color="#, <font color="#)
-<font color="# Then
'获取设备号
lngRes = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, ByVal <font color="#&#038;, <font color="#, objSdn, Len(objSdn), dwBytesReturned, ByVal <font color="#&#038;)
If lngRes Then
'match the given device number with the one of the current device
If lngDeviceNumber = objSdn.dwDeviceNumber Then
Call CloseHandle(hDrive)
SetupDiDestroyDeviceInfoList hDevInfo
GetDrivesDevInstByDeviceNumber = objSpdd.DevInst
Exit Function
Call CloseHandle(hDrive)
dwIndex = dwIndex + <font color="#
Call SetupDiDestroyDeviceInfoList(hDevInfo)End Function'************************************************************************************************'参数为szDosDeviceName为USB的路径格式为"\\.\" &#038; drive &#038; ":"形式,blnIsShowNote参数是是否显示'消息窗体的着用,这里需要注意的是在9X下只能把blnIsShowNote参数设置为FALSE'************************************************************************************************<
/font>Public Function RemoveUsbDrive(ByVal szDosDeviceName As String, ByVal blnIsShowNote As Boolean) As Boolean
Dim strDrive As String, dwDeviceNumber As Long, hVolume As Long, objSdn As STORAGE_DEVICE_NUMBER, dwBytesReturned As Long
Dim lngRes As Long, uDriveType As Long, strDosDriveName As String, hDevInst As Long, uType As PNP_VETO_TYPE
Dim strVetoName As String, blnSuccess As Boolean, dwDevInstParent As Long, i As Integer, pVetoType As Long
'获取USB所在盘符
strDrive = Right(szDosDeviceName, <font color="#)
dwDeviceNumber = -<font color="#
hVolume = CreateFile(szDosDeviceName, <font color="#, FILE_SHARE_READ or FILE_SHARE_WRITE, ByVal <font color="#&#038;, OPEN_EXISTING, <font color="#, <font color="#)
If hVolume = -<font color="# Then
RemoveUsbDrive = False
Exit Function
'获取设备号
lngRes = DeviceIoControl(hVolume, IOCTL_STORAGE_GET_DEVICE_NUMBER, ByVal <font color="#&#038;, <font color="#, objSdn, Len(objSdn), dwBytesReturned, ByVal <font color="#&#038;)
If lngRes Then
dwDeviceNumber = objSdn.dwDeviceNumber
Call CloseHandle(hVolume)
If dwDeviceNumber = -<font color="# Then
RemoveUsbDrive = False
Exit Function
'获取驱动器类型
uDriveType = GetDriveType(strDrive)
strDosDriveName = String(<font color="#0, Chr(<font color="#))
'get the dos device name (like \device\floppy0) to decide if it's a floppy or not - who knows a better way?
lngRes = QueryDosDevice(strDrive, strDosDriveName, <font color="#0)
strDosDriveName = Left(strDosDriveName, InStr(strDosDriveName, Chr(<font color="#)) - <font color="#)
If lngRes = <font color="# Then
RemoveUsbDrive = False
Exit Function
'get the device instance handle of the storage volume by means of a SetupDi enum and matching the device number
hDevInst = GetDrivesDevInstByDeviceNumber(dwDeviceNumber, uDriveType, strDosDriveName)
If hDevInst = <font color="# Then
RemoveUsbDrive = False
Exit Function
strVetoName = String(<font color="#0, Chr(<font color="#))
'get drives's parent, e.g. the USB bridge, the SATA port, an IDE channel with two drives!
lngRes = CM_Get_Parent(dwDevInstParent, hDevInst, <font color="#)
For i = <font color="# To <font color="#
'卸载UB设备
If blnIsShowNote Then
lngRes = CM_Request_Device_EjectW(dwDevInstParent, ByVal VarPtr(pVetoType), vbNullString, <font color="#, <font color="#)
lngRes = CM_Request_Device_EjectW(dwDevInstParent, uType, strVetoName, <font color="#0, <font color="#)
If lngRes = <font color="# And uType = PNP_VetoTypeUnknown Then
blnSuccess = True
Sleep <font color="#0
RemoveUsbDrive = blnSuccessEnd Function
THEME DESIGN BY JEZZZZ & MUGEE}

我要回帖

更多关于 war3plugin.dll 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信