Please check my Program and help me.
Its running succesfully in the local machine but not working over LAN or Internet
http://www.4shared.com/file/mYSD5KDg/RemoteApp.html[
^]
CODE:
Remote Class:::
xx.cs file:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.Remoting;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.InteropServices;
namespace remoteclass
{
public class xx : MarshalByRefObject
{
public int sum(int a, int b)
{
return a + b;
}
private static Bitmap bmpScreenshot;
int k = 0;
private static Graphics gfxScreenshot;
public MemoryStream screenshot()
{
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
MemoryStream ms = new MemoryStream();
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(ms, bmpScreenshot);
ms.Position = 0;
return ms;
}
[DllImport("winmm.dll", EntryPoint = "mciSendStringA")]
public static extern void mciSendStringA(string lpstrCommand,
string lpstrReturnString, long uReturnLength, long hwndCallback);
string rt = "";
public void EjectCdTray()
{
mciSendStringA("set CDAudio door open", rt, 127, 0);
}
public void CloseCdTray()
{
mciSendStringA("set CDAudio door closed", rt, 127, 0);
}
public void CursorSet(int X, int Y)
{
Cursor.Position = new Point(X,Y);
}
}
}
Remote Client::::
using System
using System.Collections.Generic
using System.ComponentModel
using System.Data
using System.Drawing
using System.Text
using System.Windows.Forms
using System.Runtime.Remoting
using System.Runtime.Remoting.Channels
using System.Runtime.Remoting.Channels.Tcp
using System.Runtime.Serialization.Formatters.Soap
using System.Threading
namespace remoteclient
{
public partial class Form1 : Form
{
remoteclass.xx obj = new remoteclass.xx()
public Form1()
{
InitializeComponent()
}
private void button1_Click_1(object sender, EventArgs e)
{
try
{
obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
"tcp://"+txtPath.Text+":8085/Ankit")
int x = Int32.Parse(textBox1.Text)
int y = Int32.Parse(textBox2.Text)
textBox3.Text = (obj.sum(x, y)).ToString()
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString())
}
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Width = this.Width-36
pictureBox1.Height = this.Height - 48-36
}
remoteclass.xx abc = new remoteclass.xx()
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if(!backgroundWorker1.IsBusy)
backgroundWorker1.RunWorkerAsync()
}
catch (Exception ex)
{
timer1.Enabled = false
MessageBox.Show(ex.ToString())
}
}
private void Form1_Resize(object sender, EventArgs e)
{
pictureBox1.Width = this.Width-36
pictureBox1.Height = this.Height - 48-36
}
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Enabled = true
}
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Enabled = false
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
"tcp://" + txtPath.Text + ":8085/Ankit")
SoapFormatter formatter = new SoapFormatter()
e.Result = (Bitmap)formatter.Deserialize(obj.screenshot())
}
catch (Exception ex)
{
timer1.Enabled = false
MessageBox.Show(ex.ToString())
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
pictureBox1.Image = (Bitmap)e.Result
}
private void btnEject_Click(object sender, EventArgs e)
{
try
{
obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
"tcp://" + txtPath.Text + ":8085/Ankit")
obj.EjectCdTray()
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString())
}
}
private void btnClose_Click(object sender, EventArgs e)
{
try
{
obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
"tcp://" + txtPath.Text + ":8085/Ankit")
obj.CloseCdTray()
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString())
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
try
{
if (timer1.Enabled)
{
obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
"tcp://" + txtPath.Text + ":8085/Ankit")
int X = e.X * pictureBox1.Image.Size.Width / pictureBox1.Size.Width
int Y = e.Y * pictureBox1.Image.Size.Height / pictureBox1.Size.Height
obj.CursorSet(X, Y)
}
}
catch
{
}
}
int rndMouse
private void btnRndm_Click(object sender, EventArgs e)
{
try
{
rndMouse = 0
obj = (remoteclass.xx)Activator.GetObject(typeof(remoteclass.xx),
"tcp://" + txtPath.Text + ":8085/Ankit")
Random random = new Random()
while (rndMouse == 0)
obj.CursorSet(random.Next(pictureBox1.Image.Width), random.Next(pictureBox1.Image.Height))
}
catch
{
}
}
private void btnMouseStop_Click(object sender, EventArgs e)
{
rndMouse = 1
}
}
}
RemoteServer:::
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using Microsoft.Win32;
namespace remoteserver
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
TcpChannel ch = new TcpChannel(8085);
ChannelServices.RegisterChannel(ch);
RemotingConfiguration.RegisterWellKnownServiceType(typeof
(remoteclass.xx), "Ankit", WellKnownObjectMode.Singleton);
}
}
}