Power off an USB device in software on Windows

Some USB hubs have the ability to turn power off to its downstream devices. “Is it possible to power up ports on a USB hub from Ubuntu?” https://askubuntu.com/questions/149242/is-it-possible-to-power-up-ports-on-a-usb-hub-from-ubuntu Which points to some c source for hub-ctrl.c See: http://www.gniibe.org/development/ac-power-control-by-USB-hub/index I tested this on Ubuntu with a Dream-Cheeky USB LED unit, and it did seem to turn … Read more

Is it safe to cast SOCKET to int under Win64?

The simple answer to this question is no. Take a look at the description of SOCKET values on MSDN [1]: Windows Sockets handles have no restrictions, other than that the value INVALID_SOCKET is not a valid socket. Socket handles may take any value in the range 0 to INVALID_SOCKET–1. So clearly, the API allows all … Read more

How to programmatically move Windows taskbar?

I also have this need on Windows 7. Here is my take to do this using autohotkey script: ; This script will try to drag and move the taskbar to where the *current* mouse ; cursor is ; 0x111: WM_COMMAND, 424: lock/unlock taskbar, http://www.codeproject.com/KB/miscctrl/Taskbar_Manipulation.aspx RegRead, TaskbarLocked, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced, TaskbarSizeMove If TaskbarLocked = 0 SendMessage 0x111, … Read more

Win10 dark theme – how to use in WINAPI?

See https://github.com/ysc3839/win32-darkmode This guy has it all laid out in some nice reusable code (MIT license). It seems that Dark Mode is still an area of development in Windows 10, but I believe that Microsoft will eventually properly document and expose it to desktop apps. Until then, we are stuck with undocumented ordinal-only imports, then … Read more

How is it possible to access memory of other processes?

In all likelyhood, the tool uses ReadProcessMemory or some variant, which requires PROCESS_VM_READ access. With respect to your “malicious” comment, remember that you (or the process invoking this API, which likely needs Administrator-level permissions) already has total control over the machine. The security game is already lost at this point.

What happens internally when a file path exceeds approx. 32767 characters in Windows?

Because I’m lazy, I didn’t write a test program but tested it using the excellent Far Manager which handles things like long paths (longer than MAX_PATH) or special filenames (con, prn etc) just fine. I made a string of exactly 255 characters (“12345678901234…012345”) and started creating nested directories. Luckily, Far’s “Make Directory” function takes a … Read more

How to call an external program with parameters?

When you call CreateProcess(), System(), etc., make sure you double quote your file name strings (including the command program filename) in case your file name(s) and/or the fully qualified path have spaces otherwise the parts of the file name path will be parsed by the command interpreter as separate arguments. system(“\”d:some path\\program.exe\” \”d:\\other path\\file name.ext\””); … Read more