コード例 #1
0
ファイル: registry_test.go プロジェクト: davidsoloman/beats
func setValues(t *testing.T, k registry.Key) {
	for _, test := range ValueTests {
		var err error
		switch test.Type {
		case registry.SZ:
			err = k.SetStringValue(test.Name, test.Value.(string))
		case registry.EXPAND_SZ:
			err = k.SetExpandStringValue(test.Name, test.Value.(string))
		case registry.MULTI_SZ:
			err = k.SetStringsValue(test.Name, test.Value.([]string))
		case registry.BINARY:
			err = k.SetBinaryValue(test.Name, test.Value.([]byte))
		case registry.DWORD:
			err = k.SetDWordValue(test.Name, uint32(test.Value.(uint64)))
		case registry.QWORD:
			err = k.SetQWordValue(test.Name, test.Value.(uint64))
		default:
			t.Fatalf("unsupported type %d for %s value", test.Type, test.Name)
		}
		if test.WillFail {
			if err == nil {
				t.Fatalf("setting %s value %q should fail, but succeeded", test.Name, test.Value)
			}
		} else {
			if err != nil {
				t.Fatal(err)
			}
		}
	}
}
コード例 #2
0
ファイル: manager_windows.go プロジェクト: evolvedm/mac
func (wnic windowsManager) setInterfaceMACAddress(hwAddr string) error {
	var interfaceRegKey registry.Key
	var err error
	//open registry
	if interfaceRegKey, err = registry.OpenKey(registry.LOCAL_MACHINE, wnic.interfaceRegKey, registry.WRITE); err != nil {
		return fmt.Errorf("Unable to open registry key for writing: '%s'\n%s\n", wnic.interfaceRegKey, err)
	}
	defer interfaceRegKey.Close()

	//write spoofed mac to registry
	hwAddr = wnic.formatMacAddress(hwAddr)
	if err = interfaceRegKey.SetStringValue("NetworkAddress", hwAddr); err != nil {
		return fmt.Errorf("Unable to write MAC to registry: '%s'\n%s\n", wnic.interfaceRegKey, err)
	}
	return nil
}