Skip to content

Loading…

Add 64bit support and improve admin detection #10

Merged
merged 2 commits into from

3 participants

@dignifiedquire

I've added the ability to detect the architecture and switch thes nssm.exe based on that. (As disscussed in #9)
Also the admin detection was not working so I've changed that based on this question on SO:
http://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights

@dignifiedquire

Fixed it.

@HeyHugo

I think administrator detection is not needed since the command line will output this feedback anyway when needed, see issue #11

@jfromaniello

@HeyHugo are you sure? I remember adding this check because back then nssm.exe didn't show anything and silently failed saying that the service was installed or something alike. I will double check

@HeyHugo

At least for me the latest nssm 2.16 (which is used in winser) fails with output: "Administrator access is needed to install a service." if I don't run it as administrator.

@jfromaniello jfromaniello merged commit 3019a2c into jfromaniello:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 7 deletions.
  1. BIN bin/nssm64.exe
  2. +19 −7 bin/winser
View
BIN bin/nssm64.exe
Binary file not shown.
View
26 bin/winser
@@ -50,10 +50,13 @@ if (!(fs.existsSync||path.existsSync)(path.join(program.path, "package.json"))){
var appName = require(path.join(process.cwd(), "package.json")).name;
+
+
sequence
.then(function(next){
- exec("whoami /groups | findstr /c:\"S-1-5-32-544\" | findstr /c:\"Enabled group\"", function(err, r){
- if(r.length === 0){
+ // Based on http://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights
+ exec("net session", function(err){
+ if(err && err.code !== 0){
log("You must run this tool as an administrator");
process.exit();
}else{
@@ -90,11 +93,19 @@ sequence
next(err, npmPath);
});
})
- .then(function(next, err, npmLocation){
+ .then(function(next, err, npmLocation){
+ exec('wmic OS get OSArchitecture', function(err, stdout, stderr) {
+ var architecture = stdout.match(/([2346]{2})\-Bit/)[1];
+ next(err, npmLocation, architecture);
+ });
+ })
+ .then(function(next, err, npmLocation, architecture){
+ var nssmExe = architecture === '64' ? 'nssm64.exe' : 'nssm.exe';
if(program.install){
- exec('\"{binfolder}\\nssm.exe\" install {serviceName} "{npmLocation}" start "\\"{appFolder}\\""'.supplant({
+ exec('\"{binfolder}\\{nssmExe}\" install {serviceName} "{npmLocation}" start "\\"{appFolder}\\""'.supplant({
binfolder: __dirname,
serviceName: appName,
+ nssmExe: nssmExe,
npmLocation: npmLocation,
appFolder: fs.realpathSync(".")
}), function(err,stdout, stderr){
@@ -106,9 +117,10 @@ sequence
next();
});
}else if(program.remove){
- exec("\"{binfolder}\\nssm.exe\" remove {serviceName} confirm".supplant({
+ exec("\"{binfolder}\\{nssmExe}\" remove {serviceName} confirm".supplant({
binfolder: __dirname,
- serviceName: appName
+ serviceName: appName,
+ nssmExe: nssmExe
}), function(err,stdout, stderr){
if(stderr){
!program.silent && console.error(stderr);
@@ -118,4 +130,4 @@ sequence
next();
});
}
- });
+ });
Something went wrong with that request. Please try again.