From 33c6fc3422800902f384c2714b658679e000b5c5 Mon Sep 17 00:00:00 2001 From: Michael Z Goddard Date: Mon, 13 Dec 2021 12:09:47 -0500 Subject: [PATCH] fix: exit at-driver with error if run as admin --- lib/cli.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/cli.js b/lib/cli.js index c7eecb2..0033730 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,5 +1,8 @@ 'use strict'; +const {exec} = require('child_process'); +const {promisify} = require('util'); + const yargs = require('yargs/yargs'); const { hideBin } = require('yargs/helpers'); @@ -8,6 +11,16 @@ const createVoiceServer = require('./create-voice-server'); const NAMED_PIPE = '\\\\?\\pipe\\my_pipe'; const DEFAULT_PORT = 4382; + +const isAdmin = async () => { + try { + await promisify(exec)('net session'); + return true; + } catch ({}) { + return false; + } +}; + /** * Print logging information to the process's standard error stream, annotated * with a timestamp describing the moment that the message was emitted. @@ -35,6 +48,15 @@ module.exports = async (process) => { }) .parse(); + if (await isAdmin()) { + // Running at-driver with admin privilege creates the named pipe so that admin privilege is + // required to connect to the pipe. An application, such as a screen reader, using the + // automation voice will try to connect to the pipe and likely fail as it will be unlikely to + // have been run with admin privilege. + log(`executed with admin privilege. run at-driver without admin privilege.`); + process.exit(1); + } + const [commandServer, voiceServer] = await Promise.all([ createCommandServer(argv.port), createVoiceServer(NAMED_PIPE),