Executing createShortcut on Squirrel event in Electron application

I am trying to create shortcuts for my Electron app when I install or update it, however I am having trouble executing the command to create a shortcut. The default electronic applications are "SquirrelAware", so I have to specify where I would like to create shortcuts.

My question is related to the accepted answer to this question.

Handle Squirrel event in Electron app

I tried using module exec

and module child_process

, however both did not work. Right now I am trying (and failing) to start PowerShell and run a script there that will create shortcuts in my Start and Desktop menus, however I believe this is quite long and that there should be an easier way.

Here is my current attempt using the child_process module and PowerShell:

 var spawn = require('child_process').spawn, child;
 child = spawn("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",["C:\\ElectronSquirrelDemo\\AddAppShortcuts.ps1 -SourceExe "+ executionPath] );
                child.stdout.on('data', function(data){
                    console.log("PowerShell Data: " + data);
                });
                child.stdout.on('data', function(data){
                    console.log("PowerShell Error: " + data);
                });
                child.stdout.on('exit', function(){
                   console.log('PowerShell script finished'); 
                });

      

Any help on this would be much appreciated

+3


source to share


1 answer


It took me a while to figure out how to do it myself. Squirrel.Windows Update.exe has the ability to create shortcuts for your application for you. I wrote a blog post titled Building a Windows Distribution of an Electron Application with Squirrel and in it, Squirrel has created shortcuts for me. If you want to go that route, this is a simplified version of how to get Squirrel to create shortcuts for you:

var cp = require('child_process');    
var updateDotExe = path.resolve(path.dirname(process.execPath), '..', 'update.exe');
var target = path.basename(process.execPath);
var child = cp.spawn(updateDotExe, ["--createShortcut", target], { detached: true });
child.on('close', function(code) {
    app.quit();
});

      



You need to hack the executable with Resource Hacker, rcedit or another application to change the ProductName and Icon resources. You will want to call the above code to both install and update Squirrel events.

+4


source







All Articles