Win32_Process Create

Help
beyonddc
2013-02-21
2013-02-21
  • beyonddc
    beyonddc
    2013-02-21

    I am trying to achieve the following wmic command using j-interop.

    wmic /NODE:192.168.0.195 /USER:Test /PASSWORD:password123 process call create "calc.exe"
    

    I have my code written like this in my method. I have two other methods that create a session and connect to the WMI service so that part is taken care of.

    public void wmiExecute() throws JIException {
    
    // Obtain Win32_Process and narrow it as IJIDispatch
    Object[] params = new Object[] {
        new JIString("Win32_Process"),
        new Integer(0),
        JIVariant.OPTIONAL_PARAM()
    };
    JIVariant[] servicesSet = this._wbemServices.callMethodA("InstancesOf", params);
    IJIDispatch wbemObjectSet = (IJIDispatch) JIObjectFactory.narrowObject(servicesSet[0].getObjectAsComObject());
    
    params = new Object[] {
            "calc.exe",
             JIVariant.OPTIONAL_PARAM(),
             JIVariant.OPTIONAL_PARAM(),
             new Integer(0),
    };
    wbemObjectSet.callMethodA("Create", params);
    }
    

    I kept getting an Exception of the following when callMethodA() is called

    Caught Throwable: org.jinterop.dcom.common.JIException: Unknown name. [0x80020006]
    org.jinterop.dcom.common.JIException: Unknown name. [0x80020006]

    Basically I am following the example from http://www.vijaykandy.com/2009/09/windows-management-instrumentation-wmi-from-java/ and I was able to enumerate all the Win32_Process successfully. Now I want to spawn a process using WMI.

    Any idea what I done wrong? Thanks in advance!

     
    • Hi,

      You are calling the method on a wrong pointer. You should perhaps iterate
      the ObjectSet and call this on the members.

      thanks,
      best regards,
      Vikram

      On Thu, Feb 21, 2013 at 10:13 AM, beyonddc beyonddc@users.sf.net wrote:

      I am trying to achieve the following wmic command using j-interop.

      wmic /NODE:192.168.0.195 /USER:Test /PASSWORD:password123 process call create "calc.exe"

      I have my code written like this in my method. I have two other methods
      that create a session and connect to the WMI service so that part is taken
      care of.

      public void wmiExecute() throws JIException {
      // Obtain Win32_Process and narrow it as IJIDispatchObject[] params = new Object[] {
      new JIString("Win32_Process"),
      new Integer(0),
      JIVariant.OPTIONAL_PARAM()};JIVariant[] servicesSet = this._wbemServices.callMethodA("InstancesOf", params);IJIDispatch wbemObjectSet = (IJIDispatch) JIObjectFactory.narrowObject(servicesSet[0].getObjectAsComObject());
      params = new Object[] {
      "calc.exe",
      JIVariant.OPTIONAL_PARAM(),
      JIVariant.OPTIONAL_PARAM(),
      new Integer(0),};wbemObjectSet.callMethodA("Create", params);}

      I kept getting an Exception of the following when callMethodA() is called

      Caught Throwable: org.jinterop.dcom.common.JIException: Unknown name.
      [0x80020006]
      org.jinterop.dcom.common.JIException: Unknown name. [0x80020006]

      Basically I am following the example from
      http://www.vijaykandy.com/2009/09/windows-management-instrumentation-wmi-from-java/and I was able to enumerate all the Win32_Process successfully. Now I want
      to spawn a process using WMI.
      Any idea what I done wrong? Thanks in advance!

      Win32_Process Createhttps://sourceforge.net/p/j-interop/discussion/600730/thread/a05f6db0/?limit=25#4707

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/j-interop/discussion/600730/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/prefs/

      --
      The Mind is a place of its own. It can make a heaven out of hell or a hell
      out of heaven. Attitude is everything. No matter how adverse conditions
      maybe, one has the capacity to turn things around by one's Determination,
      Perseverance and Hardwork.

      John Milton
      (Paradise Lost)

       
      • beyonddc
        beyonddc
        2013-02-21

        Hi Vikram,

        I think I am getting closer but still no luck. I created a working VBScript

        Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
        
        Set objSWbemServices = objSWbemLocator.ConnectServer _
            ("192.168.0.195", "root\cimv2", "WINDOWSXP_VM\test", "WindowsXP")
        
        Set obj = objSWbemServices.Get("Win32_Process")
        
        objText = obj.GetObjectText_
        WScript.Echo (objText)
        
        returnvalue = obj.create("calc.exe",,,processid)
        

        Here's my equivalent Java method.

        public void wmiExecute() throws JIException {
        
            // Obtain Win32_Process and narrow it as IJIDispatch
            Object[] params = new Object[] {
                new JIString("Win32_Process"),
                JIVariant.OPTIONAL_PARAM(),
                JIVariant.OPTIONAL_PARAM()
            };
        
            JIVariant[] service = this._wbemServices.callMethodA("Get", params);
            IJIDispatch wbemObject = (IJIDispatch) JIObjectFactory.narrowObject(service[0].getObjectAsComObject());
        
            // Retrieve GetObjectText_ and print it
            JIVariant jiVariant = (JIVariant)(wbemObject.callMethodA("GetObjectText_", new Object[] { new Integer(1) }))[0];
            System.out.println(jiVariant.getObjectAsString().getString());
        
            // Create parameter to create a process
            Object[] paramsCalc = new Object[] {
                     "calc.exe",
                     JIVariant.OPTIONAL_PARAM(),
                     JIVariant.OPTIONAL_PARAM(),
                     JIVariant.OPTIONAL_PARAM()
            };
        
            JIVariant[] results = wbemObject.callMethodA("Create", params);
        }
        

        The output of GetObjectText_ from my Java app is identical to the output from my VBScript and I no longer hit any exception. However I am still not able to create a calc process.

        Any idea what I did wrong?

        Thanks in advance!