Skip to content

Instantly share code, notes, and snippets.

@nir9
Last active December 4, 2023 03:43
Show Gist options
  • Save nir9/dd09bcb8b47874d5b719fef24f05eecd to your computer and use it in GitHub Desktop.
Save nir9/dd09bcb8b47874d5b719fef24f05eecd to your computer and use it in GitHub Desktop.
Beep with a ioctl
#include <stdio.h>
#include <cstdint>
#include <Windows.h>
struct Beep
{
uint32_t freq;
uint32_t duration;
};
void main()
{
HANDLE handle = CreateFileA("\\\\.\\GLOBALROOT\\Device\\Beep", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
ULONG code = 0x10000;
for (int i = 0;;i+=10)
{
struct Beep input = {};
input.freq = 2000+i;
input.duration = 50;
DeviceIoControl(handle, code, &input, sizeof(input), nullptr, 0, nullptr, nullptr);
Sleep(100);
}
CloseHandle(handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment