Find Window from Client-Side (ActiveX?) to Copy Contents into Web

Discussion in 'ASP .Net' started by =?Utf-8?B?R3JlZyBN?=, May 15, 2007.

  1. Hello,

    I'm running an asp.net, intranet web application using .net framework 1.1 on
    IIS5.1 / 6.0. Through the web application, I would like to press a button on
    the web page, have another window (not web-based or part of current
    application) brought to the front and focused (findwindow api) and have the
    button scrape the contents of the focused window so the contents can be
    parsed and entered into the web application.

    Ideally, I would like to do this server-side, but I don't think I can get to
    a window on the client's pc to bring it to the front. I'm definitely open to
    javascript since this is an intranet application and the environment is
    controlled.

    I've considered and attempted to create an ActiveX control that will be in a
    web page (object tag). The class library project contains an interface,
    IScreenScrape, that defines the method and properties available (COM
    support?). If I run the ActiveX control and exit before it attempts to
    "activate" the other application's window, the properties are accessible and
    contain values, and the process finishes successfully. The ActiveX control
    seems to work until it attempts to "activate" the other application's window
    where I get a System.Security.Permissions.SecurityPermission error. This
    action is initiated through Javascript by calling
    USSActiveX.GetVisionInformation().

    Things I've tried:
    1) I've added my local pc to the "Trusted Sites" in IE 7;
    2) I've modified code-access security in LocalIntranet_Zone to FullTrust and
    Everything;
    3) I've strong-name signed the dll that houses the ActiveX control (when I
    did this, I started getting a Javascript error indicating "object does not
    support this property or method" even though it exists).

    Any help that can be provided is appreciated. Thanks.

    Web Application calling code:

    <%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false"
    Inherits="Test_ActiveXDotNetWeb.WebForm4" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm4</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    <script type="text/javascript">
    function doScript()
    {
    USSActiveX.GetVisionInformation();
    Form1.hdnName.value = USSActiveX.ApplicantName;
    Form1.hdnSSN.value = USSActiveX.ApplicantSSN;
    Form1.hdnOTA.value = USSActiveX.OrgTypeApplicationNumber;
    Form1.hdnScreen.value = USSActiveX.VisionScreen;

    }
    </script>
    </HEAD>
    <body>
    <OBJECT id="USSActiveX"
    classid="Unicorn.ScreenScrapeActiveX.dll#Unicorn.ScreenScrapeActiveX.ScreenScrape"
    name="USSActiveX" VIEWASTEXT>
    </OBJECT>
    <form id="Form1" method="post" runat="server">
    <input type="hidden" id="hdnName" runat="server" NAME="hdnName"> <input
    type="hidden" id="hdnSSN" runat="server" NAME="hdnSSN">
    <input type="hidden" id="hdnOTA" runat="server" NAME="hdnOTA"> <input
    type="hidden" id="hdnScreen" runat="server" name="hdnScreen">
    <br>
    <input type="text" name="txt" value="Enter text here">
    <br>
    <asp:Button ID="butSetText" Runat="server" Text="Set Text"></asp:Button>
    </form>
    </body>
    </HTML>

    The butSetText onclick event is assigned server side using:
    this.butSetText.Attributes.Add("onclick","doScript();");
    =?Utf-8?B?R3JlZyBN?=, May 15, 2007
    #1
    1. Advertising

  2. You really mean you have a managed user control, that's sthe only reason you
    could get a security error. You simply need to update your cas policy with
    the appropriate permissions.
    --
    Regards,
    Alvin Bruney
    ------------------------------------------------------
    Shameless author plug
    Excel Services for .NET is coming...
    OWC Black book on Amazon and
    www.lulu.com/owc
    Professional VSTO 2005 - Wrox/Wiley


    "Greg M" <Greg > wrote in message
    news:...
    > Hello,
    >
    > I'm running an asp.net, intranet web application using .net framework 1.1
    > on
    > IIS5.1 / 6.0. Through the web application, I would like to press a button
    > on
    > the web page, have another window (not web-based or part of current
    > application) brought to the front and focused (findwindow api) and have
    > the
    > button scrape the contents of the focused window so the contents can be
    > parsed and entered into the web application.
    >
    > Ideally, I would like to do this server-side, but I don't think I can get
    > to
    > a window on the client's pc to bring it to the front. I'm definitely open
    > to
    > javascript since this is an intranet application and the environment is
    > controlled.
    >
    > I've considered and attempted to create an ActiveX control that will be in
    > a
    > web page (object tag). The class library project contains an interface,
    > IScreenScrape, that defines the method and properties available (COM
    > support?). If I run the ActiveX control and exit before it attempts to
    > "activate" the other application's window, the properties are accessible
    > and
    > contain values, and the process finishes successfully. The ActiveX control
    > seems to work until it attempts to "activate" the other application's
    > window
    > where I get a System.Security.Permissions.SecurityPermission error. This
    > action is initiated through Javascript by calling
    > USSActiveX.GetVisionInformation().
    >
    > Things I've tried:
    > 1) I've added my local pc to the "Trusted Sites" in IE 7;
    > 2) I've modified code-access security in LocalIntranet_Zone to FullTrust
    > and
    > Everything;
    > 3) I've strong-name signed the dll that houses the ActiveX control (when I
    > did this, I started getting a Javascript error indicating "object does not
    > support this property or method" even though it exists).
    >
    > Any help that can be provided is appreciated. Thanks.
    >
    > Web Application calling code:
    >
    > <%@ Page language="c#" Codebehind="WebForm4.aspx.cs"
    > AutoEventWireup="false"
    > Inherits="Test_ActiveXDotNetWeb.WebForm4" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>WebForm4</title>
    > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > <meta name="CODE_LANGUAGE" Content="C#">
    > <meta name="vs_defaultClientScript" content="JavaScript">
    > <meta name="vs_targetSchema"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    > <script type="text/javascript">
    > function doScript()
    > {
    > USSActiveX.GetVisionInformation();
    > Form1.hdnName.value = USSActiveX.ApplicantName;
    > Form1.hdnSSN.value = USSActiveX.ApplicantSSN;
    > Form1.hdnOTA.value = USSActiveX.OrgTypeApplicationNumber;
    > Form1.hdnScreen.value = USSActiveX.VisionScreen;
    >
    > }
    > </script>
    > </HEAD>
    > <body>
    > <OBJECT id="USSActiveX"
    > classid="Unicorn.ScreenScrapeActiveX.dll#Unicorn.ScreenScrapeActiveX.ScreenScrape"
    > name="USSActiveX" VIEWASTEXT>
    > </OBJECT>
    > <form id="Form1" method="post" runat="server">
    > <input type="hidden" id="hdnName" runat="server" NAME="hdnName"> <input
    > type="hidden" id="hdnSSN" runat="server" NAME="hdnSSN">
    > <input type="hidden" id="hdnOTA" runat="server" NAME="hdnOTA"> <input
    > type="hidden" id="hdnScreen" runat="server" name="hdnScreen">
    > <br>
    > <input type="text" name="txt" value="Enter text here">
    > <br>
    > <asp:Button ID="butSetText" Runat="server" Text="Set Text"></asp:Button>
    > </form>
    > </body>
    > </HTML>
    >
    > The butSetText onclick event is assigned server side using:
    > this.butSetText.Attributes.Add("onclick","doScript();");
    Alvin Bruney [MVP], May 16, 2007
    #2
    1. Advertising

  3. Re: Find Window from Client-Side (ActiveX?) to Copy Contents into

    Thanks for your response Alvin.

    What permissions do I give it? I tried SecurityPermission to no avail. I
    tried to give the LocalIntranet_Zone both FullTrust and Everything and that
    didn't work. Is there some sort of Win32Permission to give the assembly?

    The code I'm working with is in a Class Library DLL, not a UserControl. Do I
    need to move it into a UserControl? I don't intend for any user interface
    components to be on the web page (at least not visible)... I just want to be
    able to have the user push a button which will then instantiate the ActiveX
    to scrape data from another window for use in the web app.

    Thanks.
    Greg

    "Alvin Bruney [MVP]" wrote:

    > You really mean you have a managed user control, that's sthe only reason you
    > could get a security error. You simply need to update your cas policy with
    > the appropriate permissions.
    > --
    > Regards,
    > Alvin Bruney
    > ------------------------------------------------------
    > Shameless author plug
    > Excel Services for .NET is coming...
    > OWC Black book on Amazon and
    > www.lulu.com/owc
    > Professional VSTO 2005 - Wrox/Wiley
    >
    >
    > "Greg M" <Greg > wrote in message
    > news:...
    > > Hello,
    > >
    > > I'm running an asp.net, intranet web application using .net framework 1.1
    > > on
    > > IIS5.1 / 6.0. Through the web application, I would like to press a button
    > > on
    > > the web page, have another window (not web-based or part of current
    > > application) brought to the front and focused (findwindow api) and have
    > > the
    > > button scrape the contents of the focused window so the contents can be
    > > parsed and entered into the web application.
    > >
    > > Ideally, I would like to do this server-side, but I don't think I can get
    > > to
    > > a window on the client's pc to bring it to the front. I'm definitely open
    > > to
    > > javascript since this is an intranet application and the environment is
    > > controlled.
    > >
    > > I've considered and attempted to create an ActiveX control that will be in
    > > a
    > > web page (object tag). The class library project contains an interface,
    > > IScreenScrape, that defines the method and properties available (COM
    > > support?). If I run the ActiveX control and exit before it attempts to
    > > "activate" the other application's window, the properties are accessible
    > > and
    > > contain values, and the process finishes successfully. The ActiveX control
    > > seems to work until it attempts to "activate" the other application's
    > > window
    > > where I get a System.Security.Permissions.SecurityPermission error. This
    > > action is initiated through Javascript by calling
    > > USSActiveX.GetVisionInformation().
    > >
    > > Things I've tried:
    > > 1) I've added my local pc to the "Trusted Sites" in IE 7;
    > > 2) I've modified code-access security in LocalIntranet_Zone to FullTrust
    > > and
    > > Everything;
    > > 3) I've strong-name signed the dll that houses the ActiveX control (when I
    > > did this, I started getting a Javascript error indicating "object does not
    > > support this property or method" even though it exists).
    > >
    > > Any help that can be provided is appreciated. Thanks.
    > >
    > > Web Application calling code:
    > >
    > > <%@ Page language="c#" Codebehind="WebForm4.aspx.cs"
    > > AutoEventWireup="false"
    > > Inherits="Test_ActiveXDotNetWeb.WebForm4" %>
    > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > > <HTML>
    > > <HEAD>
    > > <title>WebForm4</title>
    > > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    > > <meta name="CODE_LANGUAGE" Content="C#">
    > > <meta name="vs_defaultClientScript" content="JavaScript">
    > > <meta name="vs_targetSchema"
    > > content="http://schemas.microsoft.com/intellisense/ie5">
    > > <script type="text/javascript">
    > > function doScript()
    > > {
    > > USSActiveX.GetVisionInformation();
    > > Form1.hdnName.value = USSActiveX.ApplicantName;
    > > Form1.hdnSSN.value = USSActiveX.ApplicantSSN;
    > > Form1.hdnOTA.value = USSActiveX.OrgTypeApplicationNumber;
    > > Form1.hdnScreen.value = USSActiveX.VisionScreen;
    > >
    > > }
    > > </script>
    > > </HEAD>
    > > <body>
    > > <OBJECT id="USSActiveX"
    > > classid="Unicorn.ScreenScrapeActiveX.dll#Unicorn.ScreenScrapeActiveX.ScreenScrape"
    > > name="USSActiveX" VIEWASTEXT>
    > > </OBJECT>
    > > <form id="Form1" method="post" runat="server">
    > > <input type="hidden" id="hdnName" runat="server" NAME="hdnName"> <input
    > > type="hidden" id="hdnSSN" runat="server" NAME="hdnSSN">
    > > <input type="hidden" id="hdnOTA" runat="server" NAME="hdnOTA"> <input
    > > type="hidden" id="hdnScreen" runat="server" name="hdnScreen">
    > > <br>
    > > <input type="text" name="txt" value="Enter text here">
    > > <br>
    > > <asp:Button ID="butSetText" Runat="server" Text="Set Text"></asp:Button>
    > > </form>
    > > </body>
    > > </HTML>
    > >
    > > The butSetText onclick event is assigned server side using:
    > > this.butSetText.Attributes.Add("onclick","doScript();");

    >
    >
    >
    =?Utf-8?B?R3JlZyBN?=, May 16, 2007
    #3
  4. Re: Find Window from Client-Side (ActiveX?) to Copy Contents into

    Use the .net configuration console application (mscorcfg.msc at a Visual
    Studio command prompt). Right click on the evaluate assembly node found in
    my computer node. Find your dll. It tells you where the application will be
    run from and what permissions it needs.

    Actually there is a better, simpler way. Run the application and wait for it
    to choke. Open your browser, and find the temporary file. Look for a
    fusionlog file in the list of temporary file. Open that file in notepad by
    dragging it into notepad. That file is a stack dump of the permissions
    error. The stack dump tells you which permission is missing. Add that
    permission to your cas policy (1st paragraph). Reset IIS you should be all
    set. I have an article about this on MSDN but i forget where it is. google
    if you feel lucky.

    --
    Regards,
    Alvin Bruney
    ------------------------------------------------------
    Shameless author plug
    Excel Services for .NET is coming...
    https://www.microsoft.com/MSPress/books/10933.aspx
    OWC Black Book www.lulu.com/owc
    Professional VSTO 2005 - Wrox/Wiley


    "Greg M" <> wrote in message
    news:D...
    > Thanks for your response Alvin.
    >
    > What permissions do I give it? I tried SecurityPermission to no avail. I
    > tried to give the LocalIntranet_Zone both FullTrust and Everything and
    > that
    > didn't work. Is there some sort of Win32Permission to give the assembly?
    >
    > The code I'm working with is in a Class Library DLL, not a UserControl. Do
    > I
    > need to move it into a UserControl? I don't intend for any user interface
    > components to be on the web page (at least not visible)... I just want to
    > be
    > able to have the user push a button which will then instantiate the
    > ActiveX
    > to scrape data from another window for use in the web app.
    >
    > Thanks.
    > Greg
    >
    > "Alvin Bruney [MVP]" wrote:
    >
    >> You really mean you have a managed user control, that's sthe only reason
    >> you
    >> could get a security error. You simply need to update your cas policy
    >> with
    >> the appropriate permissions.
    >> --
    >> Regards,
    >> Alvin Bruney
    >> ------------------------------------------------------
    >> Shameless author plug
    >> Excel Services for .NET is coming...
    >> OWC Black book on Amazon and
    >> www.lulu.com/owc
    >> Professional VSTO 2005 - Wrox/Wiley
    >>
    >>
    >> "Greg M" <Greg > wrote in message
    >> news:...
    >> > Hello,
    >> >
    >> > I'm running an asp.net, intranet web application using .net framework
    >> > 1.1
    >> > on
    >> > IIS5.1 / 6.0. Through the web application, I would like to press a
    >> > button
    >> > on
    >> > the web page, have another window (not web-based or part of current
    >> > application) brought to the front and focused (findwindow api) and have
    >> > the
    >> > button scrape the contents of the focused window so the contents can be
    >> > parsed and entered into the web application.
    >> >
    >> > Ideally, I would like to do this server-side, but I don't think I can
    >> > get
    >> > to
    >> > a window on the client's pc to bring it to the front. I'm definitely
    >> > open
    >> > to
    >> > javascript since this is an intranet application and the environment is
    >> > controlled.
    >> >
    >> > I've considered and attempted to create an ActiveX control that will be
    >> > in
    >> > a
    >> > web page (object tag). The class library project contains an interface,
    >> > IScreenScrape, that defines the method and properties available (COM
    >> > support?). If I run the ActiveX control and exit before it attempts to
    >> > "activate" the other application's window, the properties are
    >> > accessible
    >> > and
    >> > contain values, and the process finishes successfully. The ActiveX
    >> > control
    >> > seems to work until it attempts to "activate" the other application's
    >> > window
    >> > where I get a System.Security.Permissions.SecurityPermission error.
    >> > This
    >> > action is initiated through Javascript by calling
    >> > USSActiveX.GetVisionInformation().
    >> >
    >> > Things I've tried:
    >> > 1) I've added my local pc to the "Trusted Sites" in IE 7;
    >> > 2) I've modified code-access security in LocalIntranet_Zone to
    >> > FullTrust
    >> > and
    >> > Everything;
    >> > 3) I've strong-name signed the dll that houses the ActiveX control
    >> > (when I
    >> > did this, I started getting a Javascript error indicating "object does
    >> > not
    >> > support this property or method" even though it exists).
    >> >
    >> > Any help that can be provided is appreciated. Thanks.
    >> >
    >> > Web Application calling code:
    >> >
    >> > <%@ Page language="c#" Codebehind="WebForm4.aspx.cs"
    >> > AutoEventWireup="false"
    >> > Inherits="Test_ActiveXDotNetWeb.WebForm4" %>
    >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    >> > <HTML>
    >> > <HEAD>
    >> > <title>WebForm4</title>
    >> > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    >> > <meta name="CODE_LANGUAGE" Content="C#">
    >> > <meta name="vs_defaultClientScript" content="JavaScript">
    >> > <meta name="vs_targetSchema"
    >> > content="http://schemas.microsoft.com/intellisense/ie5">
    >> > <script type="text/javascript">
    >> > function doScript()
    >> > {
    >> > USSActiveX.GetVisionInformation();
    >> > Form1.hdnName.value = USSActiveX.ApplicantName;
    >> > Form1.hdnSSN.value = USSActiveX.ApplicantSSN;
    >> > Form1.hdnOTA.value = USSActiveX.OrgTypeApplicationNumber;
    >> > Form1.hdnScreen.value = USSActiveX.VisionScreen;
    >> >
    >> > }
    >> > </script>
    >> > </HEAD>
    >> > <body>
    >> > <OBJECT id="USSActiveX"
    >> > classid="Unicorn.ScreenScrapeActiveX.dll#Unicorn.ScreenScrapeActiveX.ScreenScrape"
    >> > name="USSActiveX" VIEWASTEXT>
    >> > </OBJECT>
    >> > <form id="Form1" method="post" runat="server">
    >> > <input type="hidden" id="hdnName" runat="server" NAME="hdnName"> <input
    >> > type="hidden" id="hdnSSN" runat="server" NAME="hdnSSN">
    >> > <input type="hidden" id="hdnOTA" runat="server" NAME="hdnOTA"> <input
    >> > type="hidden" id="hdnScreen" runat="server" name="hdnScreen">
    >> > <br>
    >> > <input type="text" name="txt" value="Enter text here">
    >> > <br>
    >> > <asp:Button ID="butSetText" Runat="server" Text="Set
    >> > Text"></asp:Button>
    >> > </form>
    >> > </body>
    >> > </HTML>
    >> >
    >> > The butSetText onclick event is assigned server side using:
    >> > this.butSetText.Attributes.Add("onclick","doScript();");

    >>
    >>
    >>
    Alvin Bruney [MVP], May 17, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allan Cammish
    Replies:
    1
    Views:
    3,753
    Rajesh.V
    Nov 6, 2003
  2. Replies:
    6
    Views:
    30,235
    Diplomat
    Jan 12, 2011
  3. Boss302
    Replies:
    0
    Views:
    1,021
    Boss302
    Nov 21, 2006
  4. Bogdan
    Replies:
    2
    Views:
    637
    Bogdan
    Jun 9, 2008
  5. Zoe Hart
    Replies:
    1
    Views:
    350
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page