Skip to content

Commit 355b9a8

Browse files
committed
Add OS version
1 parent 93fd88a commit 355b9a8

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

SaveWin10Pictures/Program.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ private static void Main()
1414
List<string> files = new List<string>();
1515
int counter = 0;
1616
//string OSVersion = Environment.OSVersion.ToString(); // 6.2 ON Win 10
17+
string OSVersion = GetOSInfo();
1718
//string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
1819
string userName = Environment.UserName;
1920
// remove domain if any
@@ -184,5 +185,89 @@ public static List<string> GetFilesFileteredBySize(DirectoryInfo directoryInfo,
184185

185186
return result;
186187
}
188+
189+
public static string GetOSInfo()
190+
{
191+
//Get Operating system information.
192+
OperatingSystem os = Environment.OSVersion;
193+
//Get version information about the os.
194+
Version vs = os.Version;
195+
196+
//Variable to hold our return value
197+
string operatingSystem = "";
198+
199+
if (os.Platform == PlatformID.Win32Windows)
200+
{
201+
//This is a pre-NT version of Windows
202+
switch (vs.Minor)
203+
{
204+
case 0:
205+
operatingSystem = "95";
206+
break;
207+
case 10:
208+
if (vs.Revision.ToString() == "2222A")
209+
operatingSystem = "98SE";
210+
else
211+
operatingSystem = "98";
212+
break;
213+
case 90:
214+
operatingSystem = "Me";
215+
break;
216+
default:
217+
break;
218+
}
219+
}
220+
else if (os.Platform == PlatformID.Win32NT)
221+
{
222+
switch (vs.Major)
223+
{
224+
case 3:
225+
operatingSystem = "NT 3.51";
226+
break;
227+
case 4:
228+
operatingSystem = "NT 4.0";
229+
break;
230+
case 5:
231+
if (vs.Minor == 0)
232+
operatingSystem = "2000";
233+
else
234+
operatingSystem = "XP";
235+
break;
236+
case 6:
237+
if (vs.Minor == 0)
238+
operatingSystem = "Vista";
239+
else if (vs.Minor == 1)
240+
operatingSystem = "7";
241+
else if (vs.Minor == 2)
242+
operatingSystem = "8";
243+
else
244+
operatingSystem = "8.1";
245+
break;
246+
case 10:
247+
operatingSystem = "10";
248+
break;
249+
default:
250+
break;
251+
}
252+
}
253+
//Make sure we actually got something in our OS check
254+
//We don't want to just return " Service Pack 2" or " 32-bit"
255+
//That information is useless without the OS version.
256+
if (operatingSystem != "")
257+
{
258+
//Got something. Let's prepend "Windows" and get more info.
259+
operatingSystem = "Windows " + operatingSystem;
260+
//See if there's a service pack installed.
261+
if (os.ServicePack != "")
262+
{
263+
//Append it to the OS name. i.e. "Windows XP Service Pack 3"
264+
operatingSystem += " " + os.ServicePack;
265+
}
266+
//Append the OS architecture. i.e. "Windows XP Service Pack 3 32-bit"
267+
//operatingSystem += " " + getOSArchitecture().ToString() + "-bit";
268+
}
269+
//Return the information we've gathered.
270+
return operatingSystem;
271+
}
187272
}
188273
}

0 commit comments

Comments
 (0)