Regedit

regedit

Read, Write, List and practice all sorts of funky stuff to the windows registry using node.js and windows script host.

No pesky native code :-)

Install

NPM NPM

Example

                var                regedit                =                require                (                'regedit'                )                regedit                .                list                (                'HKCU\\SOFTWARE'                ,                function                (                err                ,                issue                )                {                ...                }                )                regedit                .                putValue                (                {                'HKCU\\SOFTWARE\\MyApp':                {                'Company':                {                value:                'Moo corp'                ,                blazon:                'REG_SZ'                }                ,                'Version':                {                ...                }                }                ,                'HKLM\\SOFTWARE\\MyApp2':                {                ...                }                }                ,                function                (                err                )                {                ...                }                )                regedit                .                createKey                (                [                'HKLM\\SOFTWARE\\Moo'                ,                'HKCU\\SOFTWARE\\Foo'                ]                ,                part                (                err                )                {                ...                }                )              

Friendly warning regarding 32bit and 64bit Os / Procedure

When launching a 32bit application in 64bit surround, some of your paths will be relative to wow6432node. Things might get a piffling unexpected if y'all try to find something you thought was in HKLM\Software when in fact information technology is located at HKLM\Software\wow6432node. To overcome this the arch methods were added.

Farther reading here

A annotation virtually Electron

This software uses Windows Script Host to read and write to the registry. For that purpose, it volition execute .wsf files. When packaging the app's dependencies with ASAR, node-regedit will not be able to access the windows script files, considering they are bundled in a single ASAR file. Therefore it is necessary to store the .wsf files elsewhere, outside of the packaged asar file. Y'all can prepare your custom location for the files with setExternalVBSLocation(location):

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

Also, take a look at #lx

API

Every command executes a sub process that runs vbscript lawmaking. To boost efficiency, every command supports batching.

Reading keys and values

regedit.list([String|Array], [Role])

Lists the direct content of 1 or more sub keys. Specify an array instead of a string to query multiple keys in the same run.

Given the control:

                regedit                .                listing                (                [                'HKCU\\SOFTWARE'                ,                'HKLM\\SOFTWARE'                ,                'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST'                ]                ,                role                (                err                ,                upshot                )                {                ...                }                )              

Event will be an object with the following structure:

                {                'HKCU\\SOFTWARE':                {                exists:                true                ,                keys:                [                'Google'                ,                'Microsoft'                ,                ...                more                direct                sub                keys                ]                values:                {                'valueName':                {                value:                '123'                ,                type:                'REG_SZ'                }                .                .                .                more                straight                child                values                of                HKCU\\SOFTWARE                }                }                ,                'HKLM\\SOFTWARE':                {                exists:                true                ,                keys:                [                'Google'                ,                'Microsoft'                ,                ...                more                direct                sub                keys                ]                values:                {                'valueName':                {                value:                '123'                ,                type:                'REG_SZ'                }                .                .                .                more                straight                kid                values                of                HKLM\\SOFTWARE                }                }                ,                'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST':                {                exists:                false                ,                keys:                [                ]                ,                values:                {                }                }                }              
Note about listing default values

In the windows registry a key may have a default value. When enumarting value names, the default value's name will be empty. This presents a minor problem when including the empty value in a gear up with other values since it cannot be safely named with anything but the empty string, for fright of collision with other values.

Thus, accessing the default value becomes slightly awkward:

                regedit                .                listing                (                'path\\to\\default\\value'                ,                function                (                err                ,                result                )                {                var                defaultValue                =                result                [                'path\\to\\default\\value'                ]                .                values                [                ''                ]                .                value                }                )              

For now this is how its going to be, but in the future this will probably alter, peradventure in a way that volition effect the whole interface.

list with callback api will exist deperecated and somewhen removed in future versions, have a expect at the streaming interface beneath

regedit.list([Cord|Assortment]) - streaming interface

Same as regedit.list([String|Array], [Role]) exposes a streaming interface instead of a callback. This is useful for situations where you have a lot of data coming in and out of the list process. Somewhen this will completely supercede the list() with callback api

This operation will mutate the keys array

Example:

                regedit                .                listing                (                [                'HKCU\\SOFTWARE'                ,                'HKLM\\SOFTWARE'                ]                )                .                on                (                'information'                ,                office                (                entry                )                {                console                .                log                (                entry                .                key                )                console                .                log                (                entry                .                information                )                }                )                .                on                (                'end'                ,                role                (                )                {                console                .                log                (                'list functioning finished'                )                }                )              

