Skip to content

About

Native windows api binding for nodejs

Topics

Resources

Stars

61 stars

Watchers

4 watching

Forks

Repository files navigation

winapi

Misc natives MS Windows API wrappers for nodejs & nwjs

Version License Available platform Available platform Code style

Windows x64 builds: Node.js 8, 16 and 24

The GitHub workflows share three independent build/test jobs:

Target runtime Native ABI Packaged prebuild
Node.js 8.17.0 57 winapi.abi57.node
Node.js 16.20.2 93 winapi.abi93.node
Node.js 24.16.0 137 winapi.abi137.node

Each job installs dependencies and builds with Windows x64 Node.js 24, Python 3.11 and the local node-gyp toolchain. It then switches to its target Node runtime and runs both the prebuild smoke test and the Mocha suite. The loader is forced to use the ABI-tagged prebuild, not build/Release or an older binary. The build targets are independent: one failure does not cancel the other tests.

A final job runs only after all three series pass. It merges the prebuilds, builds the unsigned WinAPI.exe helper and creates an npm .tgz containing all three binaries. It verifies the archive's file list before uploading the winapi-windows-x64-package artifact. The shared test/build workflow does not sign or publish; the publish workflow handles those operations afterwards.

Branch pushes and pull requests run test.yml; tags matching v* and manual runs use publish.yml. Both call the same native.yml, so release artifacts follow exactly the same three test series. After those jobs pass, the publish workflow signs and verifies WinAPI.exe, then repacks the signed executable and all three prebuilds. Tag runs retain npm and GitHub release publication; manual runs only produce signed artifacts. The historical NW.js/ia32 build remains in make.bat but is not part of these Windows x64 jobs.

Local build from Windows or WSL

Install Windows x64 Node.js 24, Python 3 and Visual Studio 2022 Build Tools with the Desktop development with C++ workload and a Windows SDK. From the source checkout in PowerShell, using Windows Node/npm:

npm install --ignore-scripts --package-lock=false
# Optional: select your actual Python 3 executable.
$env:WINAPI_PYTHON = 'C:\Python311\python.exe'
npm run test:build
npm run build:native -- 8.17.0
npm run build:native -- 16.20.2
npm run build:native -- 24.16.0

All three builds use the Node 24 build host; build:node24 is also available as a shortcut for the last target. To test a target, run npm run test:prebuild and npm test with that target's Windows Node executable and PREBUILDS_ONLY=1. Do not reinstall the modern build dependencies under Node 8. Mouse/input-dependent tests are opt-in through WINAPI_INTERACTIVE_TESTS=1; default tests do not manipulate the desktop or require user interaction.

In WSL, launch Windows PowerShell from the shared checkout. Linux Node is not a Windows build/test runtime. The smoke test only calls read-only native APIs; it does not change the clock, move the mouse, assign a job group or invoke the C# display helper. Keep OS-specific dependencies isolated.

API

Building and signing

The Windows test workflow builds the native prebuilds and WinAPI.exe without signing. Tests use PREBUILDS_ONLY=1 so a leftover build/Release binary cannot hide a missing or incompatible packaged prebuild.

The publish workflow builds and signs WinAPI.exe through 131/gh-actions/sign-binaries@v1, then checks its Authenticode signature on Windows. Set the repository secret SIGNING_SERVER to the current Janus winapi preset URL supplied by the administrator. Never commit that URL's token. Janus must reload its configuration after a preset is created or changed.

workflow_dispatch produces a signed artifact without publishing npm or a GitHub release. A v<package.json version> tag additionally publishes npm through OIDC trusted publishing and the executable/prebuild archive to GitHub. Configure the npm trusted publisher for 131/node-winapi, workflow publish.yml; no npm token is required. No version is bumped by the workflow.

For local signing, use SIGNING_SERVER=… bash make --sign. An explicit environment value takes precedence over .env; the old local URL/token may be obsolete. The script does not trace secrets and preserves the original executable if signing fails. bash make --build --build-cs --test builds and runs the tests.

Build-script regression tests run on Linux: node scripts/test-build-script.js.

require('winapi').getIdleTime()

Return the time the system has been idle (since last user interaction - e.g. mouse, keyboard & stuffs, see GetLastInputInfo) This is really usefull if you want to create a screensaver/like in nodejs / node-webkit.

var winapi = require('winapi');

console.log("System is idle since %s", winapi.getIdleTime() );

require('winapi').CreateJobGroup()

Create a job group with current process and all future child_process. Use this to kill zombies. Like Rick.

var winapi = require('winapi');

winapi.CreateJobGroup();

//you can now spawn subprocess and they'll be killed once you died, windows will clean everything up

  • (checkout my dispatcher project for inspiration)
  • Available for node 8, nw 26 and nw 14. (i did not re-compile other platform binaries, do it by yourself...)

require('winapi').GetLastInputInfo()

Use this native binding to get system last input time (see MSDN )

var winapi = require('winapi');

console.log("Last input time is %s", winapi.GetLastInputInfo() );

setTimeout(function(){
  //do not move, it wont change !
  console.log("Last input time is %s", winapi.GetLastInputInfo() );
}, 1000);

require('winapi').GetChildrenProcess([parentProcessId])

List all children process (of specified parent PID, default to current process)

require('winapi').GetParentProcess([childProcessId])

Get a process parent PID (of specified process PID, default to current process)

require('winapi').GetTickCount()

Retrieves the number of milliseconds that have elapsed since the system was started (uptime). (see MSDN )

require('winapi').GetDisplaysList(console.log)

List all connected screens

Credits

  • 131
  • Code signing, courtesy of IVS Group.

Keywords / shout box

screensaver, windows api, winuser.h, GetLastInputInfo, activity monitor, inactivity trigger, idle timer, system uptime, sytem bootime

About

Native windows api binding for nodejs

Topics

Resources

Stars

61 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages