Windows2003下面的批量创建随机用户程序(.NET多线程)
生活随笔
收集整理的這篇文章主要介紹了
Windows2003下面的批量创建随机用户程序(.NET多线程)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
翻看以前的代碼,發現有這么一個小工具,以前是做了郵件群發服務器的一個工具,現在公布于眾把,呵呵,沒有多少技術含量,懂的人,覺得太菜了,大家不要吐槽就行。
?
1 using System;2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6 using System.Diagnostics;
7 using System.IO;
8
9 namespace CreateMailAddress
10 {
11 class Program
12 {
13 static int count = 10;
14 static string _email_ext = "@mrhuo.com";
15 static int threadID = 0;
16 static int type = 0;
17 static List<string> emailList = new List<string>();
18
19 static void Main(string[] args)
20 {
21 if (args.Length < 1||args.Length<3)
22 {
23 helper("參數個數不正確。");
24 }
25 else
26 {
27 count = Convert.ToInt32(args[1]);
28 _email_ext = "@" + args[0];
29
30 if (args.Length == 3)
31 {
32 type = 0;
33 }
34 else
35 {
36 if (args[3].Remove(0, 1).ToLower() == "test")
37 {
38 type = 0;
39 }
40 else if (args[3].Remove(0, 1).ToLower() == "make")
41 {
42 type = 1;
43 }
44 else
45 {
46 helper("沒有 " + args[3].Remove(0, 1) + " 這個參數。");
47 }
48 }
49
50 if (type == 0)
51 {
52 Console.WriteLine("測試創建效果:");
53 }
54 else if (type == 1)
55 {
56 Console.WriteLine("創建郵件地址開始:");
57 }
58 else
59 {
60 helper("錯誤的參數傳遞。");
61 }
62
63 while (count > 0)
64 {
65 for (threadID = 1; threadID <= Convert.ToInt32(args[2]); threadID++)
66 {
67 Thread th = new Thread(new ThreadStart(makeMailAddress));
68 th.IsBackground = true;
69 th.Start();
70 th.Join();
71
72 Thread.Sleep(10);
73 }
74 }
75
76 Console.WriteLine("生成 " + args[1] + " 個電子郵件成功!");
77
78 emailList.Sort();
79
80 string _file = string.Empty;
81 foreach (string t in emailList)
82 {
83 _file += t + "\r\n";
84 }
85
86 string filename = "C:\\E_" + DateTime.Now.Ticks.ToString() + ".txt";
87 File.WriteAllText(filename, _file, Encoding.ASCII);
88 Console.WriteLine("郵件地址已經保存到 " + filename + " !");
89
90 //Console.ReadLine();
91 }
92 }
93
94 static void makeMailAddress()
95 {
96 try
97 {
98 if (count > 0)
99 {
100 if (type == 0)
101 {
102 Console.WriteLine("線程:" + threadID.ToString() + "啟動...");
103 }
104
105 string _email_addr = getRandStr(10) + _email_ext;
106
107 if (type == 1)
108 {
109 ProcessStartInfo pi = new ProcessStartInfo("winpop.exe", "add " + _email_addr + " /createuser \"123456\"");
110 pi.CreateNoWindow = true;
111 pi.WindowStyle = ProcessWindowStyle.Hidden;
112
113 Process.Start(pi);
114 }
115
116 Console.WriteLine("創建用戶:" + _email_addr + "成功!");
117
118 emailList.Add(_email_addr + "|123456");
119
120 if (type == 0)
121 {
122 Console.WriteLine("線程:" + threadID.ToString() + "結束...");
123 }
124 count--;
125 }
126 }
127 catch
128 {
129 return;
130 }
131 }
132
133 static string getRandStr(int num)
134 {
135 string _out_trade_no = "";
136
137 string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
138 long tick = DateTime.Now.Ticks;
139 Random rnd = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
140 for (int i = 1; i <= num; i++)
141 {
142 _out_trade_no += chars.Substring(rnd.Next(chars.Length), 1);
143 }
144 //Thread.Sleep(1);
145 return _out_trade_no.ToUpper();
146 }
147
148 static void helper(string err)
149 {
150 Console.WriteLine();
151 Console.WriteLine("錯誤:" + err + "");
152 Console.WriteLine();
153 Console.WriteLine("介紹:用于隨機創建服務器電子郵件地址(For Win2003)。");
154 Console.WriteLine();
155 Console.WriteLine("用法:EmailCreater.exe <mrhuo.com> <1000> <512> [/Test|/Make]");
156 Console.WriteLine(" EmailCreater.exe <郵箱域名> <郵箱個數> <線程> [測試(不生成)|生成(需要服務器的POP服務支持)]");
157 Console.WriteLine();
158 Console.WriteLine(" //Code By QQ:491217650 From:www.mrhuo.com");
159 Console.ReadLine();
160 return;
161 }
162 }
163 }
?
完整的程序下載Demo:
點擊下載
轉載注明:http://www.mrhuo.com(MR.HUO工作室)
轉載于:https://www.cnblogs.com/MrHuo/archive/2012/02/09/2343658.html
總結
以上是生活随笔為你收集整理的Windows2003下面的批量创建随机用户程序(.NET多线程)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [推荐]经典炸弹人手机游戏[年兽防御战2
- 下一篇: OLTP 和OLAP