// NewConnection returns a new *WMI connection, given the parameters
NewConnection returns a new *WMI connection, given the parameters
// NewConnection returns a new * WMI connection given the parameters
func NewConnection(params ...interface{}) (*WMI, error) {
	err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
	if err != nil {
		oleerr := err.(*ole.OleError)
		if oleerr.Code() != ole.S_OK && oleerr.Code() != 0x00000001 {
			return nil, err
		}
	}
	unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
	if err != nil {
		return nil, err
	}
	qInterface, err := unknown.QueryInterface(ole.IID_IDispatch)
	if err != nil {
		return nil, err
	}
	rawSvc, err := oleutil.CallMethod(qInterface, "ConnectServer", params...)
	if err != nil {
		return nil, fmt.Errorf("Error: %v", err)
	}
	wmi := rawSvc.ToIDispatch()
	w := &WMI{
		rawSvc:     rawSvc,
		unknown:    unknown,
		qInterface: qInterface,
		wmi:        wmi,
		params:     params,
	}
	return w, nil
}
func NewConnection ( params ... interface { } ) ( * WMI , error ) { err := ole . CoInitializeEx ( 0 , ole . COINIT_MULTITHREADED ) if err != nil { oleerr := err . ( * ole . OleError ) if oleerr . Code ( ) != ole . S_OK && oleerr . Code ( ) != 0x00000001 { return nil , err } } unknown , err := oleutil . CreateObject ( " " ) if err != nil { return nil , err } qInterface , err := unknown . QueryInterface ( ole . IID_IDispatch ) if err != nil { return nil , err } rawSvc , err := oleutil . CallMethod ( qInterface , " " , params ... ) if err != nil { return nil , fmt . Errorf ( " " , err ) } wmi := rawSvc . ToIDispatch ( ) w := & WMI { rawSvc : rawSvc , unknown : unknown , qInterface : qInterface , wmi : wmi , params : params , } return w , nil }
NewConnection returns a new *WMI connection, given the parameters
NewConnection returns a new * WMI connection given the parameters
// CoInitialize already called // https://msdn.microsoft.com/en-us/library/windows/desktop/ms695279%28v=vs.85%29.aspx