|
| 1 | +'use strict'; |
| 2 | +var registry = require('./registry'), |
| 3 | + windef = require('./windef'); |
| 4 | +module.exports = { |
| 5 | + associateExeForFile: function (handlerName, handlerDescription, iconPath, exePath, extensionName) { |
| 6 | + var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 7 | + |
| 8 | + registry.createKey(key, extensionName, windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 9 | + |
| 10 | + var appKey = registry.openKeyFromKeyObject(key, extensionName, windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 11 | + |
| 12 | + registry.setValueForKeyObject(appKey, '', windef.REG_VALUE_TYPE.REG_SZ, handlerName); |
| 13 | + appKey.close(); |
| 14 | + |
| 15 | + registry.createKey(key, handlerName, windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 16 | + var handlerKey = registry.openKeyFromKeyObject(key, handlerName, windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 17 | + |
| 18 | + registry.setValueForKeyObject(handlerKey, '', windef.REG_VALUE_TYPE.REG_SZ, handlerDescription); |
| 19 | + registry.createKey(handlerKey, 'DefaultIcon', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 20 | + |
| 21 | + var defaultIconKey = registry.openKeyFromKeyObject(handlerKey, 'DefaultIcon', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 22 | + |
| 23 | + registry.setValueForKeyObject(defaultIconKey, '', windef.REG_VALUE_TYPE.REG_SZ, iconPath); |
| 24 | + |
| 25 | + registry.createKey(handlerKey, 'shell\\Open\\Command', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 26 | + |
| 27 | + var commandKey = registry.openKeyFromKeyObject(handlerKey, 'shell\\Open\\Command', windef.KEY_ACCESS.KEY_ALL_ACCESS); |
| 28 | + registry.setValueForKeyObject(commandKey, '', windef.REG_VALUE_TYPE.REG_SZ, exePath); |
| 29 | + |
| 30 | + commandKey.close(); |
| 31 | + handlerKey.close(); |
| 32 | + } |
| 33 | +}; |
0 commit comments