forked from jagilber/powershellScripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DumpConfigurator.hta
1289 lines (1006 loc) · 49.5 KB
/
DumpConfigurator.hta
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<!--
Warranty Disclaimer
--------------------------
This sample code, utilities, and documentation are provided as is, without warranty of any kind. Microsoft further disclaims all
implied warranties including without limitation any implied warranties of merchantability or of fitness for a particular purpose.
The entire risk arising out of the use or performance of the product and documentation remains with you.
In no event shall Microsoft be liable for any damages whatsoever (including, without limitation, damages for loss of business
profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to
use the sample code, utilities, or documentation, even if Microsoft has been advised of the possibility of such damages.
Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above
limitation may not apply to you.
ver 150412 added dedicateddumpfile functionality. fixed windows 10 bug
ver 150531 fixed CInt when calculating kernel mem dump for x64. changed to Clng
-->
<head>
<title>Windows Memory Dump Configuration Editor</title>
<HTA:APPLICATION
ID="objMemDumpConfig"
APPLICATIONNAME="DumpConfigurator"
BORDER="thin"
ICON="appverif.ico"
INNERBORDER = "yes"
MAXIMIZEBUTTON = "yes"
NAVIGABLE = "no"
SCROLL="yes"
SINGLEINSTANCE="yes"
SHOWINTASKBAR="yes"
WINDOWSTATE="normal"
>
<style type="text/css">
BODY
{
FONT-FAMILY: verdana;
FONT-SIZE: 90%
}
H1
{
FONT-SIZE: 170%
}
TABLE.tblWinDialog
{
BACKGROUND-COLOR: buttonface;
FONT-SIZE: 85%
}
TABLE.tblWinDialog CAPTION
{
BACKGROUND-COLOR: activecaption;
COLOR: captiontext;
FONT-WEIGHT: bold;
TEXT-ALIGN: center;
}
TABLE.tblWinDialog INPUT
{
FONT-FAMILY: verdana;
FONT-SIZE: 100%
}
TABLE.tblWinDialog SELECT
{
FONT-FAMILY: verdana;
FONT-SIZE: 100%
}
TABLE.tblWinDialog TABLE
{
FONT-SIZE: 100%
BORDER: 10px
CELLSPACING: 2
CELLPADDING: 2
}
TABLE.tblWinDialog INPUT READONLY
{
BACKGROUND-COLOR: buttonface
}
TABLE.tblWinDialog BUTTON
{
FONT-FAMILY: verdana;
FONT-SIZE: 100%
}
input.customButton {
FONT-FAMILY: verdana;
FONT-SIZE: 100%
padding: 2px;
height: 25px;
width: 110px;
}
TABLE.t_noborder TD{
BORDER: 0px
}
</style>
</head>
<SCRIPT Language="VBScript">
' Create constants for access rights and registry hive
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
const KEY_QUERY_VALUE = 1
Const KEY_SET_VALUE = 2
Const DUMP_HEADER_32BIT = 1
Const DUMP_HEADER_64BIT = 1
Dim Shell : Set Shell = CreateObject("Wscript.Shell")
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
'Declare globals
Dim g_strComputer, g_StatusWindow, g_TempDir
Dim g_intMemTotal : g_intMemTotal = 0 'Total Physical Memory in the System
Dim g_intMemVisible : g_intMemVisible = 0 'Memory visible to the system
Dim g_pfInitialSize, g_pfPeakUsage, g_pfName
Dim g_strSystemDrive, g_strSystemRoot, g_strOSCaption, g_strOSArch, g_isPAEEnabled, g_has3gb, g_strServicePackMajorVersion, g_strOSVersion
Dim g_intDumpType, g_strDumpType, g_dumpAutoReboot, g_dumpOverwrite, g_dumpFileLocation, g_miniDumpLocation, g_LogEvent, g_CtrlScrolli8042
Dim g_NMIDump, g_SystemDriveFree, g_intDumpRequiredMB, g_RequiredFreeMB, g_CtrlScrollKbHid
Dim g_DedicatedDumpFile, g_DedicatedDumpFileChecked, g_DedicatedDumpFileLocation, g_isLegacyOS
Dim g_DumpTargetDrive, g_DumpTargetDriveFree, g_DriveType
Dim g_i8042Checked, g_nmichecked, g_autorebootChecked, g_dumpoverwriteChecked
Dim g_HasAdminPerms, g_RequiredPageFileMB, g_HtmlLoaded
g_TempDir = Shell.ExpandEnvironmentStrings("%TEMP%")
g_isLegacyOS = False 'Assume we are dealing with at Least Windows XP until the OS check is run
g_strComputer = "."
g_RequiredPageFileMB = 0
Sub Window_Onload
ResizeHTAWindow 900, 650 'Set Window size and position
document.focus
Call Main()
End Sub
'********** Main ***********
Sub Main()
g_HtmlLoaded = False
document.body.style.cursor = "wait"
'Check for admin access to the registry
g_HasAdminPerms = hasRequiredRegAccess(g_strComputer,HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Control\CrashControl",KEY_SET_VALUE)
'compensate for the output size difference when elevation warning is not displayed
If g_HasAdminPerms Then ResizeHTAWindow 900, 600
'Check Physical Memory Size
g_intMemTotal = ConvertBytes(GetTotalPhysicalMemory(g_strComputer), "MB")
g_intMemVisible = ConvertBytes(GetVisibleMem(g_strComputer),"KB")
'Populate our global variables
GetSystemInfo g_strComputer, g_strSystemDrive, g_strSystemRoot, g_strOSCaption, g_strOSArch, g_isPAEEnabled, g_strServicePackMajorVersion, g_strOSVersion
'Check for Legacy OS (Windows 2000)
If Instr(g_strOSCaption,"2000") > 0 Then
g_isLegacyOS = True
Else
g_isLegacyOS = False
End If
'Skip Pagefile Info for Windows 2000 because the WMI classes are not supported
If g_isLegacyOS Then
g_pfInitialSize = "<font size=-3 color=red>WMI CLASS NOT SUPPORTED ON THIS OS</font>"
g_pfPeakUsage = "<font size=-3 color=red>WMI CLASS NOT SUPPORTED ON THIS OS</font>"
g_pfName = "<font size=-3 color=red>WMI CLASS NOT SUPPORTED ON THIS OS</font>"
g_SystemDriveFree = -1
Else
GetPageFileInfo g_strComputer, g_strSystemDrive, g_pfInitialSize, g_pfPeakUsage, g_pfName
GetDiskFreeSpace g_strComputer, g_strSystemDrive, g_SystemDriveFree, g_DriveType
End If
'Populate variables with current crash dump settings
GetCrashDumpInfo g_strComputer, g_intDumpType, g_dumpAutoReboot, g_dumpOverwrite, g_dumpFileLocation, g_miniDumpLocation, g_LogEvent, g_CtrlScrolli8042, g_NMIDump, g_has3GB, g_DedicatedDumpFile, g_DedicatedDumpFileLocation
'Check for an alternate dump location
SetDumpTargetDrive()
'Check to see if we are returning from the Status Window and close it
If TypeName(g_StatusWindow) <> "Empty" Then g_StatusWindow.close
'set up the dump type string
Select Case g_intDumpType
Case 0
g_strDumpType = "NONE"
Case 1
g_strDumpType = "FULL"
Case 2
g_strDumpType = "KERNEL ONLY"
Case 3
g_strDumpType = "SMALL"
Case Else
'This should never happen unless this script is incorrectly modified
g_strDumpType = "INVALID TYPE: " & intDumpType
End Select
'Set g_strComputername for display purposes
If g_strComputer = "." Then
Dim network : Set network = CreateObject("Wscript.network")
g_strComputer = network.ComputerName
End If
If g_CtrlScrolli8042 = 1 Then
g_i8042Checked = "checked"
g_CtrlScrolli8042 = " <strong>Enabled</strong>"
Else
g_i8042Checked = ""
g_CtrlScrolli8042 = ""
End If
If g_NMIDump = 1 Then
g_nmichecked = "checked"
g_NMIDump = " <strong>Enabled</strong>"
Else
g_nmichecked = ""
g_NMIDump = ""
End If
If g_dumpAutoReboot = 1 Then
g_autorebootChecked = "checked"
g_dumpAutoReboot = " <strong>Enabled</strong>"
Else
g_autorebootChecked = ""
g_dumpAutoReboot = ""
End If
If g_DedicatedDumpFile = True Then
g_DedicatedDumpFileChecked = "checked"
g_DedicatedDumpFile = " <strong>Enabled</strong>"
Else
g_DedicatedDumpFileChecked = ""
g_DedicatedDumpFile = ""
End If
If g_dumpOverwrite = 1 Then
g_dumpoverwriteChecked = "checked"
g_dumpOverwrite = " <strong>Enabled</strong>"
Else
g_dumpoverwriteChecked = ""
g_dumpOverwrite = ""
End If
OutputHTML()
End Sub
'*****************************************************
' Formats strInput as an HTML table row
'*****************************************************
Function TableRow(strInput)
TableRow = "<tr><td> " & strInput & " </td></tr>"
End Function
'*************************************************************
' Resizes and Centers the Window takes (x,y) size as input
'*************************************************************
Sub ResizeHTAWindow( intWidth, intHeight)
self.ResizeTo intWidth, intHeight
self.MoveTo (screen.Width - intWidth)/2, (screen.Height - intHeight)/2
End Sub
'*********************************************************************
' Opens the status window when we try to connect to a remote system
'*********************************************************************
Sub DisplayStatusWindow(strComputer)
Dim OptionString
OptionString = "dialogHeight: 65px; dialogWidth: 450px;"
Set g_StatusWindow = window.showModelessDialog("about:blank", window, OptionString)
g_StatusWindow.document.body.style.fontFamily = "verdana"
g_StatusWindow.document.body.style.margin = "1%"
g_StatusWindow.document.body.style.cursor = "wait"
g_StatusWindow.document.body.style.backgroundColor = "buttonface"
g_StatusWindow.document.body.innerhtml = "<html><body><strong> Trying to connect to " & ucase(strComputer) & "<br> This may take up to 60 seconds. Please wait... </strong></body></html>"
End Sub
'*****************************************************
' Retrieves information about current crashdump config
'*****************************************************
Sub GetCrashDumpInfo(ByVal strComputer, ByRef DumpType, ByRef AutoReboot, ByRef Overwrite, ByRef DumpLocation, _
ByRef miniDumpDir, ByRef LogEvent, ByRef CtrlScrolli8042, ByRef NMIDump, ByRef has3GB, ByRef hasDedicatedDumpFile, ByRef dedicatedDumpFileLocation)
Dim oReg, strKeyPath, strValueName, dwValue, strValue
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "CrashDumpEnabled"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
DumpType = dwValue
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "AutoReboot"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
AutoReboot = dwValue
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "LogEvent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
LogEvent = dwValue
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "Overwrite"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
Overwrite = dwValue
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "NMICrashDump"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
NMIDump = dwValue
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "DumpFile"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
DumpLocation = strValue
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "MiniDumpDir"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
miniDumpDir = strValue
'Check for existence of dedicated dump file value (Vista/Windows 2008+)
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "DedicatedDumpFile"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If Not IsNull(strValue) Then
hasDedicatedDumpFile = True
dedicatedDumpFileLocation = strValue
Else
hasDedicatedDumpFile = False
dedicatedDumpFileLocation = Null
End If
strKeyPath = "System\CurrentControlSet\Services\i8042prt\Parameters"
strValueName = "CrashOnCtrlScroll"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
CtrlScrolli8042 = dwValue
' The following sections checks the boot options for 3GB
strKeyPath = "System\CurrentControlSet\Control"
strValueName = "SystemStartOptions"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValue = UCase(strValue)
If InStr(strValue, "3GB") > 0 Then
has3GB = True
Else
has3GB = False
End If
End Sub
'*****************************************************
' Sets system crashdump configuration
'*****************************************************
Sub SetCrashDumpInfo(ByVal strComputer, ByVal DumpType, ByVal AutoReboot, ByVal Overwrite, ByVal DumpLocation, _
ByVal miniDumpDir, ByVal LogEvent, ByVal CtrlScrolli8042, ByVal NMIDump, ByVal dedicatedDumpFile, ByVal dedicatedDumpFileLocation)
document.body.style.cursor = "wait"
Dim oReg, strKeyPath, strValueName, dwValue, strValue
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "CrashDumpEnabled"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,DumpType
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "AutoReboot"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,AutoReboot
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "LogEvent"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,LogEvent
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "Overwrite"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,Overwrite
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "NMICrashDump"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,NMIDump
strKeyPath = "System\CurrentControlSet\Services\i8042prt\Parameters"
strValueName = "CrashOnCtrlScroll"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,CtrlScrolli8042
strKeyPath = "System\CurrentControlSet\Services\kbdhid\Parameters"
strValueName = "CrashOnCtrlScroll"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,CtrlScrolli8042
'If OS is Vista or Higher set the IgnorePagefileSize value as per KB949052
If GetMajorOSVer() => 6 Then
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "IgnorePagefileSize"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,1
' for dedicated dump file if enabled
If dedicatedDumpFile = True Then
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "DedicatedDumpFile"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dedicatedDumpFileLocation
Else
' remove key
strKeyPath = "System\CurrentControlSet\Control\CrashControl"
strValueName = "DedicatedDumpFile"
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName
End If
End If
document.body.style.cursor = "default"
End Sub
'*****************************************************************
' Checks to see if the system was booted with /3gb
' returns true or false
'*****************************************************************
Function BootedWith3gb()
On Error Resume Next
Dim oReg, strKeyPath, strValueName, dwValue, strValue
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
g_strComputer & "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Control"
strValueName = "SystemStartOptions"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValue = UCase(strValue)
If InStr(strValue, "3GB") > 0 Then
BootedWith3gb = True
Else
BootedWith3gb = False
End If
End Function
'*****************************************************************
' Calculates the estimated requirement for the selected dump types
'*****************************************************************
Function GetEstimatedDumpMB(intDumpType)
Select Case intDumpType
Case "1" 'Complete Dump Selected
'32bit and 64bit actually return the same values for complete (visible mem + 1MB)
If g_strOSArch = "32-bit" Then
GetEstimatedDumpMB = g_IntMemVisible + DUMP_HEADER_32BIT 'Return Visible MEM +1MB for dump header
ElseIf g_strOSArch = "64-bit" Then
GetEstimatedDumpMB = g_IntMemVisible + DUMP_HEADER_64BIT 'Return Visible MEM +64 bit dump header size
End If
Case "2" 'Kernel Dump Selected
If g_strOSArch = "32-bit" Then
If g_has3gb Then
GetEstimatedDumpMB = 1024 + DUMP_HEADER_32BIT ' with 3gb max kernel memory is 1GB
Else
'Maximum amount of kernel VA on x86 is 2GB
If g_intMemVisible < 2048 Then
GetEstimatedDumpMB = g_intMemVisible + DUMP_HEADER_32BIT 'less than 2gb ram just use size of complete dump
Else
GetEstimatedDumpMB = 2048 + DUMP_HEADER_32BIT 'Return 2GB (rounded up) potential 32-bit kernel VA +1MB for dump header
End If
End If
ElseIf g_strOSArch = "64-bit" Then
'Return 33% of visible memory value as ESTIMATED Kernel dump size as per
'http://msdn.microsoft.com/en-us/library/cc266504.aspx
GetEstimatedDumpMB = CLng(g_intMemVisible/3) + DUMP_HEADER_64BIT
End If
End Select
End Function
'*****************************************************************
' Checks to see if there is enough room on
' the system drive to expand the pagefile (assumes +500MB free after expand)
'*****************************************************************
Sub CheckRoomOnSystemDriveForPageFileExpand(ByVal intSystemDriveFreeSpace, ByVal intCurrentPageFileSize, ByVal intRequiredPageFileSize, ByRef intRequiredFree)
'added 500MB required free space after expand for padding
If intSystemDriveFreeSpace >= (intRequiredPageFileSize - intCurrentPageFileSize + 500) Then
intRequiredFree = 0
Else
intRequiredFree = intRequiredPageFileSize - intCurrentPageFileSize + 500
End If
End Sub
'*****************************************************************
' Checks to see if dump will fit in current systemdrive pagefile
'*****************************************************************
Function DumpFitsInPageFile()
If g_pfInitialSize => g_intDumpRequiredMB Then
DumpFitsInPageFile = True
Else
g_RequiredPageFileMB = g_intDumpRequiredMB - g_pfInitialSize
DumpFitsInPageFile = False
End If
End Function
'*****************************************************************
' Checks to see if dump will fit on the target Drive
'*****************************************************************
Function DumpFitsOnTargetDrive()
'If we're on the system drive we need to account for potential required
'space for a pagefile expansion that will not happen until we reboot
If g_DumpTargetDrive = g_strSystemDrive Then
If ConvertBytes(g_DumpTargetDriveFree,"MB") => (g_intDumpRequiredMB + g_RequiredPageFileMB + 500) Then
DumpFitsOnTargetDrive = True
Else
DumpFitsOnTargetDrive = False
End If
Else
'If dump target freespace is at least 500MB larger than required
'dump size then return true
If ConvertBytes(g_DumpTargetDriveFree,"MB") => (g_intDumpRequiredMB + 500) Then
DumpFitsOnTargetDrive = True
Else
DumpFitsOnTargetDrive = False
End If
End If
End Function
'**************************************************************
' Retrieves information about pagefile on the specified Drive
'**************************************************************
Sub GetPageFileInfo(ByVal strComputer, ByVal strDrive, ByRef InitialSize, ByRef PeakUsage, byRef pfName)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate}\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.Instancesof("Win32_PageFileUsage where Name like '" & Left(strDrive,1) & "%'")
For Each objItem In colItems
InitialSize = objItem.AllocatedBaseSize
PeakUsage = objItem.PeakUsage
pfName = objItem.Name
Next
End Sub
'*****************************************************
' Sets PageFile size on the target system
'*****************************************************
Sub SetPageFileInfo(ByVal strComputer, ByVal strSystemDrive, ByVal pfInitialSizeInMB, ByVal pfMaxSizeInMB)
Dim objWMIService, colPageFiles, objPageFile
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate}\\" & strComputer & "\root\cimv2")
Set colPageFiles = objWMIService.ExecQuery _
("Select * from Win32_PageFileSetting where Name='" & strSystemDrive & "\\pagefile.sys'")
For Each objPageFile in colPageFiles
objPageFile.InitialSize = pfInitialSizeInMB
objPageFile.MaximumSize = pfMaxSizeinMB
objPageFile.Put_
Next
End Sub
'*****************************************************
' Retrieves information about the system configuration
'*****************************************************
Sub GetSystemInfo(ByVal strComputer, ByRef strSystemDrive, ByRef strSystemRoot, ByRef strOSCaption, ByRef strOSArch, ByRef isPAEEnabled, ByRef strServicePackMajorVersion, ByRef strOSVersion)
On Error Resume Next
Dim objWMIService, colItems, objItem
strOSArch = "" 'initialize this to blank until try to set it
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate}\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_OperatingSystem",,48)
For Each objItem In colItems
strSystemDrive = ucase(objItem.SystemDrive)
strSystemRoot = objItem.WindowsDirectory
strOSCaption = objItem.Caption
strOSArch = objItem.OSArchitecture
If strOSArch = "" Then 'System was pre Vista/Longhorn and strOSArch was not supported
Err.Clear 'clear error for unsupported value
If Is64bit(strComputer) Then
strOSArch = "64-bit"
Else
strOSArch = "32-bit"
End If
End If
If strOSArch = "64-bit" Then ' PAE is not used on 64-bit systems
isPAEEnabled = "N/A"
Else
isPAEEnabled = objItem.PAEEnabled
End If
strServicePackMajorVersion = objItem.ServicePackMajorVersion
strOSVersion = objItem.Version
Next
End Sub
'************************************************
' Returns the total physical memory in bytes
'************************************************
Function GetTotalPhysicalMemory(strComputer)
Dim intMem
intMem = 0
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate}\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_PhysicalMemory",,48)
For Each objItem In colItems
intMem = intMem + Int(objItem.Capacity)
Next
GetTotalPhysicalMemory = intMem
End Function
'******************************************************
' Returns an integer conversion of bytes to KB,MB,or GB
'******************************************************
Function ConvertBytes(intBytes, strConvertTo)
strConvertTo = ucase(strConvertTo)
Dim tempval
Select Case strConvertTo
Case "KB"
tempval = round((intBytes/1024 +.49 ),0) 'added .49 to round up
Case "MB"
tempval = round((intBytes/1048576 ),2)
Case "GB"
tempval = round((intBytes/1073741824 ),2)
Case Else
'raise error
End Select
ConvertBytes = tempval
End Function
'************************************************
' Returns the total visible memory in bytes
'************************************************
Function GetVisibleMem(ByVal strComputer)
Dim intMemTotal, objWMIService, colItems, objItem
intMemTotal = 0
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate}\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT TotalVisibleMemorySize FROM Win32_OperatingSystem",,48)
For Each objItem in colItems
intMemTotal = Int(objItem.TotalVisibleMemorySize)
Next
GetVisibleMem = intMemTotal
End Function
'**************************************************
' Returns true if system is 64-bit or false if 32
'**************************************************
Function Is64bit(ByVal strComputer)
On Error Resume Next
Dim oReg, strKeyPath, strValueName, strValue, retval
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion"
strValueName = "ProgramFilesDir (x86)"
retval = oReg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue)
If retval <> 0 Then
Is64bit = False
Else
Is64bit = True
End If
End Function
'*******************************************************
' Returns the freespace of the specified drive in bytes
'*******************************************************
Sub GetDiskFreeSpace(ByVal strComputer, ByVal strDrive, ByRef intFreeSpace, ByRef intDriveType)
On Error Resume Next
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:{impersonationlevel=impersonate}\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where Name ='" & strDrive & "'",,48)
For Each objItem in colItems
intFreeSpace = objItem.FreeSpace
intDriveType = objItem.DriveType
Next
End Sub
'******************************************************
' Pings a system to see if it is available
'******************************************************
Function IsUp(ByVal strComputer)
On Error Resume Next
Dim objWMIService, propValue, objItem, SWBemlocator, UserName, Password, colItems
UserName = ""
Password = ""
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(".","root\CIMV2",UserName,Password,,,128)
Set colItems = objWMIService.ExecQuery("Select * from Win32_PingStatus where address = " & "'" & strComputer & "'",,48)
For Each objItem in colItems
If objItem.StatusCode = 0 Then
IsUp = True
Else
IsUp = False
End If
Next
End Function
'**********************************************************************
' Gets a new computername to attach To (modifies global g_strComputer)
'**********************************************************************
Sub GetNewComputerName()
Dim strComputername
strComputername = Trim(InputBox("Please enter the name or IP address of the computer you would like to attach to:","Connect to a remote system","."))
If (strComputername <> "." And strComputername <> "") Then
document.body.style.cursor = "wait"
DisplayStatusWindow(ucase(strComputername))
If IsUp(strComputername) Then
g_strComputer = Ucase(strComputername)
document.body.style.cursor = "default"
Call Main()
Else
MsgBox ucase(strComputername) & " could not be reached via ping!" & VbCrLf & "Please check the spelling and try again.",vbOKOnly+vbExclamation,"System could not be pinged..."
document.body.style.cursor = "default"
Call Main()
End If
Else
If strComputername = "." Then
g_strComputer = "."
Call Main()
End If
End If
End Sub
'*******************************************************
' Checks access to the specified registry key
'*******************************************************
Function HasRequiredRegAccess(ByVal strComputer, ByVal hive, ByVal strKeyPath, ByVal AccessMask)
On Error Resume Next
Dim objReg, bHasAccessRight
Err.Clear
Set objReg=GetObject("winmgmts:"_
& "{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
If Err.Number <> 0 Then
Msgbox "Could not connect to: " & strComputer & VbCrLf & VbCrLf & "Error: " & Err.Number & " - " & Err.Description & _
VbCrLf & VbCrLf & "Please make sure the system's firewall rules allow RPC traffic for WMI/DCOM and that you have administrative "& _
"rights on the machine." & VbCrLf & VbCrLf & "Click OK to Exit.",VBExclamation+vbOKOnly
'There was a fatal error that may cause the HTA to hang so let's terminate mshta.exe, but only if it contains DumpConfigurator in the name
For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}!//.").ExecQuery("select * from Win32_Process where Name='mshta.exe' and CommandLine like '%DumpConfigurator%'")
Process.Terminate
Next
Else
'Check the access rights to the registry
objReg.CheckAccess hive, strKeyPath, AccessMask, bHasAccessRight
If bHasAccessRight = True Then
HasRequiredRegAccess = True
Else
HasRequiredRegAccess = False
End If
End If
End Function
'****************************************************************
' Auto configures system for dump w/autoreboot
' overwrite, ps2, nmi, and LogEvent
' intDumptype is passed in to set either full (1) or kernel (2)
'****************************************************************
Sub AutoConfigureDump(intDumpType)
'Backup current dump config in unique file
SetDumpTargetDrive()
g_intDumpRequiredMB = GetEstimatedDumpMB(intDumpType)
'First check to see if the dump fits in the pagefile, then check for free disk space
If Not DumpFitsInPageFile Then
'Dump too large for pagefile, check for dedicated dump file (Vista/2008+)
If Not g_DedicatedDumpFile Then
'No dedicated dump file, let's check to see if we can expand the pagefile
CheckRoomOnSystemDriveForPageFileExpand g_SystemDriveFree, g_pfInitialSize, g_intDumpRequiredMB, g_RequiredFreeMB
If (g_RequiredFreeMB = 0) Then 'we have room for a larger pagefile let's see if they want it expanded
retval = MsgBox("Your system does not currently have a pagefile large enough to accommodate the selected dump type. You need a pagefile initial size of at least " & g_intDumpRequiredMB & "MB. Would you like this application to expand the pagefile for you?",vbYesNo+vbExclamation,"Pagefile Size Warning...")
If retval = vbYes Then
SetPageFileInfo g_strComputer, g_strSystemDrive, g_intDumpRequiredMB, g_intDumpRequiredMB
Else
window.alert("You have chosen not to automatically increase the pagefile size. Your settings will be saved but a manual increase of the pagefile size and reboot will be required in order to obtain the selected memory dump type from your system.")
End If
Else
MsgBox "Your system does not have enough free space to expand the pagefile to the required sized for the selected dump type. Please free up the required space of at least " & g_RequiredFreeMB & "MB or select a different dump type.",vbOKOnly+vbExclamation,"Disk Space Warning..."
End If
Else
MsgBox "Your system has the DedicatedDumpFile value configured. Your registry settings will be saved, but pagefile checks will be skipped.",vbOKOnly+vbInformation
End If
End If
'If there's not enough room on the target drive display a warning.
If Not DumpFitsOnTargetDrive Then
If g_RequiredPageFileMB <> 0 Then
MsgBox "Once the PageFile is expanded the target drive for your dump file does not have enough free space to save the selected dump type." & VbCrLf & _
VbCrLf & "Estimated memory dump size: " & g_intDumpRequiredMB & " MB" & VbCrLf & "Drive Free Space after PF Expansion: " & (ConvertBytes(g_DumpTargetDriveFree,"MB")-g_RequiredPageFileMB) & " MB" & _
VbCrLf & VbCrLf & "You may need to change the target location for the dump or free up some space.",vbOKOnly+vbExclamation,"Disk Space Warning..."
Else
MsgBox "The target drive for your dump file does not have enough free space to save the selected dump type." & VbCrLf & _
VbCrLf & "Estimated dump size: " & g_intDumpRequiredMB & " MB" & VbCrLf & "Target Drive Free Space: " & ConvertBytes(g_DumpTargetDriveFree,"MB") & " MB" & _
VbCrLf & VbCrLf & "You may need to change the target location for the dump or free up some space.",vbOKOnly+vbExclamation,,"Disk Space Warning..."
End If
End If
document.form1.selDumpType.value = intDumpType
document.form1.chkAutoReboot.checked = True
document.form1.chkdumpoverwrite.checked = True
document.form1.chki8042dump.checked = True
document.form1.chknmidump.checked = True
g_LogEvent = 1
SaveSettings()
End Sub
'*******************************************************
' Saves settings and checks for configuration problems
'*******************************************************
Sub SaveSettings()
g_intDumpType = document.form1.selDumpType.value
If document.form1.chkAutoReboot.checked Then
g_dumpAutoReboot = 1
Else
g_dumpAutoReboot = 0
End If
If document.form1.chkdumpoverwrite.checked Then
g_dumpOverwrite = 1
Else
g_dumpOverwrite = 0
End If
If document.form1.chki8042dump.checked Then
g_CtrlScrolli8042 = 1
Else
g_CtrlScrolli8042 = 0
End If
If document.form1.chknmidump.checked Then
g_NMIDump = 1
Else
g_NMIDump = 0
End If
SetDumpTargetDrive()
SetCrashDumpInfo g_strComputer, g_intDumpType, g_dumpAutoReboot, g_dumpOverwrite, g_dumpFileLocation, g_miniDumpLocation, LogEvent, g_CtrlScrolli8042, g_NMIDump, g_DedicatedDumpFile, g_DedicatedDumpFileLocation
MsgBox "Your Settings have been saved." & VbCrLf & VbCrLf & "The target system must be rebooted before" & VbCrLf & "any changes will take effect.",vbOKOnly+vbInformation,"Saved Dump Settings..."
Call Main()
End Sub
'***************************************************
' Modifies HTML elements on the page to display data
' Also contains extra data that has been remarked
' out for the final version
'***************************************************
Sub OutputHTML()
Dim strHTML
strHTML = "<table class=tblWinDialog border=1 name=table1><Caption>Memory Dump Configuration</caption>"
If Not g_HasAdminPerms Then
strHTML = strHTML & "<th align=center colspan=3><font color=darkred>WARNING: You do not have admin permissions on the target. Settings will not be saved!<br>Please run this program with an account that has a full administrative token for the target system.</font>"
strHTML = strHTML & "<br><input type=button value='Elevate this HTA' onClick=ElevateThisHTA()></th>"
End If
strHTML = strHTML & "<tr><td style='border-right: none; border-collapse: collapse'> Computername:</td><td style='border-right:none;'> <strong> " & g_strComputer & "</strong></td><td style='border-left:none;' align=right><input type=button value='Change' name=cmdSetComputer onclick=GetNewComputerName()> </td></tr>"
strHTML = strHTML & TableRow("Operating System:</td><td colspan=2> " & g_strOSCaption)
strHTML = strHTML & TableRow("OS Architecture:</td><td colspan=2> " & g_strOSArch)
'strHTML = strHTML & TableRow("Service Pack:</td><td colspan=2> Service Pack " & g_strServicePackMajorVersion)
'strHTML = strHTML & TableRow("OS Version:</td><td colspan=2> " & g_strOSVersion)
'strHTML = strHTML & TableRow("Windows Directory:</td><td colspan=2> " & g_strSystemRoot)
'strHTML = strHTML & TableRow("System Drive:</td><td colspan=2> " & g_strSystemDrive)
strHTML = strHTML & TableRow("Total Physical Memory:</td><td colspan=2> " & g_intMemTotal & " MB")
'strHTML = strHTML & TableRow("Current Memory Visible to System:</td><td colspan=2> " & g_intMemVisible & "MB")
'strHTML = strHTML & TableRow("PAE Status:</td><td colspan=2> " & g_isPAEEnabled)
strHTML = strHTML & TableRow("System Drive Page File:</td><td colspan=2> " & g_pfName)
strHTML = strHTML & TableRow("Page File Initial Size:</td><td colspan=2> " & g_pfInitialSize)
'strHTML = strHTML & TableRow("Pagefile Peak Usage:</td><td colspan=2> " & g_pfPeakUsage)
strHTML = strHTML & TableRow("Memory Dump Type:</td><td colspan=2> <select size=1 name=selDumpType onChange=''>" & _
"<option name=full value=1> COMPLETE </option><option value=2> KERNEL ONLY </option><option value=3> SMALL </option><option value=0> NONE </option></select>")
strHTML = strHTML & TableRow("AutoReboot after Memory Dump:</td><td colspan=2> <input type='checkbox' name='chkAutoreboot' " & g_autorebootChecked &"> " & g_dumpAutoReboot)
strHTML = strHTML & TableRow("Overwrite previous dump file:</td><td colspan=2> <input type='checkbox' name='chkdumpoverwrite' " & g_dumpoverwriteChecked &"> " & g_dumpOverwrite)
'strHTML = strHTML & TableRow("Log Event:</td><td colspan=2> " & LogEvent)