Skip to content

Commit

Permalink
fix(windows): connect network for non-admin users (#164)
Browse files Browse the repository at this point in the history
## 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<userId>\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)
  • Loading branch information
geetanshjain committed Aug 11, 2021
1 parent 1eeaa50 commit 08440d4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/windows-connect.js
Expand Up @@ -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) => {
Expand Down Expand Up @@ -31,7 +34,7 @@ function connectToWifi(config, ap, callback) {
}

fs.writeFileSync(
'nodeWifiConnect.xml',
profileFilename,
win32WirelessProfileBuilder(selectedAp, ap.password)
);
})
Expand All @@ -40,7 +43,7 @@ function connectToWifi(config, ap, callback) {
'wlan',
'add',
'profile',
'filename="nodeWifiConnect.xml"'
`filename=${profileFilename}`
]);
})
.then(() => {
Expand All @@ -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();
Expand Down

0 comments on commit 08440d4

Please sign in to comment.