Please help me... i am trying to figure out how to control the power supply of a certain USB port using VB6.. i improvised a Locking device which is USB mode.. and when the locking device attached to the PC via USB, it will Lock and how can i cut off the powersupply cause when the power is cut, the locking device will be open.. so is ther any possible way to turn power supply on and off of USB port via VB6?

Dani AI

Generated

Short answer: you generally cannot reliably turn the 5 V VBUS power of an arbitrary motherboard USB port on and off from VB6 alone. Windows does not expose a simple, guaranteed user‑mode API that cuts VBUS for every hub/port — the hub driver and the physical hardware determine whether a port can actually be powered down. That means software tricks like registry edits or just unloading a device driver often do not remove the 5 V supply. described a lock that opens only when power is removed; for that behavior the solution is usually hardware or a low‑level hub control, not pure VB6.

Practical approaches that work in real systems:

  • Hardware: use a USB hub or a USB relay module that supports per‑port power switching (or an external relay controlled by a microcontroller). This is the most reliable way to cut VBUS.
  • Software (best effort): disable/enable the USB device or hub port from Windows (requires admin). Tools like Microsoft’s DevCon or SetupAPI/SetupDi functions can disable a device, which may stop it from functioning — but it may not remove VBUS on all hubs. For VB6 you can invoke DevCon from a script or WScript.Shell and wait for the return code:
Dim sh As Object
Set sh = CreateObject("WScript.Shell")
ret = sh.Run("C:\tools\devcon.exe disable ""USB\VID_XXXX&PID_YYYY""", 0, True)

Advanced option: a native helper (or kernel driver) can open the hub and send USB hub IOCTLs to change port state or cycle a port. That requires native code and careful admin/driver work; community threads (as hinted) often show examples — but they are not trivial and can vary by Windows version and hardware.

Notes and cautions: admin rights are required. Disabling ports can break keyboards/mice or cause instability if the wrong port is targeted. If the lock must open only when VBUS is removed, the hardware relay/hub route is the safest and most reliable choice. For implementation details, read Microsoft’s USB driver docs and the DevCon documentation: USB on Windows drivers and DevCon utility.

Recommended Answers

All 4 Replies

using reg object.

i guess


4ukh

using reg object.

i guess


4ukh

can you please specify it.. please... i really need Help!

Have you already solved your problem? I hace the same problem! I need to turn power supply on and off of USB port!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.