在域環境下禁用USB存儲設備的方法

隨這USB存儲設備,如U盤、移動硬盤的普及,給大家的工作帶來了很多方便,但同事,病毒、資料外泄等問題也跟這而來,下面是我在工作中碰到的,需要禁用USB存儲設備的方法,分享出來,有需要的可以參考下!

我現在的網絡環境中是用腳本做的,只對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的驅動不一樣,所以不保證能正常運行!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章