How to remotely load an executable file in ASP.NET

If you want to load an executable file (or an application) remotely, we give a simple ASP.NET with C# program.

----- one button remoteReboot.aspx file -------------

<%@ Page language="c#" Codebehind="remoteReboot.aspx.cs" AutoEventWireup="false" Inherits="Universal.Datatransfer.ExcelOracle.remoteReboot" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

 <HEAD>

  <title>remoteReboot</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">

 </HEAD>

 <body MS_POSITIONING="GridLayout">

  <form id="Form1" method="post" runat="server">

   <asp:Button id="Button1" runat="server"

    Text="Remote Reboot" Width="128px"></asp:Button>

  </form>

 </body>

</HTML>

----- remoteReboot.aspx.cs file -------------

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

 

namespace Universal.Datatransfer.ExcelOracle

{

          /// <summary>

          /// Summary description for remoteReboot.

          /// </summary>

          public class remoteReboot : System.Web.UI.Page

          {

                   protected System.Web.UI.WebControls.Button Button1;

 

                   private void Page_Load(object sender, System.EventArgs e)

                   {

                             // Put user code to initialize the page here

                   }

 

                   #region Web Form Designer generated code

                   override protected void OnInit(EventArgs e)

                   {

                             //

                             // CODEGEN: This call is required by the ASP.NET Web Form Designer.

                             //

                             InitializeComponent();

                             base.OnInit(e);

                   }

 

                   /// <summary>

                   /// Required method for Designer support - do not modify

                   /// the contents of this method with the code editor.

                   /// </summary>

                   private void InitializeComponent()

                   {   

                             this.Button1.Click += new System.EventHandler(this.Button1_Click);

                             this.Load += new System.EventHandler(this.Page_Load);

 

                   }

                   #endregion

 

                   private void Button1_Click(object sender, System.EventArgs e)

                   {

                             System.Diagnostics.Process myProcess1 = new System.Diagnostics.Process();

                             myProcess1.StartInfo.WorkingDirectory = Request.MapPath("~/bin");

                             myProcess1.StartInfo.FileName = Request.MapPath("~/bin/notepad.exe");  

                             myProcess1.Start();

                   }

          }

}

 

Procedures:

  1. Copy an excecutable file into your web-root bin directory, for example, notepad.exe.

  2. Window XP and Windows Server 2003 have the different settings.

    For Window XP users, edit machine.config file in C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG change the userName from Machine into SYSTEM as below,

    <processModel enable="true", ..., userName="SYSTEM" password="AutoGenerate" ... maxIoThreads="20"/>

    For Windows Server 2003 users, you have to set up in a little different way. Just send me an email if you need a help.

  3. If you don't want to application to run under background,  you have to go to \Administrative Tools\Services\IIS Admin and right click Property\Logon, then click the checkbox of Allow service to interact with desktop.

If you don't set (3), your application is still loaded. But it runs under background.

After restart computer, then you can remote load the executable file from the internet.


Similar Articles