Go: Manipulating the Registry

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("FMT" "Log" "Golang.org/x/sys/windows/registry") func main () {key, exists, err: = registry. CreateKey (registry. Current_User, "Software\\hello Go", registry. all_access) If err! = Nil {log. Fatal (ERR)}defer key. Close () if exists {FMT. Println ("Key already exists")} else {fmt. Println ("New registry Key")}//writes a 32-bit integer value key. SetDWORDValue ("DWORD", 0xFFFFFFFF)//write 64-bit integer value key. Setqwordvalue ("Qdword", 0xFFFFFFFFFFFFFFFF)//write String key. SetStringValue ("string", "Hello")//writes a multiline string key. Setstringsvalue ("Strings", []string{"Hello", "World"})//write binary key. SetBinaryValue ("Binary", []byte{0x11, 0x22})//Read String value S, _, _: = key. GetStringValue ("String") fmt. PRINTLN (s)//Enumerate all value names values, _: = key. Readvaluenames (0) fmt. PRINTLN (values)//Create three sub-keys Subkey1, _, _: = registry. CreateKey (Key, "Sub1", registry. All_access) Subkey2, _, _: = registry. CreateKey (Key, "Sub2", registry. All_access) Subkey3, _, _: = registry. CreateKey (Subkey1, "Sub3", registry. all_access) defer subkey1. Close () defer subkey2. Close () defer Subkey3. Close ()//Enumerate all subkeys keys, _: = key. ReAdsubkeynames (0) fmt. PRINTLN (keys)//The key has subkeys, so it will delete the failed Err = registry. DeleteKey (Key, "Sub1") if err! = Nil {fmt. PRINTLN (ERR)}//has no subkeys, deleting the successful registry. DeleteKey (Key, "Sub2")}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.