Program uruchamiający komendę w cmd

ahaker

Użytkownik
Dołączył
Marzec 11, 2008
Posty
2
Potraficie napisać program który uruchomi windowsowe cmd, następnie komendę: ipconfig/all, a potem skopiuje wszystko co zostanie wyświetlone, zapisze gdzieś i wyśle na maila?
 

D.F.

Były Moderator
Dołączył
Listopad 4, 2009
Posty
493
W języku C# mogłoby to wyglądać tak:
Kod:
using System;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Mail;


namespace Project1
{
    class Program
    {
        static void Main()
        {
            Process myProcess = new Process();
            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("ipconfig");
            myProcessStartInfo.UseShellExecute = false;
            myProcessStartInfo.RedirectStandardOutput = true; //przekieruj standardowe wyjście
            myProcessStartInfo.Arguments = "/all";
            myProcess.StartInfo = myProcessStartInfo;
            myProcess.Start();
            String OutPut = myProcess.StandardOutput.ReadToEnd();
            myProcess.WaitForExit();

            SmtpClient smtpClient = new SmtpClient();
            NetworkCredential basicCredential = new NetworkCredential();
            MailMessage message = new MailMessage();
            MailAddress fromAddress = new MailAddress("[email protected]");

            basicCredential.UserName = "[email protected]";
            basicCredential.Password = "haslo";

            smtpClient.Host = "smtp.serwer.com";
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = basicCredential;
            smtpClient.EnableSsl = true; //true, gdy serwer SMTP wymaga szyfrowania

            message.From = fromAddress;
            message.Subject = "Dane z ipconfig";

            message.IsBodyHtml = true; //true, gdy wiadomość w formacie HTML
            message.Body = OutPut;
            message.To.Add("[email protected]");

            smtpClient.Send(message); //wyślij wiadomość

        }
    }
}

Kompiluj w Microsoft Visual C# 2010 Express Edition (darmowe).
 
Do góry Bottom