안녕하세요 개발자 명월입니다.

 

이번에 소개할 툴은 CMD 프로그램입니다. 응용을 해서 BATCH 파일등을 연동하여 이런저런 예약툴등으로 사용할 수 있습니다.

물론 해킹툴로써 악용할 수 도 있으나 프로그램은 좋은 쪽으로 사용하시길 바랍니다.

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 using System.Diagnostics;
  5 using System.Threading;
  6 
  7 namespace cmd_test
  8 {
  9     class Program
10     {
11         static void Main(string[] args)
12         {
13             new Program();
14         }
15         private Process process;
16         private ProcessStartInfo startInfo;
17         public Program()
18         {
19             process = new Process();
20             startInfo = new ProcessStartInfo();
21             startInfo.FileName = "CMD.exe";
22             startInfo.UseShellExecute = false;
23             startInfo.RedirectStandardInput = true;
24 startInfo.RedirectStandardOutput = true;
25             startInfo.RedirectStandardError = true;
26 
27             process.EnableRaisingEvents = false;
28             process.StartInfo = startInfo;
29 
30             new Thread(new ThreadStart(cmd)).Start();
31         }
32         String cmd_string;
33         String ret;
34         String err;
35         public void cmd()
36         {
37             startInfo.WorkingDirectory = @"C:\";
38             Console.Write(startInfo.WorkingDirectory + ">");
39             while (true)
40             {
41                 cmd_string = Console.ReadLine();
42                 if (cmd_string.Trim() == "exit") { break; }
43                 if (cmd_type(cmd_string))
44                 {
45                     try
46                     {
47                         process.Start();
48                         process.StandardInput.Write(cmd_string + Environment.NewLine);
49                         process.StandardInput.Close();
50                         ret = process.StandardOutput.ReadToEnd();
51                         String ret_buf = ret.Substring(ret.IndexOf(cmd_string) + cmd_string.Length);
52                         Console.Write(ret_buf);
53                     }
54                     catch (Exception ex)
55                     {
56                         startInfo.WorkingDirectory = @"C:\";
57                         Console.WriteLine(ex.ToString());
58                     }
59                 }
60             }
61         }
62         public bool cmd_type(String msg)
63         {
64             if (msg.Length > 2 && msg[0].ToString() == "c" && msg[1].ToString() == "d")
65             {
66                 startInfo.WorkingDirectory += msg.Replace("cd """) + "\\";
67                 return false;
68             }
69             if (msg.Length == 2 && msg[1] == ':')
70             {
71                 msg = msg.ToUpper();
72                 startInfo.WorkingDirectory = msg[0].ToString() + @":\";
73                 Console.Write("\r\n" + startInfo.WorkingDirectory + ">");
74                 return false;
75             }
76             return true;
77         }
78     }
79 }
80

 

 

유용하게 사용하시기 바랍니다.

첨부 파일입니다.

 

 kin[2]20120911.zip

 



'C#' 카테고리의 다른 글

[C#] 코드로 Dos 명령 실행하기!  (0) 2012.10.10
[C#] 윈폼으로 콘솔명령 실행하기  (0) 2012.10.10
[C#]String Formatting 정리  (1) 2012.08.27
[C#]String Format for Double  (0) 2012.08.23
[C#]다중 모니터와 메시지 박스  (1) 2012.08.06
Posted by 요지
,