Search in sources :

Example 1 with JIException

use of org.jinterop.dcom.common.JIException in project hudson-2.x by hudson.

the class DotNet method isInstalled.

/**
     * Returns true if the .NET framework of the given version (or grater) is installed
     * on a remote machine. 
     */
public static boolean isInstalled(int major, int minor, String targetMachine, IJIAuthInfo session) throws JIException, UnknownHostException {
    IJIWinReg registry = JIWinRegFactory.getSingleTon().getWinreg(session, targetMachine, true);
    JIPolicyHandle hklm = null;
    JIPolicyHandle key = null;
    try {
        hklm = registry.winreg_OpenHKLM();
        key = registry.winreg_OpenKey(hklm, "SOFTWARE\\Microsoft\\.NETFramework", IJIWinReg.KEY_READ);
        for (int i = 0; ; i++) {
            String keyName = registry.winreg_EnumKey(key, i)[0];
            if (matches(keyName, major, minor))
                return true;
        }
    } catch (JIException e) {
        if (e.getErrorCode() == 2)
            // not found
            return false;
        throw e;
    } finally {
        if (hklm != null)
            registry.winreg_CloseKey(hklm);
        if (key != null)
            registry.winreg_CloseKey(key);
        registry.closeConnection();
    }
}
Also used : IJIWinReg(org.jinterop.winreg.IJIWinReg) JIPolicyHandle(org.jinterop.winreg.JIPolicyHandle) JIException(org.jinterop.dcom.common.JIException)

Example 2 with JIException

use of org.jinterop.dcom.common.JIException in project hudson-2.x by hudson.

the class ManagedWindowsServiceLauncher method afterDisconnect.

@Override
public void afterDisconnect(SlaveComputer computer, TaskListener listener) {
    try {
        JIDefaultAuthInfoImpl auth = createAuth();
        JISession session = JISession.createSession(auth);
        session.setGlobalSocketTimeout(60000);
        SWbemServices services = WMI.connect(session, computer.getName());
        Win32Service slaveService = services.getService("hudsonslave");
        if (slaveService != null) {
            listener.getLogger().println(Messages.ManagedWindowsServiceLauncher_StoppingService());
            slaveService.StopService();
        }
    } catch (UnknownHostException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    } catch (JIException e) {
        e.printStackTrace(listener.error(e.getMessage()));
    }
}
Also used : JISession(org.jinterop.dcom.core.JISession) UnknownHostException(java.net.UnknownHostException) JIDefaultAuthInfoImpl(org.jinterop.dcom.common.JIDefaultAuthInfoImpl) SWbemServices(org.jvnet.hudson.wmi.SWbemServices) Win32Service(org.jvnet.hudson.wmi.Win32Service) JIException(org.jinterop.dcom.common.JIException)

Example 3 with JIException

use of org.jinterop.dcom.common.JIException in project opennms by OpenNMS.

the class WmiClient method connect.

/** {@inheritDoc} */
@Override
public void connect(final String domain, final String username, final String password, final String namespace) throws WmiException {
    try {
        m_Session = JISession.createSession(domain, username, password);
        m_Session.useSessionSecurity(true);
        m_Session.setGlobalSocketTimeout(5000);
        JIComServer m_ComStub = new JIComServer(JIProgId.valueOf(WMI_PROGID), m_Address, m_Session);
        final IJIComObject unknown = m_ComStub.createInstance();
        IJIComObject m_ComObject = unknown.queryInterface(WMI_CLSID);
        // This will obtain the dispatch interface
        IJIDispatch m_Dispatch = (IJIDispatch) JIObjectFactory.narrowObject(m_ComObject.queryInterface(IJIDispatch.IID));
        final JIVariant[] results = m_Dispatch.callMethodA("ConnectServer", new Object[] { new JIString(m_Address), new JIString(namespace), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), 0, JIVariant.OPTIONAL_PARAM() });
        m_WbemServices = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
    } catch (final JIException e) {
        if (m_Session != null) {
            try {
                JISession.destroySession(m_Session);
            } catch (JIException e1) {
                LOG.error("Failed to destroy session after incomplete connect with host '{}'.", m_Address, e1);
            }
        }
        throw new WmiException("Failed to establish COM session with host '" + m_Address + "': " + e.getMessage(), e);
    } catch (final UnknownHostException e) {
        if (m_Session != null) {
            try {
                JISession.destroySession(m_Session);
            } catch (JIException e1) {
                LOG.error("Failed to destroy session after unknown host '{}'.", m_Address, e1);
            }
        }
        throw new WmiException("Unknown host '" + m_Address + "'. Failed to connect to WMI agent.", e);
    }
}
Also used : JIComServer(org.jinterop.dcom.core.JIComServer) UnknownHostException(java.net.UnknownHostException) IJIComObject(org.jinterop.dcom.core.IJIComObject) JIVariant(org.jinterop.dcom.core.JIVariant) JIString(org.jinterop.dcom.core.JIString) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) JIException(org.jinterop.dcom.common.JIException)

