Menù Principale

Cerca
Login
Registrati
Link
<< Discussione precedente | Discussione successiva >>   
[VBS] VBScript : settare le periferiche USB in sola lettura

Autore Messaggio
icemax
dom 11 feb 2007 - 13:26

online
Utente registrato #194
Registrato il: dom 21 gen 2007 - 22:27
Messaggi: 1371

come impostare in sola lettura le periferiche USB con VBscript e WMI:


'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'dichiarazione variabili
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const HKEY_LOCAL_MACHINE = &H80000002

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'The first is the computer that we are working on.
'A "." means the one we are sitting at. Anything else
'is remote. I recommend using the NetBIOS name without
'the slashes, "\\".
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
strComputer = "."

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'I also have a found_key variable set to false. The
'computer I initially checked this on didn't have the
'key at all, even though it is running XP SP2. This
'caused problems at first since there isn't a function
'to see if a registry sub-key exists. This variable
'is used to let us know whether or not the key even
'exists. You'll see why later.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
found_key = false

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'These next variables tell our script what root to look
'in, what the sub-key is, and what value name to look
'at to see if we are read-only or not.
'If the strKeyPath doesn't exist then USB devices are
'writeable if they are storage devices.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
strKeyRoot = "SYSTEM\CurrentControlSet\Control"
strKeyPath = "System\CurrentControlSet\Control\StorageDevicePolicies"
strValueName = "WriteProtect"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Crack apertura registro per lettura valore a:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Numerazione chiavi di registro ed inserimento valori in array
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyRoot, arrSubKeys

For Each subkey In arrSubKeys
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
if subkey = "StorageDevicePolicies" then
found_key = true ' chiave trovata
exit for
end if
Next

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'se il valore non è settato allora la periferica USB è in modalità scrittura.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
if not found_key then

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'chiedo se si vuole rendere in modalità sola lettura :

Read_Only = Msgbox ("Rendere la periferica USB protetta da scrittura?", 36, "Read-Only?")

if Read_Only = vbYes then

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' se si conferma allora il valore DWORD  lo setto a 1.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,1
end if
else

'altrimenti 

oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
if dwValue = 0 or dwValue = "" then

'''''''''''''''''''''''''''''''''''''''''''''''''''''''

Read_Only = Msgbox ("Rendere la periferica USB protetta da scrittura?", 36, 

"Read-Only?")

if Read_Only = vbYes then
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,1
end if
else
 
if dwValue = 1 then

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Writeable = Msgbox ("USB in sola lettura ,renderla scrivibile ?", 36, 

"sprotetta?")

if Writeable = vbYes then
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,0
end if
end if
end if
end if

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Ok

oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
Wscript.Echo "Current StorageDevicePolicies: " & dwValue

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''





salvare il testo in un file con estensione VBS ..ed eseguirlo

ATTENZIONE : script pericoloso


Torna ad inizio pagina

Moderatori: Danix, Taf, Rcs, Energy, zandet2, ZioZione, Admin, LordJim60

Salta:     Torna ad inizio pagina

RSS discussione: rss 0.92 RSS discussione: rss 2.0 RSS discussione: RDF
Powered by e107 Forum System