Skip to content

The process cannot access the file because it is being used by another process #6

@EvenAR

Description

@EvenAR

Hello,

I have tried to follow the steps provided in the readme. However, when the updater is finished I get the following message in updater.log:

2017/03/30 18:55:09 C:\Users\Even\AppData\Roaming\vnpc2\VNPCv2.exe: creating new file: open C:\Users\Even\AppData\Roaming\vnpc2\VNPCv2.exe: The process cannot access the file because it is being used by another process.

Am I doing something wrong in my code? I assume the reason is that my NW client is not 100% closed when the updater is trying to replace VNPCv2.exe.

This is the code I use to start the update:

if(newUpdate) {
	alert("Update found! I will now download the update...");

	var url = global.va.getUpdateUrl();
	var TMP_DIR = require('os').tmpdir() + "/vnpcUpdate";

	var download = require('download-file')
	
	download(url, { directory: TMP_DIR, filename: "update.zip" }, function(err){
		const shell = nw.require('shelljs');
		const path = nw.require('path');

		const APPDIR = path.dirname(process.execPath);
		const UPDATER_BIN = TMP_DIR + '/updater.exe';
		
		shell.cp(APPDIR + '/updater.exe', UPDATER_BIN);
		shell.chmod(755 & ~process.umask(), UPDATER_BIN);

		const spawn = require('child_process').spawn;
		alert("Update downloaded. I will now quit in order to install the new update.");

		spawn(UPDATER_BIN, [
			'--bundle', 'update.zip',
			'--inst-dir', APPDIR
		], {
			cwd: path.dirname(UPDATER_BIN),
			detached: true,
			stdio: 'ignore'
		}).unref();
		
		nw.App.quit();
	});
}

updater.exe is built using GOOS=windows GOARCH=386 go build -ldflags "-s -w -H=windowsgui" -o updater.exe nwjs-autoupdater with the <requestedExecutionLevel level="asInvoker" uiAccess="false"/> set in the manifest-file.

I have also tried with <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>, however this gives me this error in my application when trying to execute the updater:

Error: spawn EACCES
unless I run my app "As administrator" - In that case I get the same problem as described earlier.

My application executable (VNPCv2.exe) is built using nw-builder

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions