youtuber Posted February 17, 2018 Share Posted February 17, 2018 Friends do not want a usb disk to appear without password verification when a usb disk is inserted How do I do this? expandcollapse popup#include <WindowsConstants.au3> $strComputer = "." Global $objObject $objWMIServices = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $sink = ObjCreate("WbemScripting.SWbemSink") ObjEvent($sink, "SINK_") $objWMIServices.ExecNotificationQueryAsync($sink, "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " & "TargetInstance ISA 'Win32_LogicalDisk'") While 1 Sleep(10) WEnd Func SINK_OnObjectReady($objObject, $objAsyncContext) If $objObject.TargetInstance.DriveType = 2 Then Select Case $objObject.Path_.Class() = "__InstanceCreationEvent" _pass() ConsoleWrite("Drive " & $objObject.TargetInstance.DeviceId & " Has been added." & @CR) ShellExecute($objObject.TargetInstance.DeviceId) Case $objObject.Path_.Class() = "__InstanceDeletionEvent" ConsoleWrite("Drive " & $objObject.TargetInstance.DeviceId & " Has been removed." & @CR) EndSelect EndIf EndFunc Func _pass($Pass = "123456") Local $Inputbox For $I = 1 To 3 $Inputbox = InputBox("Please try again", "Please enter the password to view the usb disk", "", "*") If @error Then Exit ElseIf $Pass = $Inputbox Then ExitLoop Else MsgBox(0, "Please try again", "Wrong password " & $I, 3) EndIf Next If $Pass <> $Inputbox Then ConsoleWrite("Drive " & " "& " Hide" & @CR) EndIf EndFunc Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 18, 2018 Moderators Share Posted February 18, 2018 How about some more information? What OS are you using? Is this a domain-connected PC or a stand-alone? Help us help you "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
youtuber Posted February 18, 2018 Author Share Posted February 18, 2018 I am using windows 7 x64 bit Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 18, 2018 Moderators Share Posted February 18, 2018 On a domain or off "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
BrewManNH Posted February 18, 2018 Share Posted February 18, 2018 Use BitLocker on the drive, and then no one can access it without the password, plus it's encrypted. It won't hide the drive, but you can't get into it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 18, 2018 Moderators Share Posted February 18, 2018 I was thinking the same thing; part of the reason I am pulling teeth to get more information. If he is on 7 Home or Pro BitLocker is not going to be a possibility. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Au3Builder Posted February 18, 2018 Share Posted February 18, 2018 I believe you can legally download a free Windows 7 Ultimate Trial Version and encrypt your USB stick which is decryptable on home editions for later use. Link to comment Share on other sites More sharing options...
youtuber Posted February 18, 2018 Author Share Posted February 18, 2018 I do not want to encrypt the usb drive My computer needs a password when I plug in a usb driver without permission. Do not display the usb drive without entering the password. Link to comment Share on other sites More sharing options...
Au3Builder Posted February 18, 2018 Share Posted February 18, 2018 5 minutes ago, youtuber said: I do not want to encrypt the usb driveMy computer needs a password when I plug in a usb driver without permission. Do not display the usb drive without entering the password. Like I said before.BitLocker is what you need.You won't access your usb drive without entering the password. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 18, 2018 Share Posted February 18, 2018 48 minutes ago, youtuber said: My computer needs a password when I plug in a usb driver without permission. Do not display the usb drive without entering the password. From what I'm getting from this, you're looking to block ALL access to ANY USB device/drive until someone enters a password authorizing it? Sounds very difficult, and probably harder to do than you'd think. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Au3Builder Posted February 18, 2018 Share Posted February 18, 2018 3 minutes ago, BrewManNH said: From what I'm getting from this, you're looking to block ALL access to ANY USB device/drive until someone enters a password authorizing it? Sounds very difficult, and probably harder to do than you'd think. If it's what he means, then It shouldn't be that hard to do. My advice is to disable USB ports via registry and re-enable them after entering the password. Link to comment Share on other sites More sharing options...
youtuber Posted February 18, 2018 Author Share Posted February 18, 2018 @Au3Builder I tried, but it does not work expandcollapse popup#include <WindowsConstants.au3> RegWrite('HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR', 'Start', 'REG_DWORD', '4') $strComputer = "." Global $objObject $objWMIServices = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $sink = ObjCreate("WbemScripting.SWbemSink") ObjEvent($sink, "SINK_") $objWMIServices.ExecNotificationQueryAsync($sink, "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE " & "TargetInstance ISA 'Win32_LogicalDisk'") While 1 Sleep(10) WEnd Func SINK_OnObjectReady($objObject, $objAsyncContext) If $objObject.TargetInstance.DriveType = 2 Then Select Case $objObject.Path_.Class() = "__InstanceCreationEvent" _pass() RegWrite('HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR', 'Start', 'REG_DWORD', '3') ShellExecute($objObject.TargetInstance.DeviceId) Case $objObject.Path_.Class() = "__InstanceDeletionEvent" ConsoleWrite("Drive " & $objObject.TargetInstance.DeviceId & " Has been removed." & @CR) EndSelect EndIf EndFunc Func _pass($Pass = "123456") Local $Inputbox For $I = 1 To 3 $Inputbox = InputBox("Please try again", "Please enter the password to view the usb disk", "", "*") If @error Then Exit ElseIf $Pass = $Inputbox Then ExitLoop Else MsgBox(0, "Please try again", "Wrong password " & $I, 3) EndIf Next If $Pass <> $Inputbox Then RegWrite('HKLM\SYSTEM\CurrentControlSet\Services\USBSTOR', 'Start', 'REG_DWORD', '4') EndIf EndFunc Link to comment Share on other sites More sharing options...
Au3Builder Posted February 18, 2018 Share Posted February 18, 2018 (edited) $DBT_DEVICEARRIVAL = "0x00008000" $WM_DEVICECHANGE = 0x0219 GUICreate("") GUIRegisterMsg($WM_DEVICECHANGE , "MyFunc") Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam) If $WParam == $DBT_DEVICEARRIVAL Then $dg = DriveGetDrive( "REMOVABLE" ) For $i = 1 to $dg[0] $dt = DriveGetType( $dg[$i] ) If $dt = "REMOVABLE" And $dg[$i] <> "a:" And $dg[$i] <> "b:" Then ;;look for my marker file at $dg[$i] , if found do check... MsgBox(4096,"Drive " & $i, $dg[$i] & " = " & $dt) EndIf Next EndIf EndFunc While 1 $GuiMsg = GUIGetMsg() WEnd The example above detects usb insertion just fine. Edited February 18, 2018 by Au3Builder Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now