This code output volition look like this:

              HKCU\\SOFTWARE {     keys: [ 'Google', 'Microsoft', ... more direct sub keys ]     values: {         'valueName': {             value: '123',             type: 'REG_SZ'         }         ... more directly child values of HKCU\\SOFTWARE     } } HKLM\\SOFTWARE {     keys: [ 'Google', 'Microsoft', ... more direct sub keys ]     values: {         'valueName': {             value: '123',             blazon: 'REG_SZ'         }         ... more than direct child values of HKLM\\SOFTWARE         } }                          

regedit.curvation.list32([String|Array], [Function])

same equally regedit.list([String|Array], [Function]), but force a 32bit compages on the registry

regedit.curvation.list32([String|Assortment])

streaming interface, see regedit.list([String|Array])

regedit.arch.list64([String|Array], [Function])

aforementioned as listing, only force a 64bit architecture on the registry

regedit.arch.list64([String|Array])

streaming interface, see regedit.listing([Cord|Array])

regedit.arch.list([Cord|Array], [Function])

same equally list, only force your system architecture on the registry (select automatically between list64 and list32)

regedit.arch.list([Cord|Array])

streaming interface, see regedit.list([String|Array])

Manipulating the registry

regedit.createKey([Cord|Assortment], [Function])

Creates one or more keys in the registry This operation will mutate the keys array

regedit.deleteKey([String|Array], [Function])

Deletes one or more keys in the registry This performance will mutate the keys array

regedit.putValue(Object, Office)

Put one or more values in the registry. The Object given to this function is almost identical to the result of regedit.list().

Here is an case:

                var                valuesToPut                =                {                'HKCU\\Software\\MySoftware':                {                'myValue1':                {                value:                [                1                ,                2                ,                three                ]                ,                type:                'REG_BINARY'                }                ,                'myValue2':                {                value:                'aString'                ,                blazon:                'REG_SZ'                }                }                ,                'HKCU\\Software\\MySoftware\\foo':                {                'myValue3':                {                value:                [                'a'                ,                'b'                ,                'c'                ]                type:                'REG_MULTI_SZ'                }                }                }                regedit                .                putValue                (                valuesToPut                ,                office                (                err                )                {                }                )              

Supported value types are:

  • REG_SZ, REG_EXPAND_SZ: a string basically
  • REG_DWORD, REG_QWORD: should use javascript numbers
  • REG_MULTI_SZ: an array of strings
  • REG_BINARY: an array of numbers (representing bytes)
  • REG_DEFAULT: come across note virtually default values beneath
Note about setting default values

When including a default value in a putValue operation, one must use the REG_DEFAULT type. Further more, the name of the value is insignificant since in the registry the default value has no name, merely considering of the style the node and the vb processes communicate a name must be used. Delight annotation that the only legal value blazon of a default value is REG_SZ

this is a temporary solution and is subject to change in future versions

                var                values                =                {                'HKCU\\Software\\MySoftware':                {                'someNameIDontCareAbout':                {                value:                'Must be a cord'                ,                blazon:                'REG_DEFAULT'                }                ,                'myValue2':                {                value:                'aString'                ,                type:                'REG_SZ'                }                }                }                regedit                .                putValue                (                values                ,                function                (                err                )                {                }                )              

For now this is how its going to be, but in the future this volition probably change, possibly in a way that will effect the whole interface.

regedit.deleteValue([String|Assortment], [Part])

Deletes ane or more values in the registry This operation will mutate the keys array

Promises

To use promises access the role you lot want through regedit.promisified, all function signatures are the aforementioned ([Cord|Array], [Arch (optional)])

Default arch is agnostic.

Instance: regedit.promisified.listing([String|Array], [Arch (optional)])

                endeavour                {                const                registryList                =                wait                regedit                .                promisified                .                list                (                [                'HKCU\\SOFTWARE'                ,                'HKLM\\SOFTWARE'                ,                'HKCU\\IM_FAKE_THEREFOR_I_DONT_EXIST'                ]                )                }                catch                (                e                )                {                console                .                log                (                'Error while listing keys:'                ,                e                .                message                )                }              

Result and errors should be the same equally not promisified.

Develop

Run tests

                              mocha -R spec                          

Enable debug output

                              set DEBUG=regedit                          

TODO

None :)

changonsid1990.blogspot.com

Source: https://www.npmjs.com/package/regedit

0 Response to "Regedit"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel