-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launch-Toolbox.ps1
5903 lines (5795 loc) · 353 KB
/
Launch-Toolbox.ps1
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
#requires -version 2
<#
.SYNOPSIS
Generates a visual list of useful scripts and programs making them available in one place
.DESCRIPTION
This script generates a customisable list of tools and programs for ease of access and usability.
Requires PowerShell v2 and write access to the local computers registry
.NOTES
Name : Toolbox
Version : 1.0
DateCreated : 2017-06-15
Author : ITMonkey78 (ITMonkey78@gmail.com)
Purpose/Change : Original Code by IntrntPirate (https://github.com/IntrntPirate/Toolbox)
Modified from baseline 30,000 lines of code over multiple PowerShell Studio files
This version is a single file and (currently) less than 6000 lines of code.
Converted some functions to work with PS ver2 for backward compatibility
Added Registry Import/Export functions
Rewrote Debugging and Log functions
Fixed some other stuff that was broken in IntrntPirates original release
Allow Powershell scripts added to Toolbox to be ran with Powershell instead of opened in notepad by default
#>
#----------------------------------------------
# region Declare Globals
#----------------------------------------------
#defining some app variables
$Global:AppShortName = "Toolbox"
$Global:AppLongName = "Powershell App Toolbox"
$Global:CurrentRunningVersion=1.0
$Global:Config_NetSourceDir="C:\Tools\Toolbox\"
$Global:Config_RootLogLocation="C:\Tools\Toolbox\Logs\"
$Global:Config_RootHKCU="HKCU:\SOFTWARE\Toolbox\"
$Global:Config_AlwaysOnTop=$false
$Global:Config_DebugMode=$false
$Global:Config_EnableLogging=$true
$Global:Config_ShowNewStuff=$true
$Global:Config_SnapViewMode=$false
$Global:Config_ShowToolTip=$false
$Global:Config_UseLastKnownSizeLocation=$false
#endregion Declare Globals
#----------------------------------------------
#region Import Assemblies
#----------------------------------------------
[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
[void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
[void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[void][reflection.assembly]::Load('System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[System.Windows.Forms.Application]::EnableVisualStyles()
#endregion Import Assemblies
#region Source: MainForm
function Show-MainForm
{
#----------------------------------------------
#region Generated Form Objects
#----------------------------------------------
$MainForm = New-Object 'System.Windows.Forms.Form'
$listview1 = New-Object 'System.Windows.Forms.ListView'
$menustrip1 = New-Object 'System.Windows.Forms.MenuStrip'
$fileToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$configToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$helpToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$importToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$exportToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$updateToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$exitToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$showConfigToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$reloadConfigToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$logToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$showToolTipsToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$tooltip = New-Object 'System.Windows.Forms.ToolTip'
$debugModeToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$setDebugModeToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$contextmenu1 = New-Object 'System.Windows.Forms.ContextMenuStrip'
$openToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$uninstallToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$createShortcutToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$timerBringtoFront = New-Object 'System.Windows.Forms.Timer'
$timerShowNewStuff = New-Object 'System.Windows.Forms.Timer'
$removeCustomToolToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$addCustomToolToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$setSnapViewToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$alwaysOnTopToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$rememberSizeLocationToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$timerAppLaunched = New-Object 'System.Windows.Forms.Timer'
$editCustomToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$newCustomToolToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
#endregion Generated Form Objects
#establishing some internal app functions
function Log
{
param (
[string]$text,
[string]$component = "N/A",
[int]$type,
$date = (Get-Date)
)
switch ($type)
{
1 { $typeS = "Info" }
2 { $typeS = "Warning" }
3 { $typeS = "Error" }
4 { $typeS = "Verbose" }
default { $typeS = "N/A" }
}
If (!(Get-Variable -Name Config_DebugMode))
{
$Config_DebugMode = $true
}
If (!($Config_EnableLogging))
{
$Config_EnableLogging = $true
}
If ($Config_EnableLogging -eq $true)
{
Do
{
Try
{
$ErrorActionPreference = 'Stop'
$toLog = "<![LOG[$($typeS + " : " + $text)]LOG]!><time=`"$(Get-Date $date -Format "HH:mm:ss.ffffff")`" date=`"$(Get-Date $date -Format "MM-dd-yyyy")`" component=`"$AppShortName : $Component`" context=`"`" type=`"$type`" thread=`"$PID`" file=`"$($env:COMPUTERNAME)`">"
Out-File -InputObject $toLog -Append -NoClobber -Encoding Default -FilePath $Config_LogPath
$Continue = $true
}
Catch
{
Start-Sleep -Seconds 1
}
Finally
{
$count++
}
}
Until (($Continue -eq $true) -or ($count -eq 5))
#only add the verbose text if DebugMode is $true
If ($typeS -eq "Verbose") {
If ($Config_DebugMode) {
$Global:Log += $text
}
}
else {
$Global:Log += $text
}
}
}
function BringTo-Focus
{
param ([int]$processID)
add-type -AssemblyName microsoft.VisualBasic
[Microsoft.VisualBasic.Interaction]::AppActivate($processID)
}
function RunAsAdmin-Check
{
(New-Object System.Security.Principal.WindowsPrincipal(([System.Security.Principal.WindowsIdentity]::GetCurrent()))).IsInRole(([System.Security.Principal.WindowsBuiltInRole]::Administrator))
}
function Build-Config
{
param ($Config2Load)
Log -text "Building config: $Config2Load" -component "MainForm_Load-Config" -type 1
If (!(Test-Path "$Config_RootHKCU$Config2Load\"))
{
$Error.Clear()
New-Item "$Config_RootHKCU$Config2Load\" -force
If ($Error) { Log -text "$Error" -component "MainForm_Build-Config" -type 4 }
}
If (!($LoadedConfigTable))
{
$Global:LoadedConfigTable = New-Object System.Data.DataTable
$Global:LoadedConfigTable.Columns.Add((New-Object System.Data.DataColumn "Config", ([string])))
$Global:LoadedConfigTable.Columns.Add((New-Object System.Data.DataColumn "Attribute", ([string])))
$Global:LoadedConfigTable.Columns.Add((New-Object System.Data.DataColumn "Value", ([string])))
$Global:LoadedConfigTable.Columns.Add((New-Object System.Data.DataColumn "User Customized", ([string])))
}
Get-Variable -Scope Global -Name "Config_*" | ForEach-Object {
$Obj = $_.Name.Replace("Config_","")
If (($LoadedConfigTable | Where-Object { $_."Attribute" -eq $obj }))
{
$eci = $true
}
Else
{
$eci = $false
}
If (((Get-ItemProperty "$Config_RootHKCU$Config2Load\")."$Obj"))
{
Log -text "Config item `"$Obj`" is user personalized." -component "MainForm_Build-Config" -type 1
$Val = (Get-ItemProperty "$Config_RootHKCU$Config2Load\")."$Obj"
$ciuc = $true
}
Else
{
$Val = $_.Value
$ciuc = $false
}
If ($Val -eq "true") { $Val = $true }
elseif ($Val -eq "false") { $Val = $false }
If (!(Get-Variable -Scope Global -Name "Config_$Obj"))
{
New-Variable -Scope Global -Name "Config_$Obj" -Value $Val
}
Else
{
Set-Variable -Scope Global -Name "Config_$Obj" -Value $Val
}
If ($eci -eq $true)
{
($Global:LoadedConfigTable | Where-Object { $_.Attribute -eq $obj }).'Config' = $Config2Load
($Global:LoadedConfigTable | Where-Object { $_.Attribute -eq $obj }).'Value' = $Val
If ($ciuc -eq $true)
{
($Global:LoadedConfigTable | Where-Object { $_.Attribute -eq $obj }).'User Customized' = "True"
}
elseif ($ciuc -eq $false)
{
($Global:LoadedConfigTable | Where-Object { $_.Attribute -eq $obj }).'User Customized' = "False"
}
}
elseif ($eci -eq $false)
{
$row = $Global:LoadedConfigTable.NewRow()
$row."Config" = $Config2Load
$row."Attribute" = $obj
$row."Value" = $Val
If ($ciuc -eq $true)
{
$row."User Customized" = "True"
}
elseif ($ciuc -eq $false)
{
$row."User Customized" = "False"
}
$Global:LoadedConfigTable.Rows.Add($row)
}
}
}
function Update-LoadedConfigTable
{
Log -text "Updating Loaded Config Table..." -component "MainForm_Update-LoadedConfigTable" -type 4
foreach ($row in ($LoadedConfigTable))
{
Log -text "Processing setting for config $($row.Config), setting $($row.Attribute)..." -component "MainForm_Update-LoadedConfigTable" -type 4
If (!($row.Value -eq "$((Get-Variable -Scope Global -Name "Config_$($row.Attribute)").Value)"))
{
Log -text "Updating entry..." -component "MainForm_Update-LoadedConfigTable" -type 4
($LoadedConfigTable.Rows | Where-Object { $_.Config -eq "$($row.Config)" -and $_.Attribute -eq "$($row.Attribute)" }).value = "$((Get-Variable -Scope Global -Name "Config_$($row.Attribute)").Value)"
}
}
Log -text "Finished updating Loaded Config Table." -component "MainForm_Update-LoadedConfigTable" -type 4
}
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.DereferenceLinks = $false
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "CSV files (*.csv)| *.csv|All files (*.*)| *.*"
If ([threading.thread]::CurrentThread.GetApartmentState() -ne 'STA') { $OpenFileDialog.ShowHelp = $true } #workaround for MTA issue not displaying dialog
If ($OpenFileDialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { $return = ($OpenFileDialog.filename) }
Try { $OpenFileDialog.Dispose() } Catch {}
Return $return
}
function MainForm-Startup
{
param (
[bool]$RunAdminCheck,
[bool]$silent = $false,
[bool]$OverRideArch = $false
)
$script:currentuser = $env:username
$Global:Config_LogPath = "$Config_RootLogLocation" + "$currentuser.log"
If (!(Test-Path $Config_RootLogLocation))
{
Log -text "Creating the root log location..." -component "MainForm_MainForm-Startup" -type 1
$Error.Clear()
New-Item -Path $Config_RootLogLocation -ItemType directory -Force
If ($Error)
{
Log -text "An error occured while attempting to create the root log location." -component "MainForm_MainForm-Startup" -type 3
Log -text "$Error" -component "MainForm_MainForm-Startup" -type 3
Log -text "" -component "MainForm_MainForm-Startup" -type 3
}
}
If (!(Test-Path $Config_RootHKCU))
{
Log -text "Creating first run registry entries..." -component "MainForm_MainForm-Startup" -type 1
$Error.Clear()
New-Item "$Config_RootHKCU$AppShortName" -Force
If ($Error)
{
Log -text "An error occured while attempting to create the registry tree." -component "MainForm_MainForm-Startup" -type 3
Log -text "$Error" -component "MainForm_MainForm-Startup" -type 3
Log -text "" -component "MainForm_MainForm-Startup" -type 3
}
}
$Global:Log = @()
Log -text "$AppLongName starting..." -component "MainForm_MainForm-Startup" -type 1
Log -text "User: $currentuser" -component "MainForm_MainForm-Startup" -type 1
$Global:CurrentExecutable = (Get-WmiObject Win32_Process | Where-Object { $_.handle -eq $pid }).ExecutablePath
Log -text "Executable Path: $CurrentExecutable" -component "MainForm_MainForm-Startup" -type 1
$Global:CurrentRunningPath = (Get-Item $CurrentExecutable).directory.fullname
Log -text "Running Path: $CurrentRunningPath" -component "MainForm_MainForm-Startup" -type 1
$Global:CurrentPSVersion = (Get-Item $CurrentExecutable).VersionInfo.ProductVersion
Log -text "Running Version: $CurrentPSVersion" -component "MainForm_MainForm-Startup" -type 1
$Global:RootDirectory = (Get-Item $CurrentExecutable).Directory.Parent.FullName
Log -text "Root Directory: $RootDirectory" -component "MainForm_MainForm-Startup" -type 1
Log -text "" -component "MainForm_MainForm-Startup" -type 1
Log -text "RunAdminCheck: $RunAdminCheck" -component "MainForm_MainForm-Startup" -type 1
Log -text "Silent: $silent" -component "MainForm_MainForm-Startup" -type 1
# Log -text "OverRideArch: $OverRideArch" -component "MainForm_MainForm-Startup" -type 1
Log -text "UpdateCheckVer: $CurrentRunningVersion" -component "MainForm_MainForm-Startup" -type 1
Check-ForUpdate -RunManualCheck $false
Check-LastRanVersion
Build-Config -Config2Load $AppShortName
If ($RunAdminCheck -eq $true)
{
Log -text "This app requires admin rights to run. Performing admin rights detection..." -component "MainForm_MainForm-Startup" -type 1
If (RunAsAdmin-Check -eq $true)
{
Log -text "Admin rights detected." -component "MainForm_MainForm-Startup" -type 1
return, $true
}
else
{
Log -text "Tool is not running as an admin." -component "MainForm_MainForm-Startup" -type 3
If (!($silent -eq $true))
{
Message-Box -text "You're not running $AppLongName as an Administrator. You need to re-launch it as an Administrator." -title "Whoa there..."
}
return, $false
}
}
Else
{
return, $true
}
}
function Get-LockedConfigItems
{
return, @('EnableLogging', 'CoreFunctions', 'AboutInfoImg', 'ProdVersion', 'OptionalVersion', 'UniUpdateProdVersion', 'UniUpdateNetRoot', 'RootHKCU', 'NetSourceDir')
}
function Message-Box
{
param (
$text,
$title,
$boxtype = "0"
)
BringTo-Focus -processID $pid
[System.Windows.Forms.MessageBox]::Show("$text", "$title", $boxtype)
}
function Check-ForUpdate
{
param ([bool]$RunManualCheck)
$match = Select-String "$Config_NetSourceDir$AppShortName\Toolbox.ps1" -pattern '$Global:CurrentRunningVersion=' -SimpleMatch
$CurrentSourceVersion = $Match.line.Split("=")[1]
If ($CurrentSourceVersion -gt $CurrentRunningVersion)
{
Message-Box -title "Version Check" -text "New version available. Updating script..."
Copy-Item "$Config_NetSourceDir$AppShortName\Toolbox.ps1" -Destination $PSScriptRoot -force
#reload the script and exit the currently running version
Invoke-Expression -Command $PSCommandPath
[Environment]::Exit(1)
}
Else
{
if ($RunManualCheck -eq $true) { Message-Box -title "No New Version Available" -text "You are using the most recent version." }
}
}
function Check-LastRanVersion
{
If (((Get-ItemProperty "$Config_RootHKCU$AppShortName\").LastRanVer))
{
$Global:LRV = ((Get-ItemProperty "$Config_RootHKCU$AppShortName\").LastRanVer)
If ($CurrentRunningVersion -gt $LRV)
{
$Global:ShowVersionUpdates = $true
}
Else
{
$Global:ShowVersionUpdates = $false
}
$Error.Clear()
Set-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name LastRanVer -Value "$CurrentRunningVersion"
If ($Error)
{
Log -text "An error occured while attempting to update the LastRanVer attribute for the tool in the registry." -component "MainForm_Check-LastRanVersion" -type 3
Log -text "$Error" -component "MainForm_Check-LastRanVersion" -type 3
Log -text "" -component "MainForm_Check-LastRanVersion" -type 3
Message-Box -title "ERROR" -text "An error occured. See log for details."
}
Else
{
Log -text "Successfully updated the LastRanVer attribute." -component "MainForm_Check-LastRanVersion" -type 4
}
}
Else
{
$Error.Clear()
New-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name LastRanVer -PropertyType String -Value "$CurrentRunningVersion" -force
If ($Error)
{
Log -text "An error occured while attempting to create the LastRanVer attribute for the tool in the registry." -component "MainForm_Check-LastRanVersion" -type 3
Log -text "$Error" -component "MainForm_Check-LastRanVersion" -type 3
Log -text "" -component "MainForm_Check-LastRanVersion" -type 3
Message-Box -title "ERROR" -text "An error occured. See log for details."
}
Else
{
Log -text "Successfully created the LastRanVer attribute" -component "MainForm_Check-LastRanVersion" -type 4
}
}
}
function Toggle-DebugMode
{
If ($Config_DebugMode -eq $true)
{
If (((Get-ItemProperty "$Config_RootHKCU$AppShortName\").DebugMode))
{
$Error.Clear()
Set-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name DebugMode -Value "False"
If ($Error)
{
Log -text "An error occured while trying to disable Debug Mode." -component "MainForm_Toggle-DebugMode" -type 3
Log -text "$Error" -component "MainForm_Toggle-DebugMode" -type 3
Log -text "" -component "MainForm_Toggle-DebugMode" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to disable Debug Mode.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Debug Mode Disabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_DebugMode = $false
return, $true
}
}
Else
{
$Error.Clear()
New-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name DebugMode -PropertyType String -Value "False"
If ($Error)
{
Log -text "An error occured while trying to disable Debug Mode." -component "MainForm_Toggle-DebugMode" -type 3
Log -text "$Error" -component "MainForm_Toggle-DebugMode" -type 3
Log -text "" -component "MainForm_Toggle-DebugMode" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to disable Debug Mode.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Debug Mode Disabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_DebugMode = $false
return, $true
}
}
}
elseif ($Config_DebugMode -eq $false)
{
If (((Get-ItemProperty "$Config_RootHKCU$AppShortName\").DebugMode))
{
$Error.Clear()
Set-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name DebugMode -Value "True"
If ($Error)
{
Log -text "An error occured while trying to enable Debug Mode." -component "MainForm_Toggle-DebugMode" -type 3
Log -text "$Error" -component "MainForm_Toggle-DebugMode" -type 3
Log -text "" -component "MainForm_Toggle-DebugMode" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to enable Debug Mode.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Debug Mode Enabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_DebugMode = $true
return, $true
}
}
Else
{
$Error.Clear()
New-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name DebugMode -PropertyType String -Value "True"
If ($Error)
{
Log -text "An error occured while trying to enable Debug Mode." -component "MainForm_Toggle-DebugMode" -type 3
Log -text "$Error" -component "MainForm_Toggle-DebugMode" -type 3
Log -text "" -component "MainForm_Toggle-DebugMode" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to enable Debug Mode.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Debug Mode Enabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_DebugMode = $true
return, $true
}
}
}
}
function Toggle-ToolTips
{
If ($Config_ShowToolTip -eq $false)
{
#enable, set reg key to 0
If (((Get-ItemProperty "$Config_RootHKCU$AppShortName\").ShowToolTip))
{
$Error.Clear()
Set-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name ShowToolTip -Value "True"
If ($Error)
{
Log -text "An error occured while trying to enable Tool Tips." -component "MainForm_Toggle-ToolTips" -type 3
Log -text "$Error" -component "MainForm_Toggle-ToolTips" -type 3
Log -text "" -component "MainForm_Toggle-ToolTips" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to enable Tool Tips.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Tool Tips Enabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_ShowTooltip = $true
return, $true
}
}
Else
{
$Error.Clear()
New-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name ShowToolTip -PropertyType String -Value "True"
If ($Error)
{
Log -text "An error occured while trying to enable Tool Tips." -component "MainForm_Toggle-ToolTips" -type 3
Log -text "$Error" -component "MainForm_Toggle-ToolTips" -type 3
Log -text "" -component "MainForm_Toggle-ToolTips" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to enable Tool Tips.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Tool Tips Enabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_ShowTooltip = $true
return, $true
}
}
}
elseif ($Config_ShowTooltip -eq $true)
{
#disable, set reg key to 1
If (((Get-ItemProperty "$Config_RootHKCU$AppShortName\").ShowToolTip))
{
$Error.Clear()
Set-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name ShowToolTip -Value "False"
If ($Error)
{
Log -text "An error occured while trying to disable Tool Tips." -component "MainForm_Toggle-ToolTips" -type 3
Log -text "$Error" -component "MainForm_Toggle-ToolTips" -type 3
Log -text "" -component "MainForm_Toggle-ToolTips" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to disable Tool Tips.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Tool Tips Disabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_ShowTooltip = $false
return, $true
}
}
Else
{
$Error.Clear()
New-ItemProperty -Path "$Config_RootHKCU$AppShortName" -Name ShowToolTip -PropertyType String -Value "False"
If ($Error)
{
Log -text "An error occured while trying to disable Tool Tips." -component "MainForm_Toggle-ToolTips" -type 3
Log -text "$Error" -component "MainForm_Toggle-ToolTips" -type 3
Log -text "" -component "MainForm_Toggle-ToolTips" -type 3
Show-MessageBox -title "ERROR" -text "An error occured while attempting to disable Tool Tips.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
return, $false
}
Else
{
Show-MessageBox -title "" -text "Tool Tips Disabled" -autoclose 5 -boxtype 1 -image 2 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
$Global:Config_ShowTooltip = $false
return, $true
}
}
}
}
function Check-ScreenLocation
{
param (
[int]$x,
[int]$y,
[int]$formHeight,
[int]$formWidth
)
Log -text "Checking Screen Location..." -component "MainForm_Check-ScreenLocation" -type 4
If ($x -lt 0)
{
Log -text "The location point for X is less than 0. Setting X to 0..." -component "MainForm_Check-ScreenLocation" -type 4
$x = 0
}
If ($y -lt 0)
{
Log -text "The location point for Y is less than 0. Setting Y to 0..." -component "MainForm_Check-ScreenLocation" -type 4
$y = 0
}
Log -text "Gathering screen statistics..." -component "MainForm_Check-ScreenLocation" -type 4
$AllScreens = [System.Windows.Forms.Screen]::AllScreens
Log -text "Processing screens..." -component "MainForm_Check-ScreenLocation" -type 4
foreach ($Screen in $AllScreens)
{
Log -text "Processing screen: $($Screen.DeviceName)" -component "MainForm_Check-ScreenLocation" -type 4
$WL = $Screen.WorkingArea.X #Width Low Range
$WH = $Screen.WorkingArea.X + $Screen.WorkingArea.Width #Width High Range
$HL = $Screen.WorkingArea.Y #Heigh Low Range
$HH = $Screen.WorkingArea.Y + $Screen.WorkingArea.Height #Heigh High Range
If ((($x -ge $WL) -and ($x -le $WH)) -and (($y -ge $HL) -and ($y -le $HH)))
{
Log -text "The current location is primarily on $($Screen.DeviceName)." -component "MainForm_Check-ScreenLocation" -type 4
$WorkingScreen = $Screen
}
Else
{
Log -text "It does not appear that the location is on this screen." -component "MainForm_Check-ScreenLocation" -type 4
}
}
If (!($WorkingScreen))
{
Log -text "The location could not be found on a screen! Returning likely bad location points anyways..." -component "MainForm_Check-ScreenLocation" -type 1
$obj = New-Object PSObject
Add-Member -InputObject $obj -MemberType NoteProperty -Name X -Value $x
Add-Member -InputObject $obj -MemberType NoteProperty -Name Y -Value $y
return, $obj
}
Else
{
Log -text "Checking to make sure that the form isn't getting cut off..." -component "MainForm_Check-ScreenLocation" -type 4
$xx = $x + $formWidth
$ScreenMaxX = $WorkingScreen.WorkingArea.X + $WorkingScreen.WorkingArea.Width
If ($xx -le $ScreenMaxX)
{
Log -text "The X axis appears to not be getting cut off." -component "MainForm_Check-ScreenLocation" -type 4
}
Else
{
Log -text "The X axis appears to be getting cut off. Attempting to adjust..." -component "MainForm_Check-ScreenLocation" -type 4
$x = $x - ($xx - $ScreenMaxX)
}
$yy = $y + $formHeight
$ScreenMaxY = $WorkingScreen.WorkingArea.Y + $WorkingScreen.WorkingArea.Height
If ($yy -le $ScreenMaxY)
{
Log -text "The Y axis appears to not be getting cut off." -component "MainForm_Check-ScreenLocation" -type 4
}
Else
{
Log -text "The Y axis appears to be getting cut off. Attempting to adjust..." -component "MainForm_Check-ScreenLocation" -type 4
$y = $y - ($yy - $ScreenMaxY)
}
$obj = New-Object PSObject
Add-Member -InputObject $obj -MemberType NoteProperty -Name X -Value $x
Add-Member -InputObject $obj -MemberType NoteProperty -Name Y -Value $y
return, $obj
}
}
function Initial-Load
{
Log -text "Running Initial-Load..." -Component "MainForm_Initial-Load" -Type 4
If ($Config_DebugMode -eq $true)
{
$setDebugModeToolStripMenuItem.Text = "Disable"
}
Else
{
$setDebugModeToolStripMenuItem.Text = "Enable"
}
If ($Config_ShowToolTip -eq $true)
{
$showToolTipsToolStripMenuItem.Text = "Hide Tool Tips"
$listview1.ShowItemToolTips = $true
}
Else
{
$showToolTipsToolStripMenuItem.Text = "Show Tool Tips"
$listview1.ShowItemToolTips = $false
}
Load-Apps
Populate-ListView
Set-SnapViewMode
Toggle-AlwaysOnTop
Toggle-RememberSizeLocation
If ($Config_UseLastKnownSizeLocation -eq $true)
{
If (((Get-ItemProperty -Path "$Config_RootHKCU$AppShortName\").LastKnownLocation) -and ($Config_UseLastKnownSizeLocation -eq $true))
{
Log -text "Last known location record exists and is set to be used. Using last known location..." -Component "MainForm_Initial-Load" -Type 4
$Location = (Get-ItemProperty -Path "$Config_RootHKCU$AppShortName\").LastKnownLocation
$FoundLocation = $true
}
If (((Get-ItemProperty -Path "$Config_RootHKCU$AppShortName\").LastKnownSize) -and ($Config_UseLastKnownSizeLocation -eq $true))
{
Log -text "Last known size record exists and is set to be used. Using last known size..." -Component "MainForm_Initial-Load" -Type 4
$Size = (Get-ItemProperty -Path "$Config_RootHKCU$AppShortName\").LastKnownSize
$FoundSize = $true
}
If (($FoundLocation -eq $true) -and ($FoundSize -eq $true))
{
Log -text "Found both an existing location and size. Checking to ensure the location is valid..." -Component "MainForm_Initial-Load" -Type 4
If (([System.Windows.Forms.Screen]::AllScreens | select -expandproperty workingarea).IntersectsWith(([System.Drawing.Rectangle]::FromLTRB([int]$Location.Split('_')[0], [int]$Location.Split('_')[1], [int]$Size.Split('_')[1], [int]$Size.Split('_')[0]))))
{
Log -text "All screen working area check identified that the saved form location/size is within the boundary of the screens on the system. Restoring last known location and size..." -Component "MainForm_Initial-Load" -Type 4
$MainForm.Location = (New-Object System.Drawing.Size([int]$Location.Split('_')[0], [int]$Location.Split('_')[1]))
$MainForm.Size = (New-Object System.Drawing.Size([int]$Size.Split('_')[1], [int]$Size.Split('_')[0]))
}
Else
{
Log -text "A screen working area check determined that the form is off screen. Not restoring the last known location and size." -Component "MainForm_Initial-Load" -Type 1
}
}
Else
{
Log -text "Failed to locate an existing location or size." -Component "MainForm_Initial-Load" -Type 3
}
}
$Global:Original_Size="$($MainForm.Size.Height)_$($MainForm.Size.Width)"
}
function Load-Apps
{
Log -text "Creating EXE Table..." -Component "MainForm_Load-Apps" -Type 4
$Script:EXETable = New-Object System.Data.DataTable
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "Name", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "LocalPath", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "SourcePath", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "Description", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "AutoInstall", ([bool])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "IsInstalled", ([bool])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "ImageIndex", ([int])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "Local", ([bool])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "CustomAdd", ([bool])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "CustomAddRegPath", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "CustomAddArgs", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "IconPath", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "AppN", ([string])))
$Script:EXETable.Columns.Add((New-Object System.Data.DataColumn "ArchSupp", ([string])))
Log -text "Creating ImageList..." -Component "MainForm_Load-Apps" -Type 4
$ImageIndexNum = 0
$Script:ImageList = New-Object System.Windows.Forms.ImageList
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 32
$System_Drawing_Size.Height = 32
$Script:ImageList.ImageSize = $System_Drawing_Size
Log -text "Checking to see if there are any custom tools to add..." -Component "MainForm_Load-Apps" -Type 4
If ((Test-Path -Path "$Config_RootHKCU$AppShortName\CustomAdd\"))
{
Log -text "Processing custom tools..." -Component "MainForm_Load-Apps" -Type 4
foreach ($CustomAdd in (Get-ChildItem -Path "$Config_RootHKCU$AppShortName\CustomAdd\"))
{
Log -text "Processing Custom Add tool `"$($CustomAdd.Name)`"" -Component "MainForm_Load-Apps" -Type 4
$Error.Clear()
$Properties = Get-ItemProperty -Path $CustomAdd.Name.Replace('HKEY_CURRENT_USER', 'HKCU:')
If ($Error)
{
Log -text "An error occured while attempting to obtain the properties of the custom tool." -Component "MainForm_Load-Apps" -Type 3
Log -text "$Error" -Component "MainForm_Load-Apps" -Type 3
Log -text "" -Component "MainForm_Load-Apps" -Type 3
Show-MessageBox -title "ERROR" -text "An error was encountered while processing the custom tool: $($CustomAdd.Name).`n`nIt will not be added. See log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
}
Else
{
Log -text "Successfully obtained the properties. Processing add..." -Component "MainForm_Load-Apps" -Type 4
$row = $EXETable.NewRow()
$row."CustomAddRegPath" = $CustomAdd.Name.Replace('HKEY_CURRENT_USER', 'HKCU:')
$row."Name" = $Properties.Name
$row."Description" = $Properties.Description
$row."LocalPath" = $Properties.LocalPath
$row."AutoInstall" = $false
$row."IsInstalled" = $true
$row."CustomAdd" = $true
If (($Properties.Args))
{
$row."CustomAddArgs" = $Properties.Args
}
Log -text "Extracting icon image..." -Component "MainForm_Load-Apps" -Type 4
$filename = (Get-ItemProperty -Path $($row."LocalPath")).BaseName
Log -text "FileName: $filename" -Component "MainForm_Load-Apps" -Type 4
If (($Properties.IconPath))
{
Log -text "Custom icon path provided." -Component "MainForm_Load-Apps" -Type 4
$Error.Clear()
$ImageList.Images.Add("$filename", ([Drawing.Icon]::ExtractAssociatedIcon("$($Properties.IconPath)").ToBitmap()))
If ($Error)
{
Log -text "An error occured while attempting to extract the icon and add it to the ImageList." -Component "MainForm_Load-Apps" -Type 3
Log -text "$Error" -Component "MainForm_Load-Apps" -Type 3
Log -text "" -Component "MainForm_Load-Apps" -Type 3
}
Else
{
$row."ImageIndex" = $ImageIndexNum
$ImageIndexNum++
}
$row."IconPath" = "$($Properties.IconPath)"
}
Else
{
$Error.Clear()
$ImageList.Images.Add("$filename", ([Drawing.Icon]::ExtractAssociatedIcon("$($row."LocalPath")").ToBitmap()))
If ($Error)
{
Log -text "An error occured while attempting to extract the icon and add it to the ImageList." -Component "MainForm_Load-Apps" -Type 3
Log -text "$Error" -Component "MainForm_Load-Apps" -Type 3
Log -text "" -Component "MainForm_Load-Apps" -Type 3
}
Else
{
$row."ImageIndex" = $ImageIndexNum
$ImageIndexNum++
}
$row."IconPath" = "$($row."LocalPath")"
}
Log -text "Finished with adding custom tool." -Component "MainForm_Load-Apps" -Type 4
$script:EXETable.Rows.Add($row)
}
}
}
Else
{
Log -text "No custom tools found." -Component "MainForm_Load-Apps" -Type 4
}
}
function Populate-ListView
{
$listview1.LargeImageList = $ImageList
Log -text "Clearing listview..." -Component "MainForm_Populate-ListView" -Type 4
$listview1.Items.Clear()
$itemNum = 0
Log -text "Populating listview..." -Component "MainForm_Populate-ListView" -Type 4
foreach ($Tool in ($EXETable | Where-Object { $_.IsInstalled -eq $true }))
{
Log -text "Processing tool: $($Tool.Name)" -Component "MainForm_Populate-ListView" -Type 4
$listviewItem = New-Object System.Windows.Forms.ListViewItem
$listviewItem.Name = $Tool.Name
$listviewItem.Text = $Tool.Name
$listviewItem.Tag = $Tool.LocalPath
$listviewItem.ImageIndex = $Tool.ImageIndex
$listviewItem.ToolTipText = $Tool.Description
$listview1.Items.Add($listviewItem)
}
}
function Launch-App
{
Log -text "Processing Launch-App..." -Component "MainForm_Launch-App" -Type 4
If (($EXETable | Where-Object { $_.Name -eq "$($listview1.SelectedItems[0].Name)" }).CustomAddArgs.GetType().Name -eq "DBNull")
{
If ((ExecutionSecurityCheck -ExecutedFile "$($listview1.SelectedItems[0].Tag)") -eq $true)
{
Log -text "Launching tool without Args..." -Component "MainForm_Launch-App" -Type 4
$Error.Clear()
Start-Process -FilePath "$($listview1.SelectedItems[0].Tag)"
If ($Error)
{
Log -text "An error occured while attempting to launch the process." -Component "MainForm_Launch-App" -Type 3
Log -text "$Error" -Component "MainForm_Launch-App" -Type 3
Log -text "" -Component "MainForm_Launch-App" -Type 3
Show-MessageBox -title "ERROR" -text "An error occured.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
}
}
Else
{
Log -text "Execution Security Check failed. Not launching tool." -Component "MainForm_Launch-App" -Type 3
Show-MessageBox -title "ERROR" -text "The selected tool failed the Execution Security Check and will not be launched." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
}
}
Else
{
If ((ExecutionSecurityCheck -ExecutedFile "$($($listview1.SelectedItems[0].Tag))" -Arguments "$($(($EXETable | Where-Object { $_.Name -eq "$($listview1.SelectedItems[0].Name)" }).CustomAddArgs))") -eq $true)
{
Log -text "Launching tool with Args..." -Component "MainForm_Launch-App" -Type 4
$Error.Clear()
Start-Process -FilePath "$($listview1.SelectedItems[0].Tag)" -ArgumentList "$(($EXETable | Where-Object { $_.Name -eq "$($listview1.SelectedItems[0].Name)" }).CustomAddArgs)"
If ($Error)
{
Log -text "An error occured while attempting to launch the process." -Component "MainForm_Launch-App" -Type 3
Log -text "$Error" -Component "MainForm_Launch-App" -Type 3
Log -text "" -Component "MainForm_Launch-App" -Type 3
Show-MessageBox -title "ERROR" -text "An error occured.`n`nSee log for additional details." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
}
}
Else
{
Log -text "Execution Security Check failed. Not launching tool." -Component "MainForm_Launch-App" -Type 3
Show-MessageBox -title "ERROR" -text "The selected tool failed the Execution Security Check and will not be launched." -boxtype 1 -image 5 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
}
}
}
Function Export-Registry {
push-location HKCU:
$data=@()
#go through each pipelined path
$path = (Get-ChildItem -Path "$Config_RootHKCU" -Recurse)
Foreach ($item in $path) {
$regItem=Get-Item -Path $item
#get property names
$properties = $regItem.Property
if (-not ($properties))
{
#no item properties were found so create a default entry
$value=$Null
$PropertyItem=”(Default)”
$RegType=”String”
#create a custom object for each entry and add it the temporary array
$data+=New-Object -TypeName PSObject -Property @{
“Path”=$item
“Name”=$propertyItem
“Value”=$value
“Type”=$regType
}
}
else
{
#enumerate each property getting its name,value and type
foreach ($property in $properties)
{
$value=$regItem.GetValue($property,$null,”DoNotExpandEnvironmentNames”)
#get the registry value type
$regType=$regItem.GetValueKind($property)
$PropertyItem=$property
#create a custom object for each entry and add it the temporary array
$data+=New-Object -TypeName PSObject -Property @{
“Path”=$item
“Name”=$propertyItem
“Value”=$value
“Type”=$regType
}
} #foreach
} #else
} #close Foreach
#make sure we got something back and export it
if ($data)
{
Log -text "Creating the settings file..." -component "MainForm_Export-Registry" -type 1
$data | Export-CSV -Path "$env:SystemDrive\Users\$env:Username\Desktop\Toolbox_Settings.csv" -noTypeInformation
Show-MessageBox -title "EXPORT" -text "Toolbox_Settings.csv file exported to desktop`n`nThis file can be used to import the same settings to another computer." -boxtype 1 -image 4 -x ($MainForm.Location.X + ($MainForm.Size.Width / 2)) -y ($MainForm.Location.Y + ($MainForm.Size.Height / 2))
}
pop-location
} #end Function
Function Import-Registry{
push-location HKCU:
$path = Get-FileName -initialDirectory $env:SystemDrive
$data = Import-CSV -Path $path
if($data)
{
$data | Foreach
{
#Write the new entries, creating new keys and overwriting any existing.
if (!(Test-Path $_.Path))
{
New-Item -Path (Split-Path -Parent $_.Path) -Name (Split-Path -Leaf $_.Path)
}
New-ItemProperty -Path $_.Path -Name $_.Name -Value $_.Value -PropertyType $_.Type -Force -EA Ignore
}
}
pop-location
#reload the imported config
Build-Config -Config2Load $AppShortName
Initial-Load
} #end Function
function Set-SnapViewMode
{
param ([bool]$switch)