4
4
using Microsoft . VisualBasic . Devices ;
5
5
using Microsoft . Win32 ;
6
6
using System . Management ;
7
- using System . IO . Compression ;
8
7
using System . Net ;
9
8
using System . Security . AccessControl ;
10
9
using System . Security . Principal ;
@@ -42,7 +41,7 @@ private static void Main()
42
41
string tempDirectory = Path . GetTempPath ( ) + @"blueelvis" ;
43
42
string systemDrive = Path . GetPathRoot ( Environment . SystemDirectory ) ;
44
43
string applicationVersion = "1.0.4" ;
45
-
44
+ bool is64BitOperatingSystem = false ;
46
45
ComputerInfo sysinfo = new ComputerInfo ( ) ; //References Microsoft.VisualBasic.Devices
47
46
48
47
@@ -94,6 +93,30 @@ private static void Main()
94
93
95
94
// ======================================================================================
96
95
96
+ // ====================================================================================
97
+ Console . WriteLine ( DateTime . Now . ToString ( "G" ) + "\t - Generating SystemInfo\n \n " ) ;
98
+ using ( StreamWriter fileWriter = new StreamWriter ( tempDirectory + @"\systeminfo.txt" ) )
99
+ {
100
+ using ( Process systeminfo = new Process ( ) )
101
+ {
102
+ if ( File . Exists ( Environment . SystemDirectory + @"\systeminfo.exe" ) )
103
+ {
104
+ systeminfo . StartInfo . FileName = Environment . SystemDirectory + @"\systeminfo.exe" ;
105
+ systeminfo . StartInfo . RedirectStandardOutput = true ;
106
+ systeminfo . StartInfo . UseShellExecute = false ;
107
+ systeminfo . Start ( ) ;
108
+ fileWriter . WriteLine ( systeminfo . StandardOutput . ReadToEnd ( ) ) ;
109
+ systeminfo . WaitForExit ( ) ;
110
+ fileWriter . Close ( ) ;
111
+ systeminfo . Close ( ) ;
112
+ }
113
+ else
114
+ {
115
+ Console . WriteLine ( "Systeminfo.exe not found in system" ) ;
116
+ }
117
+ }
118
+
119
+ }
97
120
98
121
// ======================================================================================
99
122
Console . WriteLine ( DateTime . Now . ToString ( "G" ) + "\t - Querying System for Drivers\n \n " ) ;
@@ -122,7 +145,33 @@ private static void Main()
122
145
}
123
146
}
124
147
148
+ // ======================================================================================
149
+ if ( File . Exists ( tempDirectory + @"\systeminfo.txt" ) )
150
+ {
151
+ using ( StreamReader systeminfoReader = new StreamReader ( tempDirectory + @"\systeminfo.txt" ) )
152
+ //Filter out the email address from the report for privacy concerns
153
+ {
154
+ using ( StreamWriter goodsysinfoWriter = new StreamWriter ( tempDirectory + @"\goodsysteminfo.txt" ) )
155
+ {
156
+ int lineNumber = - 1 ;
157
+ while ( systeminfoReader . Peek ( ) >= 0 )
158
+ {
159
+ string logFileContent = systeminfoReader . ReadLine ( ) ;
160
+ lineNumber ++ ;
161
+ if ( lineNumber == 7 )
162
+ continue ;
163
+ if ( lineNumber == 14 )
164
+ if ( logFileContent . Contains ( "x64" ) )
165
+ is64BitOperatingSystem = true ;
166
+
167
+ goodsysinfoWriter . WriteLine ( logFileContent ) ;
125
168
169
+ }
170
+ }
171
+ }
172
+ }
173
+ else
174
+ Console . WriteLine ( "Cannot find SystemInfo.txt" ) ;
126
175
// ======================================================================================
127
176
128
177
using ( StreamWriter fileWriter = new StreamWriter ( tempDirectory + @"\driverlist.txt" ) )
@@ -241,33 +290,8 @@ private static void Main()
241
290
242
291
}
243
292
244
- // ====================================================================================
245
- Console . WriteLine ( DateTime . Now . ToString ( "G" ) + "\t - Generating SystemInfo\n \n " ) ;
246
- using ( StreamWriter fileWriter = new StreamWriter ( tempDirectory + @"\systeminfo.txt" ) )
247
- {
248
- using ( Process systeminfo = new Process ( ) )
249
- {
250
- if ( File . Exists ( Environment . SystemDirectory + @"\systeminfo.exe" ) )
251
- {
252
- systeminfo . StartInfo . FileName = Environment . SystemDirectory + @"\systeminfo.exe" ;
253
- systeminfo . StartInfo . RedirectStandardOutput = true ;
254
- systeminfo . StartInfo . UseShellExecute = false ;
255
- systeminfo . Start ( ) ;
256
- fileWriter . WriteLine ( systeminfo . StandardOutput . ReadToEnd ( ) ) ;
257
- systeminfo . WaitForExit ( ) ;
258
- fileWriter . Close ( ) ;
259
- systeminfo . Close ( ) ;
260
- }
261
- else
262
- {
263
- Console . WriteLine ( "Systeminfo.exe not found in system" ) ;
264
- }
265
- }
266
-
267
- }
268
-
269
293
// ==================================================================================
270
- if ( Environment . Is64BitOperatingSystem )
294
+ if ( is64BitOperatingSystem )
271
295
{
272
296
Console . WriteLine ( DateTime . Now . ToString ( "G" ) + "\t - Exporting x86 Uninstall Registry\n \n " ) ;
273
297
@@ -279,7 +303,7 @@ private static void Main()
279
303
uninstallListx86 . StartInfo . Arguments =
280
304
@"export HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\ " + "\" " +
281
305
tempDirectory +
282
- @"\uninstallx86.txt" + "\" " ;
306
+ @"\uninstallx86.txt" + "\" " + " /reg:32" ;
283
307
uninstallListx86 . Start ( ) ;
284
308
uninstallListx86 . WaitForExit ( ) ;
285
309
uninstallListx86 . Close ( ) ;
@@ -380,7 +404,7 @@ private static void Main()
380
404
{
381
405
if ( File . Exists ( systemDrive + @"\Windows\System32\reg.exe" ) )
382
406
{
383
- if ( ! Environment . Is64BitOperatingSystem )
407
+ if ( ! is64BitOperatingSystem )
384
408
{
385
409
uninstallListx64 . StartInfo . FileName = systemDrive + @"\Windows\System32\reg.exe" ;
386
410
uninstallListx64 . StartInfo . Arguments =
@@ -390,7 +414,7 @@ private static void Main()
390
414
}
391
415
else
392
416
{
393
- uninstallListx64 . StartInfo . FileName = systemDrive + @"\Windows\Sysnative \reg.exe" ;
417
+ uninstallListx64 . StartInfo . FileName = systemDrive + @"\Windows\System32 \reg.exe" ;
394
418
uninstallListx64 . StartInfo . Arguments =
395
419
@"export HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall " +
396
420
"\" " + tempDirectory + "\" " +
@@ -406,6 +430,7 @@ private static void Main()
406
430
{
407
431
Console . WriteLine ( "reg.exe not found in system" ) ;
408
432
}
433
+ Console . WriteLine ( "HelloWorld" ) ;
409
434
}
410
435
411
436
}
@@ -515,7 +540,7 @@ private static void Main()
515
540
Console . WriteLine ( DateTime . Now . ToString ( "G" ) +
516
541
"\t - Blank File for x64 Uninstall List Created\n \n " ) ;
517
542
}
518
- using ( var output = File . Create ( tempDirectory + @"\uninstall-reg.txt" ) )
543
+ /* using (var output = File.Create(tempDirectory + @"\uninstall-reg.txt"))
519
544
{
520
545
foreach (
521
546
var file in new[] { tempDirectory + @"\uninstallx86.txt", tempDirectory + @"\uninstallx64.txt" })
@@ -525,7 +550,25 @@ private static void Main()
525
550
input.CopyTo(output);
526
551
}
527
552
}
528
- }
553
+ }*/
554
+ using ( StreamReader uninstallx86Reader = new StreamReader ( tempDirectory + @"\uninstallx86.txt" ) )
555
+ {
556
+ using ( StreamReader uninstallx64Reader = new StreamReader ( tempDirectory + @"\uninstallx64.txt" ) )
557
+ {
558
+ using ( StreamWriter uninstallRegWriter = new StreamWriter ( tempDirectory + @"\uninstall-reg.txt" ) )
559
+ {
560
+ while ( uninstallx86Reader . Peek ( ) >= 0 )
561
+ {
562
+ uninstallRegWriter . WriteLine ( uninstallx86Reader . ReadLine ( ) ) ;
563
+ }
564
+ while ( uninstallx64Reader . Peek ( ) >= 0 )
565
+ {
566
+ uninstallRegWriter . WriteLine ( uninstallx64Reader . ReadLine ( ) ) ;
567
+ }
568
+ }
569
+ }
570
+ }
571
+
529
572
530
573
//Process the exported uninstall registry and filter out values and compile a single list
531
574
using (
@@ -663,23 +706,6 @@ private static void Main()
663
706
}
664
707
}
665
708
666
- using ( StreamReader systeminfoReader = new StreamReader ( tempDirectory + @"\systeminfo.txt" ) ) //Filter out the email address from the report for privacy concerns
667
- {
668
- using ( StreamWriter goodsysinfoWriter = new StreamWriter ( tempDirectory + @"\goodsysteminfo.txt" ) )
669
- {
670
- int lineNumber = - 1 ;
671
- while ( systeminfoReader . Peek ( ) >= 0 )
672
- {
673
- string logFileContent = systeminfoReader . ReadLine ( ) ;
674
- lineNumber ++ ;
675
- if ( lineNumber == 7 )
676
- continue ;
677
- goodsysinfoWriter . WriteLine ( logFileContent ) ;
678
-
679
- }
680
- }
681
- }
682
-
683
709
using ( StreamReader hotFixReader = new StreamReader ( tempDirectory + @"\InstalledWindowsUpdates.txt" ) ) //Check the number of Windows Updates installed on a system
684
710
{
685
711
while ( hotFixReader . Peek ( ) >= 0 )
@@ -869,9 +895,11 @@ private static void Main()
869
895
Thread . Sleep ( 8000 ) ;
870
896
}
871
897
Console . WriteLine ( DateTime . Now . ToString ( "G" ) + "\t - Zipping Up Files!" ) ;
872
- ZipFile . CreateFromDirectory ( tempDirectory ,
873
- Environment . GetFolderPath ( Environment . SpecialFolder . DesktopDirectory ) + @"\" + zipFileName ,
874
- CompressionLevel . Optimal , false ) ;
898
+ bool zipFileStatus = ZipFile ( tempDirectory , zipFileName ) ;
899
+ if ( ! zipFileStatus )
900
+ {
901
+ Console . WriteLine ( "There was an error while creating the ZIP file" ) ;
902
+ }
875
903
var greetingsProcess = Process . Start ( tempDirectory + @"\greetings.txt" ) ;
876
904
Thread . Sleep ( 1000 ) ;
877
905
if ( greetingsProcess != null ) //Flash the taskbar icon of Notepad in case user has lost focus
@@ -925,23 +953,70 @@ static string Quotes()
925
953
}
926
954
}
927
955
956
+ /// <summary>
957
+ /// Zip File mechanism using Shell32. Easiest way to do without any 3rd party API
958
+ /// </summary>
959
+ /// <param name="inputPath"></param>
960
+ /// <param name="zipFileName"></param>
961
+ /// <returns></returns>
962
+ private static bool ZipFile ( string inputPath , string zipFileName )
963
+ {
964
+ byte [ ] emptyzip = new byte [ ] { 80 , 75 , 5 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
965
+ FileStream fs = File . Create ( Environment . GetFolderPath ( Environment . SpecialFolder . DesktopDirectory ) + @"\" +
966
+ zipFileName ) ;
967
+ fs . Write ( emptyzip , 0 , emptyzip . Length ) ;
968
+ fs . Flush ( ) ;
969
+ fs . Close ( ) ;
970
+ try
971
+ {
972
+ Shell32 . Folder zipInput = GetShell32NameSpace ( inputPath ) ;
973
+ Shell32 . Folder zipOutput =
974
+ GetShell32NameSpace ( Environment . GetFolderPath ( Environment . SpecialFolder . DesktopDirectory ) + @"\" +
975
+ zipFileName ) ;
976
+ foreach ( var file in zipInput . Items ( ) )
977
+ {
978
+ if ( file != null )
979
+ zipOutput . CopyHere ( file , 4 | 16 ) ;
980
+ Thread . Sleep ( 1000 ) ;
981
+ }
982
+ return true ;
983
+ }
984
+ catch ( Exception )
985
+ {
986
+ return false ;
987
+ }
988
+ }
989
+
928
990
/// <summary>
929
991
/// Converts the Date & Time which is generated by several WMI commands into human readable form
930
992
/// </summary>
931
993
/// <param name="stringDateToConvert">String parameter which contains the date & time outputted by several WMI Commands</param>
932
994
/// <returns>Returns a string containing the date & time</returns>
933
- static string ConvertDateTime ( string stringDateToConvert )
995
+ private static string ConvertDateTime ( string stringDateToConvert )
934
996
{
935
997
stringDateToConvert = stringDateToConvert . Replace ( "\r " , "" ) . Replace ( "\n " , "" ) ;
936
998
if ( stringDateToConvert . Length > 8 )
937
999
stringDateToConvert = stringDateToConvert . Remove ( 8 ) ;
938
1000
939
1001
var temporaryArray = stringDateToConvert . ToCharArray ( ) ;
940
- var output = temporaryArray [ 0 ] . ToString ( ) + temporaryArray [ 1 ] . ToString ( ) + temporaryArray [ 2 ] . ToString ( ) + temporaryArray [ 3 ] . ToString ( ) + "-" ;
1002
+ var output = temporaryArray [ 0 ] . ToString ( ) + temporaryArray [ 1 ] . ToString ( ) + temporaryArray [ 2 ] . ToString ( ) +
1003
+ temporaryArray [ 3 ] . ToString ( ) + "-" ;
941
1004
output += temporaryArray [ 4 ] . ToString ( ) + temporaryArray [ 5 ] . ToString ( ) + "-" ;
942
1005
output += temporaryArray [ 6 ] . ToString ( ) + temporaryArray [ 7 ] . ToString ( ) ;
943
1006
944
1007
return output ;
945
1008
}
1009
+
1010
+ /// <summary>
1011
+ /// Shell32 Code Since Shell32 changed in Windows 7. Read More over here - http://techitongue.blogspot.in/2012/06/shell32-code-compiled-on-windows-7.html
1012
+ /// </summary>
1013
+ /// <param name="folder"></param>
1014
+ /// <returns></returns>
1015
+ static public Shell32 . Folder GetShell32NameSpace ( Object folder )
1016
+ {
1017
+ Type shellAppType = Type . GetTypeFromProgID ( "Shell.Application" ) ;
1018
+ var shell = Activator . CreateInstance ( shellAppType ) ;
1019
+ return ( Shell32 . Folder ) shellAppType . InvokeMember ( "NameSpace" , System . Reflection . BindingFlags . InvokeMethod , null , shell , new [ ] { folder } ) ;
1020
+ }
946
1021
}
947
1022
}
0 commit comments