kessler / node-regedit

Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host
MIT License
279 stars 45 forks source link

unsupported hive error while read chrome.exe #62

Closed hl-a-k closed 4 years ago

hl-a-k commented 5 years ago

I need know path of chrome.exe, here is my code:

var regedit = require('regedit')

regedit.list('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe', function(err, result) {
  if (err) {
    return
  }
  console.log(result)
})

And I get

{"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe": 
unsupported hive HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe

My machine is windows 10.

hubei207 commented 5 years ago

I also encountered this problem, I don't know how to solve it.

bradisbell commented 5 years ago

Instead of HKEY_LOCAL_MACHINE, use HKLM.

xieerduos commented 3 years ago
这么写会报错
regedit.list('HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', (err, data) => {
        if (err) {
            console.log(err);
        }
        console.log('data: ', data);
    });

HKEY_CURRENT_USER简写为 HKCU, 改成下面的写法就可以了

    regedit.list('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', (err, data) => {
        if (err) {
            console.log(err);
        }
        console.log('data: ', data);
    });
xieerduos commented 3 years ago

"vue-cli-plugin-electron-builder": "^1.4.6",

// vue.config.js
module.exports = {
    pluginOptions: {
        electronBuilder: {
                extraResources: [
                    {
                        from: 'node_modules/regedit/vbs',
                        to: 'vbs',
                        filter: ['**/*']
                    }
                ],
        }
     }
}
// setRegedit.js
import path from 'path';
import electron from 'electron';
import regedit from 'regedit';

export function setExternalVBSLocation() {
    // 打包时vbs 单独抽离出来,一起打包regedit会读取不了
    // 官网地址:https://github.com/ironSource/node-regedit

    // Assuming the files lie in <app>/resources/my-location
    const vbsDirectory = path.join(path.dirname(electron.remote.app.getPath('exe')), './resources/vbs');
    regedit.setExternalVBSLocation(vbsDirectory);
}

export default function setRegedit() {
    setExternalVBSLocation();

    // HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run
    // HKCU === HKEY_CURRENT_USER (当前用户sid)
    // 为什么是HKCU?因为regedit不支持HKEY_CURRENT_USER开头的形式,具体请看下面的issues链接
    // https://github.com/ironSource/node-regedit/issues/62
    regedit.list('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', (err, data) => {
        if (err) {
            console.log(err);
        }
        console.log('data: ', data);
    })
}