| 10 |
Kevin |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.Linq;
|
|
|
4 |
using System.Text;
|
|
|
5 |
using System.IO;
|
|
|
6 |
using System.Windows.Forms;
|
|
|
7 |
using System.Diagnostics;
|
|
|
8 |
|
|
|
9 |
namespace SWAT_USB_App
|
|
|
10 |
{
|
|
|
11 |
public static class Initialization
|
|
|
12 |
{
|
|
|
13 |
public static string pathToSWATDrive { get; set; }
|
| 16 |
Kevin |
14 |
public static string computerModel { get; set; }
|
| 10 |
Kevin |
15 |
public static void Initialize()
|
|
|
16 |
{
|
|
|
17 |
try
|
|
|
18 |
{
|
|
|
19 |
// Pulls information from all drives on the running computer
|
|
|
20 |
DriveInfo[] allDrives = DriveInfo.GetDrives();
|
|
|
21 |
// Looks for a drive with the correct label, updates pathToSWATDrive with the drive letter
|
|
|
22 |
foreach (DriveInfo drive in allDrives)
|
|
|
23 |
{
|
|
|
24 |
if (drive.IsReady == true)
|
|
|
25 |
// Drive label for the USB drives is set here.
|
|
|
26 |
if (
|
|
|
27 |
((drive.VolumeLabel.ToUpper() == "SWAT DRIVE X32")
|
|
|
28 |
|| (drive.VolumeLabel.ToUpper() == "SWAT DRIVE X64")
|
|
|
29 |
) && drive.DriveType == DriveType.Removable)
|
|
|
30 |
{
|
|
|
31 |
pathToSWATDrive = drive.Name;
|
|
|
32 |
break;
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
// Prompts for drive to be inserted if none found
|
|
|
36 |
if (pathToSWATDrive == null)
|
|
|
37 |
{
|
|
|
38 |
DialogResult result;
|
|
|
39 |
result = MessageBox.Show("Unable to locate the SWAT USB drive.", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);
|
|
|
40 |
if (result == DialogResult.Retry)
|
|
|
41 |
Initialize();
|
|
|
42 |
else if (result == DialogResult.Cancel)
|
|
|
43 |
{
|
|
|
44 |
if (System.IO.Directory.GetCurrentDirectory() == System.Environment.SystemDirectory)
|
|
|
45 |
{
|
|
|
46 |
// If user chooses to remove the program from startup, initializes code to delete the exe after program exits
|
|
|
47 |
result = MessageBox.Show("Would you like to remove this menu from startup?", "Remove from startup?", MessageBoxButtons.YesNo);
|
|
|
48 |
if (result == DialogResult.Yes)
|
|
|
49 |
{
|
|
|
50 |
// Calls up a hidden command prompt with a timeout of 3 seconds, automatically chooses yes to delete
|
|
|
51 |
ProcessStartInfo Info = new ProcessStartInfo();
|
|
|
52 |
Info.Arguments = "/C choice /C Y /N /D Y /T 3 & Del \"" + Application.ExecutablePath + "\"";
|
|
|
53 |
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
54 |
Info.CreateNoWindow = true;
|
|
|
55 |
Info.FileName = "cmd.exe";
|
|
|
56 |
Process.Start(Info);
|
|
|
57 |
Environment.Exit(1);
|
|
|
58 |
}
|
|
|
59 |
else
|
|
|
60 |
Environment.Exit(1);
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
catch (Exception e)
|
|
|
66 |
{
|
|
|
67 |
MessageBox.Show(e.ToString());
|
|
|
68 |
}
|
|
|
69 |
}
|
| 16 |
Kevin |
70 |
public static void GetModelNumber()
|
|
|
71 |
{
|
| 19 |
Kevin |
72 |
// Pulls the model nubmer of the computer using systeminfo.exe
|
| 16 |
Kevin |
73 |
try
|
|
|
74 |
{
|
|
|
75 |
Process proc = new Process();
|
|
|
76 |
proc.StartInfo.WorkingDirectory = System.Environment.SystemDirectory;
|
|
|
77 |
proc.StartInfo.FileName = "systeminfo.exe";
|
|
|
78 |
proc.StartInfo.UseShellExecute = false;
|
|
|
79 |
proc.StartInfo.RedirectStandardOutput = true;
|
|
|
80 |
proc.StartInfo.CreateNoWindow = true;
|
|
|
81 |
proc.Start();
|
|
|
82 |
string output = "";
|
|
|
83 |
for (int i = 0; i < 14; i++)
|
|
|
84 |
output = proc.StandardOutput.ReadLine();
|
|
|
85 |
computerModel = output.Substring(27);
|
|
|
86 |
}
|
|
|
87 |
catch (Exception e)
|
|
|
88 |
{
|
|
|
89 |
MessageBox.Show(e.ToString());
|
|
|
90 |
}
|
|
|
91 |
}
|
| 10 |
Kevin |
92 |
}
|
|
|
93 |
}
|