在域环境下禁用USB存储设备的方法

随这USB存储设备,如U盘、移动硬盘的普及,给你们的工做带来了不少方便,但同事,病毒、资料外泄等问题也跟这而来,下面是我在工做中碰到的,须要禁用USB存储设备的方法,分享出来,有须要的能够参考下!windows

我如今的网络环境中是用脚本作的,只对USB存储设备,如U盘、移动硬盘、USB光驱等,对USB的键盘、鼠标等无影响!原理就是对USB存储设备所须要的驱动文件进行删除或恢复,是参考Microsoft KB:823732 而来的!
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;823732

以下:在GPO中按不一样的要求分调用下面两脚本,说明以下:
好比说默认状况下,全部电脑都是在Computer OU下面,为了禁用或开启的须要,我另建两个OU: Disable USB/Enable USB,
一、禁止使用(将下面的代码copy到记事本,而后另存为.vbs),将须要禁止的电脑,移到禁用USB的Disable USB OU中,而后在此OU中的GPO调用下面的脚本
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\windows\inf\usbstor.pnf") Then
    objFSO.DeleteFile("C:\windows\inf\usbstor.pnf")
End If
If objFSO.FileExists("C:\windows\inf\usbstor.inf") Then
    objFSO.DeleteFile("C:\windows\inf\usbstor.inf")
End If
If objFSO.FileExists("C:\windows\system32\drivers\usbstor.sys") Then
    objFSO.DeleteFile("C:\windows\system32\drivers\usbstor.sys")
End If
If objFSO.FileExists("C:\winnt\inf\usbstor.pnf") Then
    objFSO.DeleteFile("C:\winnt\inf\usbstor.pnf")
End If
If objFSO.FileExists("C:\winnt\inf\usbstor.inf") Then
    objFSO.DeleteFile("C:\winnt\inf\usbstor.inf")
End If
If objFSO.FileExists("C:\winnt\system32\drivers\usbstor.sys") Then
    objFSO.DeleteFile("C:\winnt\system32\drivers\usbstor.sys")
End If

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\UsbStor"
strValueName = "Start"
dwValue = 4
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

二、解除禁止(将下面的代码copy到记事本,而后另存为.vbs),对于已禁用的电脑,须要解除的,将须要解除的电脑移到:Enable USB的OU中,而后在OU中的GPO调用,待能够用后,再移到正常使用的OU中(Computer),红色部分是具体文件及路径,须要依你实际状况而定,能够预先将几个文件COPY在某个隐藏的共享目录下!
Set objFSO = CreateObject("Scripting.FileSystemObject")
IF  objFSO.FolderExists("C:\windows") Then
If objFSO.FileExists("C:\windows\inf\usbstor.pnf") Then
Else
    objFSO.CopyFile "Usbstor.pnf" , "C:\windows\inf\usbstor.pnf"
End If
If objFSO.FileExists("C:\windows\inf\usbstor.Inf") Then
Else
    objFSO.CopyFile "Usbstor.Inf" , "C:\windows\inf\usbstor.Inf"
End If
If objFSO.FileExists("C:\windows\system32\drivers\usbstor.sys") Then
Else
    objFSO.CopyFile "Usbstor.sys" , "C:\windows\system32\drivers\usbstor.sys"
End If
End If
IF  objFSO.FolderExists("C:\winnt") Then
If objFSO.FileExists("C:\winnt\inf\usbstor.pnf") Then
Else
    objFSO.CopyFile "Usbstor.pnf" , "C:\winnt\inf\usbstor.pnf"
End If
If objFSO.FileExists("C:\winnt\inf\usbstor.inf") Then
Else
    objFSO.CopyFile "Usbstor.Inf" , "C:\winnt\inf\usbstor.Inf"
End If
If objFSO.FileExists("C:\winnt\inf\usbstor.sys") Then
Else
    objFSO.CopyFile "Usbstor.sys" , "C:\winnt\system32\drivers\usbstor.sys"
End If
End If
??
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\UsbStor"
strValueName = "Start"
dwValue = 3
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

说明:以上在Windows 2000/XP/Vista/Win7 32位的环境中都能正常,解除禁用的部分,因XP 64/Vista 64/Win7 64的驱动不同,因此不保证能正常运行!

 网络

相关文章
相关标签/搜索