Sign in to follow this  
Followers 0
Rahul Rohela

Dieable\Enable USB Storage\CD-Rom\Floppy Drive

4 posts in this topic

#1 ·  Posted (edited)

HI,

With attached script you can disable enable USB Storage & removable devices of PC having admin rights with you. Remotely this can disable & enable devices. Only drawback is PC requires restart...

Rahul

#include<GUIconstants.Au3>
Opt("TrayIconHide", 1)
Opt("GUICloseOnESC", 0) 

$DE = GUICreate("Disable/Enable Devices", 305, 145, -1, -1)
GUICtrlCreateLabel("PC name or IP ", 10,10,70,15)

$PCName = GUICtrlCreateInput(@ComputerName, 85,10,150, 15, -1,0x00000020 )
GUICtrlSetLimit(-1,256)
$Status = GUICtrlCreateButton("Query PC",240,10,60,20,BitOr(0x0001,0x8000))
GUICtrlSetState($status, $GUI_FOCUS)
GUICtrlCreateLabel("USB Mass Storage ", 10,35,90,15)
$UDisable = GUICtrlCreateButton("Disable",105,35,60,20,BitOr(0x0001,0x8000))
$UEnable = GUICtrlCreateButton("Enable",170,35,60,20,BitOr(0x0001,0x8000))
$USB = GUICtrlCreateLabel("", 240,37,60,15)

GUICtrlCreateLabel("CD-ROM ", 10,60,90,15)
$CDisable = GUICtrlCreateButton("Disable",105,60,60,20,BitOr(0x0001,0x8000))

$CEnable = GUICtrlCreateButton("Enable",170,60,60,20,BitOr(0x0001,0x8000))
$CD = GUICtrlCreateLabel("", 240,62,60,15)

GUICtrlCreateLabel("Floppy Drive", 10,85,90,15)
$FDisable = GUICtrlCreateButton("Disable",105,85,60,20,BitOr(0x0001,0x8000))

$FEnable = GUICtrlCreateButton("Enable",170,85,60,20,BitOr(0x0001,0x8000))
$FD = GUICtrlCreateLabel("", 240,87,60,15)

GUICtrlCreateLabel("High Capacity Floppy Drive", 10,105,90,30)
$FHDisable = GUICtrlCreateButton("Disable",105,110,60,20,BitOr(0x0001,0x8000))

