Skip to content

Instantly share code, notes, and snippets.

View brad-jones's full-sized avatar

Brad Jones brad-jones

View GitHub Profile
@brad-jones
brad-jones / libc.js
Created August 18, 2021 08:23 — forked from hinzundcode/libc.js
call execve from nodejs!
const { syscall, getAddress } = require("libsys");
const os = require("os");
if (os.endianess() != "LE")
throw "only little endian supported";
let dontGC = [];
function ref(buffer) {
dontGC.push(buffer);
return getAddress(buffer);
@brad-jones
brad-jones / Elevate when needed in Go.md
Created March 19, 2021 02:29 — forked from jerblack/Elevate when needed in Go.md
Relaunch Windows Golang program with UAC elevation when admin rights needed.

I'm buiding a command line tool in Go that has an option to install itself as a service on Windows, which it needs admin rights for. I wanted to be able to have it reliably detect if it was running as admin already and if not, relaunch itself as admin. When the user runs the tool with the specific switch to trigger this functionality (-install or -uninstall in my case) they are prompted by UAC (User Account Control) to run the program as admin, which allows the tool to relaunch itself with the necessary rights.

To detect if I was admin, I tried the method described here first:
https://coolaj86.com/articles/golang-and-windows-and-admins-oh-my/
This wasn't accurately detecting that I was elevated, and was reporting that I was not elevated even when running the tool in CMD prompt started with "Run as Administrator" so I needed a more reliable method.

I didn't want to try writing to an Admin protected area of the filesystem or registry because Windows has the ability to transparently virtualize those writes

@brad-jones
brad-jones / README.md
Last active August 29, 2015 14:14 — forked from peteboere/README.md