2011-09-15 92 views
4

我只想做這樣的事情我可以從elisp中讀取Windows註冊表嗎?怎麼樣?

(defun my-fun (reg-path) 
    "reads the value from the given Windows registry path." 
    ...??... 
) 

有一個內置的FN做這個?

還是有一個命令行工具內置到窗口,我可以運行檢索reg值?

我想象的做法是在cscript.exe中運行.js文件來完成這項工作。


ANSWER

(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))) 

==>謝謝奧列格。

回答

5

使用reg命令行實用程序。

Emacs的命令

(shell-command "REG QUERY KeyName" &optional OUTPUT-BUFFER ERROR-BUFFER)

允許你運行一個shell命令。輸出發送到OUTPUT-BUFFER

+0

ahhh,比編寫定製的Javascript邏輯更容易閱讀!謝謝。 – Cheeso

+0

參見http://marmalade-repo.org/packages/w32-registry – Cheeso

+0

我想你將無法從Emacs Win32訪問64位節點。 – antonio

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運行臨時文件,傳遞註冊表路徑來讀取。它刪除文件,然後返回運行它的結果。

相關問題