Hello
I'm New User in this forum
I need to simple code in Vb.Net for Open / close USB Port (Windows 7) ...
I'm waiting replay
and Thanks you
PS : I do not know Good the English language
Hello
I'm New User in this forum
I need to simple code in Vb.Net for Open / close USB Port (Windows 7) ...
I'm waiting replay
and Thanks you
PS : I do not know Good the English language
A short, practical summary tied to the earlier replies from and .
Windows 7 does not expose a simple, supported “power on/off this physical USB jack” API from user mode — the hub power-cycle IOCTLs that exist for newer Windows versions are not supported on Vista/Windows 7. (learn.microsoft.com) That means two reliable, commonly used approaches on Windows 7 are: (A) block USB mass‑storage by changing the USB storage service/driver (simple, system-wide for storage devices only), or (B) enable/disable specific devices/hubs (targeted, requires admin tools or SetupAPI calls). The registry approach is officially documented by Microsoft for blocking USB storage. (support.microsoft.com)
A minimal VB.Net pattern for the registry option (affects only USB mass‑storage drivers; keyboards/mice remain usable). Back up the registry; run the program elevated.
Imports Microsoft.Win32
Using k As RegistryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", writable:=True)
If k IsNot Nothing Then
k.SetValue("Start", 4, RegistryValueKind.DWord) ' 4 = disabled (set to 3 to enable)
k.Close()
End If
End Using For targeted device control, 's DevCon idea is valid: DevCon (a WDK tool) can enable/disable devices but requires the correct x86/x64 build and Administrator rights; the DevCon docs and WDK tool index explain where the matching binaries come from. (learn.microsoft.com) If embedding control into an app without external tools is required, the programmatic route uses the SetupAPI (DIF_PROPERTYCHANGE / SetupDi* calls) to request device enable/disable — it is more complex but is the supported programmatic path. (learn.microsoft.com)
Cautions: running these actions requires Administrator privileges; changing the registry or disabling drivers can affect system behavior — back up and test on a nonproduction machine first.
Jump to Post— trpsjt2008 0U can Open Window Dialog By Shell
Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")I'm trying to find the way without dialog
now i converting vb to vb.net
Thanks you
but...
I did not understand this code
do this in VB.Net 2008?
I cannot useing this code
pleas help me
U can Open Window Dialog By Shell
Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll") I'm trying to find the way without dialog
now i converting vb to vb.net
Copy This File into your folder
From Microsoft
And Then use this code
Shell(Application.StartupPath & "\devcon.exe disable *USBSTOR*") to Disable All USB Storage
Shell(Application.StartupPath & "\devcon.exe enable *USBSTOR*")[/ You can change *USBSTOR* to *CDROM To disable/enable all CDROM Drive or Anything Device ID
*usb\ROOT_HUB* ' I'm Not Sure About This But It Can Change all USB Port
Thanks You
i'm has used this code
but while run program :
click Turn On Or Click Turn Off show this window :
Pleas help Me
pleas help Me
Sorry
You Need To Extract file first before you use the file
Extract file And Copy The Inner file /i386/Devcon.exe
file to your directory
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.