Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exit at-driver with error if run as admin #4

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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.
Expand Down Expand Up @@ -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),
Expand Down