Access to Application object from exe

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

    Access to Application object from exe

    Hi,

    I have many virtual directory with my web app. I'd like to create one exe
    appliaction to administrating these web apps. Is it possible to access
    Application object of web appliaction from exe appliaction?

    With regards,

    Woland


  • Natty Gur

    #2
    Re: Access to Application object from exe

    As far as I know you cant. If you want i got an example that let you
    access all AppDomaines (Applications) from ASP.NET page.

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    • Woland

      #3
      Re: Access to Application object from exe


      "Natty Gur" <natty@dao2com. com> wrote in message
      news:e1FYAxxPDH A.3016@TK2MSFTN GP10.phx.gbl...[color=blue]
      > As far as I know you cant. If you want i got an example that let you
      > access all AppDomaines (Applications) from ASP.NET page.
      >
      > Natty Gur, CTO[/color]

      I'd be very grateful if you send me this app or link to the page where I can
      look at it.

      Thanks in advance,

      Woland
      Woland1(at)pocz ta.onet.pl


      Comment

      • Natty Gur

        #4
        Re: Access to Application object from exe

        1)You need to reference mscoree tlb.
        2)the code :

        using System;
        using System.Collecti ons;
        using System.Componen tModel;
        using System.Data;
        using System.Drawing;
        using System.Web;
        using System.Web.Sess ionState;
        using System.Web.UI;
        using System.Web.UI.W ebControls;
        using System.Web.UI.H tmlControls;
        using System.Reflecti on;
        using System.Runtime. InteropServices ;

        namespace WebApplication3
        {
        /// <summary>
        /// Summary description for WebForm1.
        /// </summary>
        public class WebForm1 : System.Web.UI.P age
        {
        protected System.Web.UI.W ebControls.Butt on btnStop;
        protected System.Web.UI.W ebControls.Chec kBoxList CheckBoxList1;

        private void Page_Load(objec t sender, System.EventArg s e)
        {
        // Put user code to initialize the page here
        if (!this.IsPostBa ck)

        GetAllDomains() ;
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArg s e)
        {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeCompo nent();
        base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeCompo nent()
        {
        this.CheckBoxLi st1.SelectedInd exChanged += new
        System.EventHan dler(this.Check BoxList1_Select edIndexChanged) ;
        this.btnStop.Cl ick += new System.EventHan dler(this.btnSt op_Click);
        this.Load += new System.EventHan dler(this.Page_ Load);

        }
        #endregion

        private void btnStop_Click(o bject sender, System.EventArg s e)
        {
        System.AppDomai n.Unload (System.AppDoma in.CurrentDomai n );

        mscoree.CorRunt imeHostClass host = new mscoree.CorRunt imeHostClass();
        IntPtr enumHandle = IntPtr.Zero;
        host.EnumDomain s( out enumHandle );
        object dom = null;
        while(true)
        {
        host.NextDomain ( enumHandle, out dom );
        if( dom == null )
        break;
        AppDomain ad = (AppDomain) dom;
        //dom = null;
        for(int iIndx =0;iIndx < CheckBoxList1.I tems.Count;iInd x++)
        {
        if ( CheckBoxList1.I tems[iIndx].Value == ad.FriendlyName )
        {
        if ( CheckBoxList1.I tems[iIndx].Selected == true )
        {
        System.Security .Policy.Evidenc e NE = new
        System.Security .Policy.Evidenc e(ad.Evidence);
        System.AppDomai nSetup NADS = new System.AppDomai nSetup();
        NADS.Applicatio nBase = ad.SetupInforma tion.Applicatio nBase;
        NADS.Applicatio nName = ad.SetupInforma tion.Applicatio nName;
        NADS.Configurat ionFile = ad.SetupInforma tion.Configurat ionFile;
        NADS.DynamicBas e = ad.SetupInforma tion.DynamicBas e;
        NADS.PrivateBin Path = ad.SetupInforma tion.PrivateBin Path;
        ad.ClearPrivate Path();
        ad.ClearShadowC opyPath();
        host.UnloadDoma in( ad);
        //host.DeleteLogi calThreadState ();
        System.AppDomai n.Unload (System.AppDoma in.CurrentDomai n );

        //System.AppDomai n.Unload(ad);
        System.Web.Host ing.Application Host.CreateAppl icationHost(Sys tem.T
        ype.GetType("ms coree.CorRuntim eHostClass"),"C RExample","c:\\ Inetpub\\www
        root\\CRExample ");
        //System.AppDomai n.CreateDomain( CheckBoxList1.I tems[iIndx].Value
        ,NE,NADS ) ;
        }
        break;
        }
        }
        dom = null;
        ad = null;
        }
        host.CloseEnum( enumHandle );
        int refctr = Marshal.Release ComObject( host );
        host = null;

        GetAllDomains() ;
        }
        private void GetAllDomains()
        {
        this.CheckBoxLi st1.Items.Clear ();

        mscoree.CorRunt imeHostClass host = new mscoree.CorRunt imeHostClass();

        IntPtr enumHandle = IntPtr.Zero;
        host.EnumDomain s( out enumHandle );
        object dom = null;
        while(true)
        {
        host.NextDomain ( enumHandle, out dom );
        if( dom == null )
        break;
        AppDomain ad = (AppDomain) dom;
        dom = null;
        ListItem oLI = new ListItem(ad.Fri endlyName,ad.Fr iendlyName);
        CheckBoxList1.I tems.Add ( oLI);
        //Response.Write ( ad.FriendlyName + "<br>");

        //try
        //{
        // Assembly[] allAsm = ad.GetAssemblie s();
        //
        // foreach( Assembly asm in allAsm )
        // Response.Write( " -->" + asm.FullName + "<br>" );
        //}
        //catch (Exception err)
        //{
        // Response.Write( err.Message + "<br>" );
        //}
        //
        ad = null;
        }
        host.CloseEnum( enumHandle );
        int refctr = Marshal.Release ComObject( host );
        host = null;

        }

        private void CheckBoxList1_S electedIndexCha nged(object sender,
        System.EventArg s e)
        {

        }
        }
        }


        Natty Gur, CTO
        Dao2Com Ltd.
        28th Baruch Hirsch st. Bnei-Brak
        Israel , 51114

        Phone Numbers:
        Office: +972-(0)3-5786668
        Fax: +972-(0)3-5703475
        Mobile: +972-(0)58-888377

        Know the overall picture


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Woland

          #5
          Re: Access to Application object from exe

          "Natty Gur" <natty@dao2com. com> wrote in message
          news:uTPrktEQDH A.2424@tk2msftn gp13.phx.gbl...[color=blue]
          > 1)You need to reference mscoree tlb.
          > 2)the code :[/color]

          [...]
          [color=blue]
          > Natty Gur, CTO[/color]

          Thanks very much Natty.

          Woland


          Comment

          Working...