nim读写注册表的小例子
2018年5月7日 15:11:58 codegay

贴一个nim读写注册表的例子,虽然简单,但是nim官方没有写windows注册表相关的文档,
我贴的例子兴许能帮大家省点时间,以下代码是读取计算机描述和设置计算机描述的:

import registry

const path = r"SYSTEM\CurrentControlSet\services\LanmanServer\Parameters"
const key = "srvcomment"

proc getsrvcomment():string {.discardable.} =
    getUnicodeValue(path, key, HKEY_LOCAL_MACHINE)

echo getsrvcomment()


proc setsrvcomment(comment: string) {.discardable.} =
    setUnicodeValue(path, key, val = comment, HKEY_LOCAL_MACHINE)

setsrvcomment("呆瓜小贼 给我上来")

其中 registry 模块是目前nim中自带的,对应是 nim的目录\lib\windows\registry.nim
是一个非常好的学习例子。