Example 4 with JIException

use of org.jinterop.dcom.common.JIException in project opennms by OpenNMS.

the class WmiClient method performWmiGet.

/**
     * <p>performWmiGet</p>
     *
     * @param strObjectPath a {@link java.lang.String} object.
     * @return a {@link org.opennms.protocols.wmi.wbem.OnmsWbemObject} object.
     * @throws org.opennms.protocols.wmi.WmiException if any.
     */
public OnmsWbemObject performWmiGet(final String strObjectPath) throws WmiException {
    try {
        final JIVariant[] results = m_WbemServices.callMethodA("Get", new Object[] { new JIString(strObjectPath), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM() });
        final IJIDispatch obj_dsp = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
        return new OnmsWbemObjectImpl(obj_dsp);
    } catch (final JIException e) {
        throw new WmiException("Failed to perform get '" + strObjectPath + "': " + e.getMessage(), e);
    }
}
Also used : JIVariant(org.jinterop.dcom.core.JIVariant) OnmsWbemObjectImpl(org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectImpl) JIString(org.jinterop.dcom.core.JIString) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) JIException(org.jinterop.dcom.common.JIException)

Example 5 with JIException

use of org.jinterop.dcom.common.JIException in project opennms by OpenNMS.

the class WmiClient method performSubclassOf.

/**
     * <p>performSubclassOf</p>
     *
     * @return a {@link org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet} object.
     * @throws org.opennms.protocols.wmi.WmiException if any.
     */
public OnmsWbemObjectSet performSubclassOf() throws WmiException {
    try {
        final JIVariant[] results = m_WbemServices.callMethodA("SubclassesOf", new Object[] { JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM() });
        final IJIDispatch objset_dsp = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
        return new OnmsWbemObjectSetImpl(objset_dsp);
    } catch (final JIException e) {
        throw new WmiException("Failed to perform SubclassesOf: " + e.getMessage(), e);
    }
}
Also used : JIVariant(org.jinterop.dcom.core.JIVariant) OnmsWbemObjectSetImpl(org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectSetImpl) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) JIException(org.jinterop.dcom.common.JIException)

Aggregations

JIException (org.jinterop.dcom.common.JIException)18 IJIDispatch (org.jinterop.dcom.impls.automation.IJIDispatch)13 IJIComObject (org.jinterop.dcom.core.IJIComObject)9 JIVariant (org.jinterop.dcom.core.JIVariant)8 WmiException (org.opennms.protocols.wmi.WmiException)7 JIString (org.jinterop.dcom.core.JIString)5 JIArray (org.jinterop.dcom.core.JIArray)4 IJIEnumVariant (org.jinterop.dcom.impls.automation.IJIEnumVariant)4 OnmsWbemObjectSetImpl (org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectSetImpl)4 UnknownHostException (java.net.UnknownHostException)3 JIDefaultAuthInfoImpl (org.jinterop.dcom.common.JIDefaultAuthInfoImpl)2 JISession (org.jinterop.dcom.core.JISession)2 SWbemServices (org.jvnet.hudson.wmi.SWbemServices)2 Win32Service (org.jvnet.hudson.wmi.Win32Service)2 OnmsWbemObject (org.opennms.protocols.wmi.wbem.OnmsWbemObject)2 Proc (hudson.Proc)1 TaskListener (hudson.model.TaskListener)1 Channel (hudson.remoting.Channel)1 Listener (hudson.remoting.Channel.Listener)1 SocketInputStream (hudson.remoting.SocketInputStream)1