1
- # ========================================================================
1
+ # ========================================================================
2
2
#
3
3
# Title: Admin Run-As Menu
4
4
# Created: 2016-11-03
@@ -161,6 +161,7 @@ Start-Log -FilePath "$env:LocalAppData\AdminMenu\Logs\$(Get-Date -Format yyyyMMd
161
161
# # Variables: Script Name and Script Paths
162
162
[string ]$scriptPath = $MyInvocation.MyCommand.Definition
163
163
[string ]$scriptName = [IO.Path ]::GetFileNameWithoutExtension($scriptPath )
164
+ [string ]$scriptFileName = Split-Path - Path $scriptPath - Leaf
164
165
[string ]$scriptRoot = Split-Path - Path $scriptPath - Parent
165
166
[string ]$invokingScript = (Get-Variable - Name ' MyInvocation' ).Value.ScriptName
166
167
@@ -180,17 +181,17 @@ Else {
180
181
[string ]$XamlPath = Join-Path - Path $scriptRoot - ChildPath ' Resources'
181
182
[string ]$ModulesPath = Join-Path - Path $scriptRoot - ChildPath ' Modules'
182
183
[string ]$UtilPath = Join-Path - Path $scriptRoot - ChildPath ' Utilities'
183
- [string ]$ConfigPath = Join-Path - Path $scriptRoot - ChildPath ' Configs'
184
- [string ]$MenuScriptsPath = Join-Path - Path $scriptRoot - ChildPath ' Scripts'
185
184
186
185
# When Using Executable Command Line
187
186
If ($ConfigCommandLine ){
188
187
[string ]$ConfigFile = Join-Path - Path $scriptRoot - ChildPath $ConfigCommandLine
189
188
}
190
189
Else {
191
- [string ]$ConfigFile = Join-Path - Path $ConfigPath - ChildPath ' AdminMenu.ps1.config'
190
+ [string ]$ConfigFile = Join-Path - Path $scriptRoot - ChildPath ' AdminMenu.ps1.config'
192
191
}
193
- [string ]$NameFile = Join-Path - Path $ConfigPath - ChildPath ' AdminMenu.prereqs'
192
+ [string ]$NameFile = Join-Path - Path $scriptRoot - ChildPath ' AdminMenu.ps1.names'
193
+
194
+ [string ]$appAuthor = ' Richard Tracy'
194
195
# =======================================================
195
196
# PARSE CONFIG FILE
196
197
# =======================================================
@@ -205,7 +206,6 @@ Else{
205
206
[Xml.XmlElement ]$xmlMenuOptions = $xmlConfig.Menu_Options
206
207
[boolean ]$AppOptionRequireAdmin = [boolean ]::Parse($xmlMenuOptions.Option_RequireAdmin )
207
208
[boolean ]$AppOptionRSATCheck = [boolean ]::Parse($xmlMenuOptions.Option_RSATCheck )
208
- [boolean ]$AppPrereqCheck = [boolean ]::Parse($xmlMenuOptions.Option_PrereqCheck )
209
209
[boolean ]$AppOptionDebugeMode = [boolean ]::Parse($xmlMenuOptions.Option_DebugMode )
210
210
[string ]$AppOptionAccent = $xmlMenuOptions.Option_Accent
211
211
[string ]$AppOptionTheme = $xmlMenuOptions.Option_Theme
@@ -215,6 +215,7 @@ Else{
215
215
[boolean ]$AppUIHideButtons = [boolean ]::Parse($xmlUIControls.Control_HideUnusedButtons )
216
216
[boolean ]$AppUIHideCredManager = [boolean ]::Parse($xmlUIControls.Control_HideCredManager )
217
217
[boolean ]$AppUIHideQuickAccess = [boolean ]::Parse($xmlUIControls.Control_HideQuickAccess )
218
+ [string ]$AppUIQuickAccessPosition = $xmlUIControls.Control_QuickAccessPosition
218
219
[boolean ]$AppUIDisableOptionMenu = [boolean ]::Parse($xmlUIControls.Control_DisableUserOption )
219
220
# Get Menu Configurations
220
221
[Xml.XmlElement ]$xmlMenuConfigs = $xmlConfig.Menu_Configs
@@ -224,8 +225,8 @@ Else{
224
225
225
226
# check if remote config will be used and path is accessible
226
227
If (($AppUseRemoteConfig ) -and (Test-Path $AppRemotePath ) -and (! $ForceLocal )){
227
- [string ]$remoteConfig = Join-Path - Path $AppRemotePath - ChildPath ' \Configs\ AdminMenu.ps1.config' - ErrorAction SilentlyContinue
228
- [string ]$remoteNames = Join-Path - Path $AppRemotePath - ChildPath ' \Configs\ AdminMenu.prereqs ' - ErrorAction SilentlyContinue
228
+ [string ]$remoteConfig = Join-Path - Path $AppRemotePath - ChildPath ' AdminMenu.ps1.config' - ErrorAction SilentlyContinue
229
+ [string ]$remoteNames = Join-Path - Path $AppRemotePath - ChildPath ' AdminMenu.ps1.names ' - ErrorAction SilentlyContinue
229
230
If (-not (Test-Path $remoteConfig - ErrorAction SilentlyContinue) -and (-not (Test-Path $remoteNames - ErrorAction SilentlyContinue)) ){
230
231
If ($AppOptionDebugeMode ){Write-Log - Message " Remote config files were not found at: $AppRemotePath ; local config will be processed instead" - Severity 2 - OutputHost}
231
232
[boolean ]$AppUseRemoteConfig = $False
@@ -595,7 +596,7 @@ $notifyicon.BalloonTipText = $BalloonMsg
595
596
596
597
# Call the balloon notification
597
598
$ExitItem = New-Object System.Windows.Forms.MenuItem
598
- $ExitItem.Text = " Exit Tool "
599
+ $ExitItem.Text = " Exit"
599
600
# When Exit is clicked, close everything and kill the PowerShell process
600
601
$ExitItem.add_Click ({
601
602
$App.Close ()
@@ -606,111 +607,116 @@ $ExitItem.add_Click({
606
607
If (! $envRunningInISE ){Stop-Process $pid }
607
608
})
608
609
610
+
609
611
$DebugItem = New-Object System.Windows.Forms.MenuItem
610
612
$DebugItem.Text = " Show Debug Console"
611
- $DebugItem.Add_Click ({
612
- If (Show-PSConsole ){
613
- Hide-PSConsole
614
- $DebugItem.Text = ' Show Debug Console'
615
- }
616
- Else {
617
- Show-PSConsole
618
- $DebugItem.Text = ' Hide Debug Console'
619
- write-host " Use the 'Hide Debug button' from the context menu in the taskbar icon to close this debug window.
620
- `n If closed with the X button, it will close the menu as well" - ForegroundColor Yellow - BackgroundColor Black
621
- }
622
- })
613
+ $DebugItem.Add_Click ({Toggle- PSConsole})
614
+
615
+ $PSOBItem = New-Object System.Windows.Forms.MenuItem
616
+ $PSOBItem.Text = " Object Browser"
617
+ $PSOBItem.Add_Click ({Start-ButtonProcess - ProcessCall ps1 - File " PSObjectBrowser.ps1" - CreateNoWindow})
623
618
624
619
$AboutItem = New-Object System.Windows.Forms.MenuItem
625
620
$AboutItem.Text = " About"
626
621
$AboutItem.Add_Click ({Open-AboutWindow })
627
622
628
- $QuickItem = New-Object System.Windows.Forms.MenuItem
629
- $QuickItem.Text = " Quick Access"
623
+ # $SeperatorItem = New-Object System.Windows.Forms.SplitContainer
624
+ $SeperatorItem1 = New-Object System.Windows.Forms.MenuItem
625
+ $SeperatorItem1.Text = " -"
630
626
631
- $SeperatorItem = New-Object System.Windows.Forms.MenuItem
632
- $SeperatorItem.Text = " ──────────────────"
633
- $SeperatorItem.Enabled = $false
627
+ $SeperatorItem2 = New-Object System.Windows.Forms.MenuItem
628
+ $SeperatorItem2.Text = " -"
634
629
635
- If (! $AppUIHideQuickAccess ){
636
- $contextmenu = New-Object System.Windows.Forms.ContextMenu
637
- $notifyicon.ContextMenu = $contextmenu
638
- If ($AppOptionDebugeMode -and ! $envRunningInISE ){
639
- $notifyicon.contextMenu.MenuItems.AddRange (@ ($DebugItem , $QuickItem , $SeperatorItem , $AboutItem , $ExitItem ))
640
- }
641
- Else {
642
- $notifyicon.contextMenu.MenuItems.AddRange (@ ($QuickItem , $SeperatorItem , $AboutItem , $ExitItem ))
643
- }
644
- $quickitem.add_Click ({Launch- QuickMenu})
645
- }
646
- Else {
647
- $contextmenu = New-Object System.Windows.Forms.ContextMenu
648
- $notifyicon.ContextMenu = $contextmenu
649
- If ($AppOptionDebugeMode -and ! $envRunningInISE ){
650
- $notifyicon.contextMenu.MenuItems.AddRange (@ ($DebugItem , $SeperatorItem , $AboutItem , $ExitItem ))
651
- }
652
- Else {
653
- $notifyicon.contextMenu.MenuItems.AddRange (@ ($AboutItem , $ExitItem ))
654
- }
630
+ $contextmenu = New-Object System.Windows.Forms.ContextMenu
631
+ $notifyicon.ContextMenu = $contextmenu
632
+ If ($AppOptionDebugeMode -and ! $envRunningInISE ){
633
+ $notifyicon.contextMenu.MenuItems.AddRange (@ ($DebugItem , $PSOBItem , $SeperatorItem2 , $AboutItem , $SeperatorItem1 , $ExitItem ))
634
+ }
635
+ Else {
636
+ $notifyicon.contextMenu.MenuItems.AddRange (@ ($PSOBItem , $SeperatorItem2 , $AboutItem , $SeperatorItem1 , $ExitItem ))
655
637
}
656
638
657
- # Add a left click that makes the Window appear
658
- # part of the screen, above the notify icon.
659
- $notifyicon.add_Click ({
660
- # if ($_.Button -eq [Windows.Forms.MouseButtons]::Left) {
661
- $App.Add_Closing ({$_.Cancel = $True })
662
- $App.Hide () # ensures the window isn't already open
663
- $App.Add_Closing ({$_.Cancel = $False })
664
- $App.Show ()
665
- # }
666
- })
667
-
668
-
639
+ $notifyicon.add_Click ({Show-Menu })
640
+ $notifyicon.add_DoubleClick ({Show-Menu })
669
641
670
642
# #*==============================
671
643
# #* LOAD FORM - Open / Hide App Button
672
644
# #*==============================
673
645
674
- $OApp.Hide ()
675
- # reposition each time, in case the resolution or monitor changes
676
646
$OApp.Topmost = $True
677
- $OApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )-20
678
- $OApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )-15
679
-
680
-
681
- $OAppbtnOpenApp.add_Click ({
682
- $OApp.Hide ()
683
- $HApp.Show ()
684
- $HApp.Activate ()
685
-
686
- $App.Add_Closing ({$_.Cancel = $False })
687
- $App.Show ()
688
- })
689
-
690
-
691
- $HApp.Show ()
692
- # reposition each time, in case the resolution or monitor changes
693
647
$HApp.Topmost = $True
694
- $HApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )-20
695
- $HApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )-15
696
648
697
- $HAppbtnHideApp.add_Click ({
698
- $HApp.Hide ()
699
- $OApp.Show ()
700
- $OApp.Activate ()
649
+ Switch ($AppUIQuickAccessPosition )
650
+ {
651
+ " BottomLeft"
652
+ {
653
+ $OApp.Left = 20
654
+ $OApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )-15
655
+ $HApp.Left = 20
656
+ $HApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $HApp.Height )-15
657
+ }
658
+ " BottomCenter"
659
+ {
660
+ $OApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )/ 2
661
+ $OApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )-15
662
+ $HApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $HApp.Width )/ 2
663
+ $HApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $HApp.Height )-15
664
+ }
665
+ " BottomRight"
666
+ {
667
+ $OApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )-20
668
+ $OApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )-15
669
+ $HApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $HApp.Width )-20
670
+ $HApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $HApp.Height )-15
671
+ }
672
+ " TopLeft"
673
+ {
674
+ $OApp.Left = 20
675
+ $OApp.Top = 30
676
+ $HApp.Left = 20
677
+ $HApp.Top = 30
678
+ }
679
+ " TopCenter"
680
+ {
681
+ $OApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )/ 2
682
+ $OApp.Top = 30
683
+ $HApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $HApp.Width )/ 2
684
+ $HApp.Top = 30
685
+ }
686
+ " TopRight"
687
+ {
688
+ $OApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )-20
689
+ $OApp.Top = 30
690
+ $HApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $HApp.Width )-20
691
+ $HApp.Top = 30
692
+ }
693
+ " LeftCenter"
694
+ {
695
+ $OApp.Left = 20
696
+ $OApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )/ 2
697
+ $HApp.Left = 20
698
+ $HApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $HApp.Height )/ 2
699
+ }
700
+ " RightCenter"
701
+ {
702
+ $OApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $OApp.Width )-20
703
+ $OApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $OApp.Height )/ 2
704
+ $HApp.Left = $ ([System.Windows.SystemParameters ]::WorkArea.Width- $HApp.Width )-20
705
+ $HApp.Top = $ ([System.Windows.SystemParameters ]::WorkArea.Height- $HApp.Height )/ 2
706
+ }
707
+
708
+ }
701
709
702
- $App.Add_Closing ({$_.Cancel = $True })
703
- $App.Hide ()
704
- # $notifyicon.ShowBalloonTip(5)
705
- })
710
+ $OAppbtnOpenApp.add_Click ({Show-Menu })
711
+ $HAppbtnHideApp.add_Click ({Hide-Menu })
706
712
707
713
# #*==============================
708
714
# #* LOAD FORM - APP CONTENT AND BUTTONS
709
715
# #*==============================
710
716
# $App.Opacity = 0.95
711
717
712
718
# create Local directory for user settings
713
- New-Item " $envLocalAppData \AdminMenu" - ItemType Directory - ErrorAction SilentlyContinue | Out-Null
719
+ New-Item " $env: LocalAppData \AdminMenu" - ItemType Directory - ErrorAction SilentlyContinue | Out-Null
714
720
715
721
Write-OutputBox - OutputBoxMessage " Loading $AppTitle [ver. $AppVersion ]" - Type " START: " - Object tab1
716
722
If ($AppOptionDebugeMode ){Get-FormVariables }
@@ -759,27 +765,11 @@ Else{
759
765
# $WPFbtnOptions.Add_Click({$WPFFlyOutContent.IsOpen = $true})
760
766
}
761
767
762
- $WPFbtnHide.Add_Click ({
763
- $HApp.Hide ()
764
- $OApp.Show ()
765
- $OApp.Activate ()
766
-
767
- $App.Add_Closing ({$_.Cancel = $True })
768
- $App.Hide ()
769
- $notifyicon.ShowBalloonTip (5 )
770
- })
768
+ $WPFbtnHide.Add_Click ({Hide-Menu - ShowTip})
771
769
772
770
# Hide the window if it loses focus
773
771
If ($AppUIHideApp ){
774
- $App.Add_Deactivated ({
775
- $HApp.Hide ()
776
- $OApp.Show ()
777
- $OApp.Activate ()
778
-
779
- $App.Add_Closing ({$_.Cancel = $True })
780
- $App.Hide ()
781
- $notifyicon.ShowBalloonTip (5 )
782
- })
772
+ $App.Add_Deactivated ({Hide-Menu - ShowTip})
783
773
}
784
774
785
775
# App Window (top right) Exit button
@@ -804,21 +794,10 @@ $App.Add_KeyDown({
804
794
Change- TabItem - increment 1
805
795
}
806
796
" UP" {
807
- $OApp.Hide ()
808
- $HApp.Show ()
809
- $HApp.Activate ()
810
-
811
- $App.Add_Closing ({$_.Cancel = $False })
812
- $App.Show ()
797
+ Show-Menu - OnTop
813
798
}
814
799
" DOWN" {
815
- $HApp.Hide ()
816
- $OApp.Show ()
817
- $OApp.Activate ()
818
-
819
- $App.Add_Closing ({$_.Cancel = $True })
820
- $App.Hide ()
821
- $notifyicon.ShowBalloonTip (5 )
800
+ Hide-Menu - ShowTip
822
801
}
823
802
Default {$Null }
824
803
}
@@ -863,32 +842,29 @@ $App.Icon = $AppBitmap
863
842
# Allow input to window for TextBoxes, etc
864
843
[Void ][System.Windows.Forms.Integration.ElementHost ]::EnableModelessKeyboardInterop($App )
865
844
866
- # Make PowerShell Window Disappear
867
- If (! $envRunningInISE ){Hide-PSConsole } # hide the console at start when running exe
845
+ If (! $envRunningInISE ){
846
+ # Hide-PSConsole # hide the console at start when running exe
847
+ # Make PowerShell Disappear
848
+ $windowcode = ' [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
849
+ $asyncwindow = Add-Type - MemberDefinition $windowcode - name Win32ShowWindowAsync - namespace Win32Functions - PassThru
850
+ $null = $asyncwindow ::ShowWindowAsync((Get-Process - PID $pid ).MainWindowHandle, 0 )
851
+ }
868
852
869
- <#
870
- $windowcode = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
871
- $asyncwindow = Add-Type -MemberDefinition $windowcode -name Win32ShowWindowAsync -namespace Win32Functions -PassThru
872
- $null = $asyncwindow::ShowWindowAsync((Get-Process -PID $pid).MainWindowHandle, 0)
873
- #>
853
+ Show-Menu - OnTop
874
854
855
+ # Force garbage collection just to start slightly lower RAM usage.
875
856
[System.GC ]::Collect()
876
857
[System.GC ]::WaitForPendingFinalizers()
877
858
878
- # This makes it pop up
879
- $App.Show ()
880
- # This makes it the active window
881
- $App.Activate () | Out-Null
882
-
883
859
Try {
884
860
$AppWindowState = [System.Windows.Forms.FormWindowState ]::Normal
885
861
$App.WindowState = $AppWindowState
886
862
}
887
863
Catch {
888
864
$ErrorMessage = $_.Exception.Message
889
- Write-Host " Unable to set WindosState . May be unsupported in OS version"
865
+ Write-Host " Unable to set WindowsState . May be unsupported in OS version"
890
866
}
891
867
# Create an application context for it to all run within.
892
868
# This helps with responsiveness, especially when clicking Exit.
893
869
$appContext = New-Object System.Windows.Forms.ApplicationContext
894
- [System.Windows.Forms.Application ]::Run($appContext )
870
+ [System.Windows.Forms.Application ]::Run($appContext )
0 commit comments