Example #1
1
func TranslateADName(name string, fromType ADNameType, toType ADNameType) (string, error) {
	var object uintptr
	hr := wrappers.CoCreateInstance(
		&wrappers.CLSID_NameTranslate,
		nil,
		wrappers.CLSCTX_INPROC_SERVER,
		&wrappers.IID_IADsNameTranslate,
		&object)
	if wrappers.FAILED(hr) {
		return "", NewWindowsError("CoCreateInstance", COMError(hr))
	}
	trans := (*wrappers.IADsNameTranslate)(unsafe.Pointer(object))
	defer trans.Release()
	if hr := trans.Init(wrappers.ADS_NAME_INITTYPE_GC, nil); wrappers.FAILED(hr) {
		return "", NewWindowsError("IADsNameTranslate::Init", COMError(hr))
	}
	nameRaw := wrappers.SysAllocString(syscall.StringToUTF16Ptr(name))
	defer wrappers.SysFreeString(nameRaw)
	if hr := trans.Set(int32(fromType), nameRaw); wrappers.FAILED(hr) {
		return "", NewWindowsError("IADsNameTranslate::Set", COMError(hr))
	}
	var outRaw *uint16
	if hr := trans.Get(int32(toType), &outRaw); wrappers.FAILED(hr) {
		return "", NewWindowsError("IADsNameTranslate::Get", COMError(hr))
	}
	return BstrToString(outRaw), nil
}
Example #2
0
func NewADWinNTSystemInfo() (*ADWinNTSystemInfo, error) {
	var object uintptr
	hr := wrappers.CoCreateInstance(
		&wrappers.CLSID_WinNTSystemInfo,
		nil,
		wrappers.CLSCTX_INPROC_SERVER,
		&wrappers.IID_IADsWinNTSystemInfo,
		&object)
	if wrappers.FAILED(hr) {
		return nil, NewWindowsError("CoCreateInstance", COMError(hr))
	}
	return &ADWinNTSystemInfo{object: (*wrappers.IADsWinNTSystemInfo)(unsafe.Pointer(object))}, nil
}
Example #3
0
func NewFirewallManager() (*FirewallManager, error) {
	var object uintptr
	hr := wrappers.CoCreateInstance(
		&wrappers.CLSID_NetFwMgr,
		nil,
		wrappers.CLSCTX_INPROC_SERVER,
		&wrappers.IID_INetFwMgr,
		&object)
	if wrappers.FAILED(hr) {
		return nil, NewWindowsError("CoCreateInstance", COMError(hr))
	}
	return &FirewallManager{object: (*wrappers.INetFwMgr)(unsafe.Pointer(object))}, nil
}