How to use node-windows - 10 common examples

To help you get started, we’ve selected a few node-windows examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jon-hall / pm2-windows-service / test / integration.js View on Github external
'use strict';

const assert = require('assert'),
    util = require('util'),
    path = require('path'),
    co = require('co'),
    promisify = require('promisify-node'),
    exec = promisify(require('child_process').exec),
    node_win = require('node-windows'),
    elevate = promisify(node_win.elevate),
    Service = node_win.Service,
    fsx = promisify('fs-extra'),
    temp = require('temp').track(),
    mkdir_temp = promisify(temp.mkdir),
    sid = get_sid();

co(function*() {
    // We deploy everything to a temp dir to avoid creating daemon files in this repo
    let temp_dir = yield mkdir_temp('pm2-windows-service-test');

    // Use npm to install ourselves to the temp dir
    // First thing we need is a skeleton package.json in the temp dir (otherwise it doesn't install there)
    let pkg = { name: path.basename(temp_dir), version: '0.0.1' };
    yield fsx.writeJson(path.resolve(temp_dir, 'package.json'), pkg);

    // Now we can 'npm install' there
github kennethrisa / discord-rustserverstatus / install / uninstallSVC.js View on Github external
// for windows - uninstall windows service
var Service = require('node-windows').Service;
 
// Create a new service object
var svc = new Service({
  name:'discord-rustserverstatus',
  script: require('path').join(__dirname,'app.js')
});
 
// Listen for the "uninstall" event so we know when it's done.
svc.on('uninstall',function(){
  console.log('Uninstall complete.');
  console.log('The service exists: ',svc.exists);
});
 
// Uninstall the service.
svc.uninstall();
github ioBroker / ioBroker.js-controller / build / windows / uninstall.js View on Github external
var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'ioBroker',
  script: require('path').join(__dirname, 'controller.js')
});

// Listen for the "uninstall" event so we know when it's done.
svc.on('uninstall',function(){
  console.log('Uninstall complete.');
  console.log('The service exists: ',svc.exists);
});

// Uninstall the service.
svc.uninstall();
github sematext / logagent-js / bin / logagent-windows.js View on Github external
grow: 0.5
    })
    svc.on('error', console.log)
    // Listen for the "install" event, which indicates the
    // process is available as a service.
    svc.on('install', function () {
      console.log('Logagent service installed')
      svc.start()
    })
    svc.on('start', function () {
      console.log('Logagent service started')
    })
    svc.install()
  } else if (process.argv[2] === '-uninstall') {
    let Service = require('node-windows').Service
    let svc = new Service({
      name: 'Logagent',
      description: 'Sematext Logagent',
      script: process.mainModule.filename
    })
    svc.on('uninstall', function () {
      console.log('Service Logagent removed.')
    })
    svc.uninstall()
  } else {
    if (process.argv.join(',').indexOf('--config') === -1) {
      // use default config
      process.argv.push('--config')
      process.argv.push(process.env.LOGAGENT_CONFIG || process.env.ProgramData + '\\Sematext\\logagent.conf')
    }
    var la = new (require('./logagent.js'))()
    if (!la) {
github sematext / logagent-js / bin / logagent-windows.js View on Github external
#!/usr/bin/env node
'use strict'
try {
  if (process.argv[2] === '-install') {
    var laCmd = process.mainModule.filename
    // var exec = require('child_process').execSync
    // exec('powershell -command "Set-ItemProperty -Path \'Registry::HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment\' -Name LOGAGENT_CONFIG –Value \'' + process.argv[3] +'\'',{stdio: [0,1,2]})
    console.log(laCmd)
    let Service = require('node-windows').Service
    let svc = new Service({
      name: 'Logagent',
      description: 'Sematext Logagent',
      script: laCmd,
      wait: 2,
      grow: 0.5
    })
    svc.on('error', console.log)
    // Listen for the "install" event, which indicates the
    // process is available as a service.
    svc.on('install', function () {
      console.log('Logagent service installed')
      svc.start()
    })
    svc.on('start', function () {
      console.log('Logagent service started')
    })
github ioBroker / ioBroker.js-controller / build / windows / install.js View on Github external
var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'ioBroker',
  description: 'ioBroker Controller service.',
  script: require('path').join(__dirname, 'controller.js'),
  env:{
    name: "NODE_ENV",
    value: "production"
  }
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function (){
  svc.start();
});

// Just in case this file is run twice.
github kennethrisa / discord-rustserverstatus / install / installSVC.js View on Github external
// for windows
// Install as a service
// https://stackoverflow.com/questions/20445599/auto-start-node-js-server-on-boot?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'discord-rustserverstatus',
  description: 'Updates activity status on discord bot and displays how many players are connect to your rust server from rest api',
  script: require('path').join(__dirname,'app.js')
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();
github jon-hall / pm2-windows-service / src / install.js View on Github external
yield common.admin_warning();

    let setup_response = yield no_setup ? Promise.resolve({
        perform_setup: false
    }) : inquirer.prompt([{
        type: 'confirm',
        name: 'perform_setup',
        message: 'Perform environment setup (recommended)?',
        default: true
    }]);

    if(setup_response.perform_setup) {
        yield setup();
    }

    let service = new Service({
        name: name || 'PM2',
        script: path.join(__dirname, 'service.js')
    });

    // Let this throw if we can't remove previous daemon
    try {
        yield common.remove_previous_daemon(service);
    } catch(ex) {
        throw new Error('Previous daemon still in use, please stop or uninstall existing service before reinstalling.');
    }

    // NOTE: We don't do (name = name || 'PM2') above so we don't end up
    // writing out a sid_file for default name
    yield* save_sid_file(name);

    yield* kill_existing_pm2_daemon();
github logdna / logdna-agent / test / lib / windows-utilities.js View on Github external
describe('lib:windows-utilities', function() {
    if (os.platform() !== 'win32') {
        return;
    }

    var EventLogger = require('node-windows').EventLogger;
    var log = new EventLogger(provider);

    describe('#streamEventLog()', function() {
        it('streams event logs to a socket', function() {
            this.timeout(100000);
            const MockWebSocket = require('mock-socket').WebSocket;
            const MockServer = require('mock-socket').Server;
            var server = new MockServer('ws://localhost:40002');
            var socket = new MockWebSocket('ws://localhost:40002');
            socket.connected = true;
            var lineBuffer = require('../../lib/linebuffer');
            lineBuffer.setSocket(socket);
            var windowsUtilities = requireUncached('../../lib/windows-utilities');

            return new Promise((resolve) => {
                server.on('message', data => {
                    debug('received message!');
github nitzzzu / alexa-local-skills / winservice.js View on Github external
const Service = require('node-windows').Service;

let svc = new Service({
    name: 'AlexaSkills',
    description: 'Alexa Skills',
    script: require('path').join(__dirname, 'server.js'),
    maxRetries: 3
});

svc.on('install', function() {
    console.log('Install complete. Starting...');
    svc.start();
    console.log('Service started');
});

svc.on('uninstall', function() {
    console.log('Uninstall complete.');
    console.log('The service exists: ', svc.exists);
});

node-windows

Support for Windows services, event logging, UAC, and several helper methods for interacting with the OS.

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis