From 08440d4353f40d9229ceb91c6ce9f1e950f32994 Mon Sep 17 00:00:00 2001 From: geetanshjain Date: Wed, 11 Aug 2021 16:28:43 +0530 Subject: [PATCH] fix(windows): connect network for non-admin users (#164) ## Description While connecting to a network in windows by a non-admin user, the connection fails if the project/package-workspace is under some restricted location (Ex: Program Files) because the nodeWifiConnect.xml is created is not getting created due to permission issues. Changed the location of nodeWifiConnect.xml to be created in a temporary directory (C:\Users\AppData\Local\Temp) so that work flow is uninterrupted for non-admin user also. ## Motivation and Context This change is required as all window users (Admin and Non-Admin) should be able to connect to the network. #159 ## How Has This Been Tested? After the required changes are done, we tried to connect to the network in a non-admin user machine, which works as expected. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactorization (non-functional change which improve code readibility) --- src/windows-connect.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/windows-connect.js b/src/windows-connect.js index da54b94..11e80c1 100644 --- a/src/windows-connect.js +++ b/src/windows-connect.js @@ -2,6 +2,9 @@ const fs = require('fs'); const execFile = require('child_process').execFile; const env = require('./env'); const scan = require('./windows-scan'); +const path = require('path'); +const os = require('os'); +const profileFilename = path.join(os.tmpdir(), 'nodeWifiConnect.xml'); function execCommand(cmd, params) { return new Promise((resolve, reject) => { @@ -31,7 +34,7 @@ function connectToWifi(config, ap, callback) { } fs.writeFileSync( - 'nodeWifiConnect.xml', + profileFilename, win32WirelessProfileBuilder(selectedAp, ap.password) ); }) @@ -40,7 +43,7 @@ function connectToWifi(config, ap, callback) { 'wlan', 'add', 'profile', - 'filename="nodeWifiConnect.xml"' + `filename=${profileFilename}` ]); }) .then(() => { @@ -57,7 +60,7 @@ function connectToWifi(config, ap, callback) { return execCommand(cmd, params); }) .then(() => { - return execCommand('del ".\\nodeWifiConnect.xml"'); + return execCommand(`del ${profileFilename}`); }) .then(() => { callback && callback();