我只是想做这样的事情
(defun my-fun (reg-path)
"reads the value from the given Windows registry path."
...??...
)
是否有内置的fn可以做到这一点?
或者是否有一个内置于Windows的命令行工具,我可以运行它来检索reg值?
我想象的方式是在cscript.exe中运行一个完成工作的.js文件。
(defun my-reg-read (regpath)
"read a path in the Windows registry. This probably works for string
values only. If the path does not exist, it returns nil. "
(let ((reg.exe (concat (getenv "windir") "\\system32\\reg.exe"))
tokens last-token)
(setq reg-value (shell-command-to-string (concat reg.exe " query " regpath))
tokens (split-string reg-value nil t)
last-token (nth (1- (length tokens)) tokens))
(and (not (string= last-token "value.")) last-token)))
==>谢谢Oleg。
答案 0 :(得分:5)
使用reg命令行实用程序。
Emacs命令
(shell-command "REG QUERY KeyName" &optional OUTPUT-BUFFER ERROR-BUFFER)
允许您运行shell命令。输出将发送到OUTPUT-BUFFER
。
答案 1 :(得分:0)
这就是我的所作所为:
(defun my-reg-read (regpath)
"read a path in the Windows registry"
(let ((temp-f (make-temp-file "regread_" nil ".js"))
(js-code "var WSHShell, value, regpath = '';try{ if (WScript.Arguments.length > 0){regpath = WScript.Arguments(0); WSHShell = WScript.CreateObject('WScript.Shell'); value = WSHShell.RegRead(regpath); WScript.Echo(value); }}catch (e1){ WScript.Echo('error reading registry: ' + e1);}")
reg-value)
(with-temp-file temp-f (insert js-code))
(setq reg-value (shell-command-to-string (concat temp-f " " regpath)))
(delete-file temp-f)
reg-value ))
elisp函数创建一个临时文件,然后将一些javascript逻辑写入其中。 javascript读取给定路径的Windows注册表。然后elisp fn运行临时文件,将注册表路径传递给read。它删除文件,然后返回运行它的结果。