GetObject function in windows services

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrei

    GetObject function in windows services

    Hello,

    I posted yesterday the same problem, but now I want to be
    more specific about it.

    My intention is to create a windows service to process
    some Word documents. If I use CreateObject to create a
    reference to a Word object everything is working fine.

    If I use GetObject to get a reference to Word object (of
    course that Word applicaton is started) I get an error
    ("Cannot create ActiveX component")

    It is like my service cannot detect that Word application
    is started.

    I want to say that GetObject is working fine from a
    standard Windows application.

    Thank you,
    Andrei

  • Michael Lang

    #2
    Re: GetObject function in windows services

    "Andrei" <prodanandrei@h otmail.com> wrote in news:003b01c377 0f$d95a89b0
    $a601280a@phx.g bl:
    [color=blue]
    > Hello,
    >
    > I posted yesterday the same problem, but now I want to be
    > more specific about it.
    >
    > My intention is to create a windows service to process
    > some Word documents. If I use CreateObject to create a
    > reference to a Word object everything is working fine.
    >
    > If I use GetObject to get a reference to Word object (of
    > course that Word applicaton is started) I get an error
    > ("Cannot create ActiveX component")
    >
    > It is like my service cannot detect that Word application
    > is started.
    >
    > I want to say that GetObject is working fine from a
    > standard Windows application.
    >
    > Thank you,
    > Andrei
    >
    >[/color]

    I'm unclear as to what is working and what is not for you? Are you
    saying GetObject() works for getting the reference to the application,
    but not other classes inside the application? Getobject() is only for
    getting a reference to the application. You don't use it to get a
    Document class instance. instead use the Documents property of the
    Application instance!

    Here is the code I use to get a reference to an application object in
    AutoCAD. This should be very similar for a Word application:

    mcadApplication = (AutoCAD.AcadAp plicationClass)
    Marshal.GetActi veObject("AutoC AD.Application" );

    It works similarly to GetObject.

    --
    Michael Lang, MCSD

    Comment

    • Andrei

      #3
      Re: GetObject function in windows services

      Hi Michael,

      Thank you for your reply. I will try to be more clear.

      GetObject is returning me an error when I try to get a
      reference to the Word application. But this is happening
      only in windows services, in a standard windows
      application I have no error.

      CreateObject is working fine in both cases (windows
      services or windows applications)

      My question is why I cannot use GetObject in a windows
      sevice?

      Thank you,
      Andrei

      [color=blue]
      >-----Original Message-----
      >"Andrei" <prodanandrei@h otmail.com> wrote in[/color]
      news:003b01c377 0f$d95a89b0[color=blue]
      >$a601280a@phx. gbl:
      >[color=green]
      >> Hello,
      >>
      >> I posted yesterday the same problem, but now I want to[/color][/color]
      be[color=blue][color=green]
      >> more specific about it.
      >>
      >> My intention is to create a windows service to process
      >> some Word documents. If I use CreateObject to create a
      >> reference to a Word object everything is working fine.
      >>
      >> If I use GetObject to get a reference to Word object[/color][/color]
      (of[color=blue][color=green]
      >> course that Word applicaton is started) I get an error
      >> ("Cannot create ActiveX component")
      >>
      >> It is like my service cannot detect that Word[/color][/color]
      application[color=blue][color=green]
      >> is started.
      >>
      >> I want to say that GetObject is working fine from a
      >> standard Windows application.
      >>
      >> Thank you,
      >> Andrei
      >>
      >>[/color]
      >
      >I'm unclear as to what is working and what is not for[/color]
      you? Are you[color=blue]
      >saying GetObject() works for getting the reference to the[/color]
      application,[color=blue]
      >but not other classes inside the application? Getobject[/color]
      () is only for[color=blue]
      >getting a reference to the application. You don't use it[/color]
      to get a[color=blue]
      >Document class instance. instead use the Documents[/color]
      property of the[color=blue]
      >Application instance!
      >
      >Here is the code I use to get a reference to an[/color]
      application object in[color=blue]
      >AutoCAD. This should be very similar for a Word[/color]
      application:[color=blue]
      >
      >mcadApplicatio n = (AutoCAD.AcadAp plicationClass)
      > Marshal.GetActi veObject("AutoC AD.Application" );
      >
      >It works similarly to GetObject.
      >
      >--
      >Michael Lang, MCSD
      >
      >.
      >[/color]

      Comment

      • Andrei

        #4
        Re: GetObject function in windows services

        Hi Michael,

        I have tried using Marshal.GetActi veObject instead of
        GetObject as you suggested. I got an error : "Operation
        unavailable"

        Andrei,
        [color=blue]
        >-----Original Message-----
        >"Andrei" <prodanandrei@h otmail.com> wrote in[/color]
        news:003b01c377 0f$d95a89b0[color=blue]
        >$a601280a@phx. gbl:
        >[color=green]
        >> Hello,
        >>
        >> I posted yesterday the same problem, but now I want to[/color][/color]
        be[color=blue][color=green]
        >> more specific about it.
        >>
        >> My intention is to create a windows service to process
        >> some Word documents. If I use CreateObject to create a
        >> reference to a Word object everything is working fine.
        >>
        >> If I use GetObject to get a reference to Word object[/color][/color]
        (of[color=blue][color=green]
        >> course that Word applicaton is started) I get an error
        >> ("Cannot create ActiveX component")
        >>
        >> It is like my service cannot detect that Word[/color][/color]
        application[color=blue][color=green]
        >> is started.
        >>
        >> I want to say that GetObject is working fine from a
        >> standard Windows application.
        >>
        >> Thank you,
        >> Andrei
        >>
        >>[/color]
        >
        >I'm unclear as to what is working and what is not for[/color]
        you? Are you[color=blue]
        >saying GetObject() works for getting the reference to the[/color]
        application,[color=blue]
        >but not other classes inside the application? Getobject[/color]
        () is only for[color=blue]
        >getting a reference to the application. You don't use it[/color]
        to get a[color=blue]
        >Document class instance. instead use the Documents[/color]
        property of the[color=blue]
        >Application instance!
        >
        >Here is the code I use to get a reference to an[/color]
        application object in[color=blue]
        >AutoCAD. This should be very similar for a Word[/color]
        application:[color=blue]
        >
        >mcadApplicatio n = (AutoCAD.AcadAp plicationClass)
        > Marshal.GetActi veObject("AutoC AD.Application" );
        >
        >It works similarly to GetObject.
        >
        >--
        >Michael Lang, MCSD
        >
        >.
        >[/color]

        Comment

        • Michael Lang

          #5
          Re: GetObject function in windows services

          "Andrei" <prodanandrei@h otmail.com> wrote in news:042b01c377 16$38e01020
          $a401280a@phx.g bl:
          [color=blue]
          > Hi Michael,
          >
          > I have tried using Marshal.GetActi veObject instead of
          > GetObject as you suggested. I got an error : "Operation
          > unavailable"
          >
          > Andrei,[/color]

          Sorry, I've never made a Windows Service. I don't know why it would work
          on Windows Forms and not a Windows Service?

          --
          Michael Lang, MCSD

          Comment

          • Phil Wilson

            #6
            Re: GetObject function in windows services

            This is the kind of thing that smells of a security issue. Your Service is
            probably running with the LocalSystem account in its own Windowstation, but
            trying to drive a Word application that may be installed for a different
            user, or that can't access the interactive user's desktop.

            What happens if you run the Service under your account name/password?
            --
            Phil Wilson [MVP Windows Installer]

            "Andrei" <prodanandrei@h otmail.com> wrote in message
            news:003b01c377 0f$d95a89b0$a60 1280a@phx.gbl.. .[color=blue]
            > Hello,
            >
            > I posted yesterday the same problem, but now I want to be
            > more specific about it.
            >
            > My intention is to create a windows service to process
            > some Word documents. If I use CreateObject to create a
            > reference to a Word object everything is working fine.
            >
            > If I use GetObject to get a reference to Word object (of
            > course that Word applicaton is started) I get an error
            > ("Cannot create ActiveX component")
            >
            > It is like my service cannot detect that Word application
            > is started.
            >
            > I want to say that GetObject is working fine from a
            > standard Windows application.
            >
            > Thank you,
            > Andrei
            >[/color]


            Comment

            Working...