1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace BulkAddUsers {
class Program {
static int Main(string[] args) {
if (args.Length <1) {
Console.WriteLine("[Usage]");
Console.WriteLine("BulkAddUsers <filename> [<character>]");
Console.WriteLine("<filename> is the name of the file which contains the user name and password of the users in CSV format");
Console.WriteLine("<character> is the separatation character used in the CSV file (comma (,) , semicolon (;) , space ( ))");
return -1;
}
string csvFile = args[0];
char sepChar = ',';
if (args.Length> 1) {
sepChar = args[1][0];
}
string csvContents = string.Empty;
using (StreamReader sr = new StreamReader(csvFile)) {
while ((csvContents = sr.ReadLine()) != null) {
//Split on sepChar
string[] tokens = csvContents.Split(sepChar);
string command = "net";
string arguments = "user " + tokens[0] + " "+ tokens[1] +" /add";
Process p = new Process();
p.StartInfo.FileName = command;
p.StartInfo.Arguments = arguments;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
if (p.ExitCode != 0) {
Console.WriteLine("Error creating user {0}, return code {1}", tokens[0], p.ExitCode);
}
}
}
return 0;
}
}
}
|