$FHEnable = GUICtrlCreateButton("Enable",170,110,60,20,BitOr(0x0001,0x8000))
$HFD = GUICtrlCreateLabel("", 240,112,60,15)
$Final = GUICtrlCreateLabel("", 102,132,190,15)
Opt("TrayIconHide", 1)
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $DE, "int", 1000, "long", 0x00090000);fade-out
        ExitLoop
    EndIf
    
    Select
    Case $msg = $Status
        _PathSet()
        
    Case $msg = $UDisable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", "REG_DWORD", "4")
        If Not @error Then 
            GUICtrlSetData( $USB, "Disbabled")
            GUICtrlSetColor($USB,0xff0000)
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $USB, "Error")
        EndIf
    Case $msg = $UEnable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", "REG_DWORD", "3")
        If Not @error Then 
            GUICtrlSetData( $USB, "Enabled")
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $USB, "Error")
        EndIf
    Case $msg = $CDisable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom", "Start", "REG_DWORD", "4")
        If Not @error Then 
            GUICtrlSetData( $CD, "Disbabled")
            GUICtrlSetColor($CD,0xff0000)
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $CD, "Error")
        EndIf
    Case $msg = $CEnable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom", "Start", "REG_DWORD", "1")
        If Not @error Then 
            GUICtrlSetData( $CD, "Enabled")
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $CD, "Error")
        EndIf
    Case $msg = $FDisable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Flpydisk", "Start", "REG_DWORD", "4")
        If Not @error Then 
            GUICtrlSetData( $FD, "Disbabled")
            GUICtrlSetColor($FD,0xff0000)
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $FD, "Error")
        EndIf
    Case $msg = $FEnable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Flpydisk", "Start", "REG_DWORD", "3")
        If Not @error Then 
            GUICtrlSetData( $FD, "Enabled")
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $FD, "Error")
        EndIf       
    Case $msg = $FHDisable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Sfloppy", "Start", "REG_DWORD", "4")
        If Not @error Then 
            GUICtrlSetData( $hFD, "Disbabled")
            GUICtrlSetColor($hFD,0xff0000)
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $hFD, "Error")
        EndIf       
    Case $msg = $FHEnable
        _PathSet()
        RegWrite($path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Sfloppy", "Start", "REG_DWORD", "3")
        If Not @error Then 
            GUICtrlSetData( $hFD, "Enabled")
            GUICtrlSetData( $Final,"(Restart PC to take effects )")
        Else
            GUICtrlSetData( $hFD, "Error")
        EndIf       

    EndSelect
    
WEnd

Func _ReadStatus()
    
    ; FOR USB<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $USB_REG_Value = RegRead( $Path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start")
    If $USB_REG_Value = 3 Then
        GUICtrlSetData( $USB, "Enabled" )
    ElseIf $USB_REG_Value = 4 Then
        GUICtrlSetData( $USB, "Disbabled")
        GUICtrlSetColor($USB,0xff0000)
    Else
        GUICtrlSetData( $USB, "Unknown")
    EndIf
    ;FOR CD<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $CD_REG_Value = RegRead( $Path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom", "Start")
    If $CD_REG_Value = 1 Then
        GUICtrlSetData( $CD, "Enabled" )
    ElseIf $CD_REG_Value = 4 Then
        GUICtrlSetData( $CD, "Disbabled")
        GUICtrlSetColor($CD,0xff0000)
    Else
        GUICtrlSetData( $CD, "Unknown")
    EndIf
    ;FOR Floppy<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $FD_REG_Value = RegRead( $Path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Flpydisk", "Start")
    If $FD_REG_Value = 3 Then
        GUICtrlSetData( $FD, "Enabled" )
    ElseIf $FD_REG_Value = 4 Then
        GUICtrlSetData( $FD, "Disbabled")
        GUICtrlSetColor($FD,0xff0000)
    Elseif $FD_REG_Value = 1 Then
        GUICtrlSetData( $FD, "System")
    ElseIf $FD_REG_Value = 2 Then
        GUICtrlSetData( $FD, "Auto Load")
    Else
        GUICtrlSetData( $FD, "Unknown")
    EndIf
    ;FOR High Capacity Floppy<<<<<<<<<<<<<<<<<
    $hFD_REG_Value = RegRead( $Path & "\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Sfloppy", "Start")
    If $hFD_REG_Value = 3 Then
        GUICtrlSetData( $hFD, "Enabled" )
    ElseIf $hFD_REG_Value = 4 Then
        GUICtrlSetData( $hFD, "Disbabled")
        GUICtrlSetColor($hFD,0xff0000)
    Else
        GUICtrlSetData( $hFD, "Unknown")
    EndIf
    

EndFunc

Func _PathSet()
    $NameIP = GUICtrlRead($PCName)
    If $NameIP = "" Then
        MsgBox(0,"PCName or IP", "Please enter PC Name or IP")
    Else
    Global  $Path = "\\" & $NameIP
        ;MsgBox(0,"Path", $path)
        $ping = Ping($NameIP)
        If @error then 
            GUICtrlSetData($Final,"Error: Could not contact to remote Host")
            GUICtrlSetColor($final,0xff0000)
        Else
            GUICtrlSetData( $Final,"")
            _ReadStatus()
            
        EndIf
        
    EndIf
    
EndFunc
Edited by Rahul Rohela

Share this post


Link to post
Share on other sites



HI,

With attached script you can disable enable USB Storage & removable devices of PC having admin rights with you. Remotely this can disable & enable devices. Only drawback is PC requires restart...

Rahul

post the code... no one will download an exe

Share this post


Link to post
Share on other sites

I wonder, won't restarting 'explorer' fix the problem with requirement of reboot? I am not 100% sure but if explorer is reloaded it gets registry keys reloaded with it aswell. But don't quote me on that ;P


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Restarting explorer will not work... restart is required...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0