分享

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

 随风Frans 2014-05-05
我现在的网络环境中是用脚本做的,只对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,
1、禁止使用(将下面的代码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

2、解除禁止(将下面的代码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的驱动不一样,所以不保证能正常运行!

  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多