index.js
function tryWindowsKey (key, device, mac) {
  // Skip the Properties key to avoid problems with permissions
  if (key.indexOf('Properties') > -1) {
    return false
  }

  const networkAdapterKeyPath = new Winreg({
    hive: Winreg.HKLM,
    key: key
  })

  // we need to format the MAC a bit for Windows
  mac = mac.replace(/:/g, '')

  networkAdapterKeyPath.values((err, values) => {
    let gotAdapter = false
    if (err) {
      console.log('ERROR: ' + err)
    } else {
      for (let x = 0; x < values.length; x++) {
        if (values[x].name === 'AdapterModel') {
          gotAdapter = true
          break
        }
      }

      if (gotAdapter) {
        networkAdapterKeyPath.set('NetworkAddress', 'REG_SZ', mac, () => {
          try {
            cp.execSync('netsh interface set interface "' + device + '" disable')
            cp.execSync('netsh interface set interface "' + device + '" enable')
          } catch (err) {
            throw new Error('Unable to restart device, is the cmd running as admin?')
          }
        })
      }
    }
  })
}
function tryWindowsKey (key, device, mac) {
  // Skip the Properties key to avoid problems with permissions
  if (key.indexOf('Properties') > -1) {
    return false
  }

  const networkAdapterKeyPath = new Winreg({
    hive: Winreg.HKLM,
    key: key
  })

  // we need to format the MAC a bit for Windows
  mac = mac.replace(/:/g, '')

  networkAdapterKeyPath.values((err, values) => {
    let gotAdapter = false
    if (err) {
      console.log('ERROR: ' + err)
    } else {
      for (let x = 0; x < values.length; x++) {
        if (values[x].name === 'AdapterModel') {
          gotAdapter = true
          break
        }
      }

      if (gotAdapter) {
        networkAdapterKeyPath.set('NetworkAddress', 'REG_SZ', mac, () => {
          try {
            cp.execSync('netsh interface set interface "' + device + '" disable')
            cp.execSync('netsh interface set interface "' + device + '" enable')
          } catch (err) {
            throw new Error('Unable to restart device, is the cmd running as admin?')
          }
        })
      }
    }
  })
}
function tryWindowsKey ( key , device , mac ) { // Skip the Properties key to avoid problems with permissions if ( key . indexOf ( 'Properties' ) > - 1 ) { return false } const networkAdapterKeyPath = new Winreg ( { hive : Winreg . HKLM , key : key } ) // we need to format the MAC a bit for Windows mac = mac . replace ( / : / g , '' ) networkAdapterKeyPath . values ( ( err , values ) => { let gotAdapter = false if ( err ) { console . log ( 'ERROR: ' + err ) } else { for ( let x = 0 ; x < values . length ; x ++ ) { if ( values [ x ] . name === 'AdapterModel' ) { gotAdapter = true break } } if ( gotAdapter ) { networkAdapterKeyPath . set ( 'NetworkAddress' , 'REG_SZ' , mac , ( ) => { try { cp . execSync ( 'netsh interface set interface "' + device + '" disable' ) cp . execSync ( 'netsh interface set interface "' + device + '" enable' ) } catch ( err ) { throw new Error ( 'Unable to restart device, is the cmd running as admin?' ) } } ) } } } ) }
Tries to set the "NetworkAddress" value on the specified registry key for given
`device` to `mac`.

@param {string} key
@param {string} device
@param {string} mac
Tries to set the NetworkAddress value on the specified registry key for given device to mac .