Skip to content

Commit fc32b77

Browse files
fixed original version
1 parent 3488325 commit fc32b77

File tree

78 files changed

+25376
-36049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+25376
-36049
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

App/AdminMenu.ps1 renamed to AdminMenu.ps1

Lines changed: 108 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#========================================================================
1+
#========================================================================
22
#
33
# Title: Admin Run-As Menu
44
# Created: 2016-11-03
@@ -161,6 +161,7 @@ Start-Log -FilePath "$env:LocalAppData\AdminMenu\Logs\$(Get-Date -Format yyyyMMd
161161
## Variables: Script Name and Script Paths
162162
[string]$scriptPath = $MyInvocation.MyCommand.Definition
163163
[string]$scriptName = [IO.Path]::GetFileNameWithoutExtension($scriptPath)
164+
[string]$scriptFileName = Split-Path -Path $scriptPath -Leaf
164165
[string]$scriptRoot = Split-Path -Path $scriptPath -Parent
165166
[string]$invokingScript = (Get-Variable -Name 'MyInvocation').Value.ScriptName
166167

@@ -180,17 +181,17 @@ Else {
180181
[string]$XamlPath = Join-Path -Path $scriptRoot -ChildPath 'Resources'
181182
[string]$ModulesPath = Join-Path -Path $scriptRoot -ChildPath 'Modules'
182183
[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'
185184

186185
# When Using Executable Command Line
187186
If ($ConfigCommandLine){
188187
[string]$ConfigFile = Join-Path -Path $scriptRoot -ChildPath $ConfigCommandLine
189188
}
190189
Else{
191-
[string]$ConfigFile = Join-Path -Path $ConfigPath -ChildPath 'AdminMenu.ps1.config'
190+
[string]$ConfigFile = Join-Path -Path $scriptRoot -ChildPath 'AdminMenu.ps1.config'
192191
}
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'
194195
#=======================================================
195196
# PARSE CONFIG FILE
196197
#=======================================================
@@ -205,7 +206,6 @@ Else{
205206
[Xml.XmlElement]$xmlMenuOptions = $xmlConfig.Menu_Options
206207
[boolean]$AppOptionRequireAdmin = [boolean]::Parse($xmlMenuOptions.Option_RequireAdmin)
207208
[boolean]$AppOptionRSATCheck = [boolean]::Parse($xmlMenuOptions.Option_RSATCheck)
208-
[boolean]$AppPrereqCheck = [boolean]::Parse($xmlMenuOptions.Option_PrereqCheck)
209209
[boolean]$AppOptionDebugeMode = [boolean]::Parse($xmlMenuOptions.Option_DebugMode)
210210
[string]$AppOptionAccent = $xmlMenuOptions.Option_Accent
211211
[string]$AppOptionTheme = $xmlMenuOptions.Option_Theme
@@ -215,6 +215,7 @@ Else{
215215
[boolean]$AppUIHideButtons = [boolean]::Parse($xmlUIControls.Control_HideUnusedButtons)
216216
[boolean]$AppUIHideCredManager = [boolean]::Parse($xmlUIControls.Control_HideCredManager)
217217
[boolean]$AppUIHideQuickAccess = [boolean]::Parse($xmlUIControls.Control_HideQuickAccess)
218+
[string]$AppUIQuickAccessPosition = $xmlUIControls.Control_QuickAccessPosition
218219
[boolean]$AppUIDisableOptionMenu = [boolean]::Parse($xmlUIControls.Control_DisableUserOption)
219220
# Get Menu Configurations
220221
[Xml.XmlElement]$xmlMenuConfigs = $xmlConfig.Menu_Configs
@@ -224,8 +225,8 @@ Else{
224225

225226
#check if remote config will be used and path is accessible
226227
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
229230
If (-not (Test-Path $remoteConfig -ErrorAction SilentlyContinue) -and (-not (Test-Path $remoteNames -ErrorAction SilentlyContinue)) ){
230231
If ($AppOptionDebugeMode){Write-Log -Message "Remote config files were not found at: $AppRemotePath; local config will be processed instead" -Severity 2 -OutputHost}
231232
[boolean]$AppUseRemoteConfig = $False
@@ -595,7 +596,7 @@ $notifyicon.BalloonTipText = $BalloonMsg
595596

596597
#Call the balloon notification
597598
$ExitItem = New-Object System.Windows.Forms.MenuItem
598-
$ExitItem.Text = "Exit Tool"
599+
$ExitItem.Text = "Exit"
599600
# When Exit is clicked, close everything and kill the PowerShell process
600601
$ExitItem.add_Click({
601602
$App.Close()
@@ -606,111 +607,116 @@ $ExitItem.add_Click({
606607
If(!$envRunningInISE){Stop-Process $pid}
607608
})
608609

610+
609611
$DebugItem = New-Object System.Windows.Forms.MenuItem
610612
$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-
`nIf 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})
623618

624619
$AboutItem = New-Object System.Windows.Forms.MenuItem
625620
$AboutItem.Text = "About"
626621
$AboutItem.Add_Click({Open-AboutWindow})
627622

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 = "-"
630626

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 = "-"
634629

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))
655637
}
656638

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})
669641

670642
##*==============================
671643
##* LOAD FORM - Open / Hide App Button
672644
##*==============================
673645

674-
$OApp.Hide()
675-
# reposition each time, in case the resolution or monitor changes
676646
$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
693647
$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
696648

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+
}
701709

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})
706712

707713
##*==============================
708714
##* LOAD FORM - APP CONTENT AND BUTTONS
709715
##*==============================
710716
#$App.Opacity = 0.95
711717

712718
#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
714720

715721
Write-OutputBox -OutputBoxMessage "Loading $AppTitle [ver. $AppVersion]" -Type "START: " -Object tab1
716722
If ($AppOptionDebugeMode){Get-FormVariables}
@@ -759,27 +765,11 @@ Else{
759765
#$WPFbtnOptions.Add_Click({$WPFFlyOutContent.IsOpen = $true})
760766
}
761767

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})
771769

772770
# Hide the window if it loses focus
773771
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})
783773
}
784774

785775
#App Window (top right) Exit button
@@ -804,21 +794,10 @@ $App.Add_KeyDown({
804794
Change-TabItem -increment 1
805795
}
806796
"UP" {
807-
$OApp.Hide()
808-
$HApp.Show()
809-
$HApp.Activate()
810-
811-
$App.Add_Closing({$_.Cancel = $False})
812-
$App.Show()
797+
Show-Menu -OnTop
813798
}
814799
"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
822801
}
823802
Default {$Null}
824803
}
@@ -863,32 +842,29 @@ $App.Icon = $AppBitmap
863842
# Allow input to window for TextBoxes, etc
864843
[Void][System.Windows.Forms.Integration.ElementHost]::EnableModelessKeyboardInterop($App)
865844

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+
}
868852

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
874854

855+
# Force garbage collection just to start slightly lower RAM usage.
875856
[System.GC]::Collect()
876857
[System.GC]::WaitForPendingFinalizers()
877858

878-
# This makes it pop up
879-
$App.Show()
880-
# This makes it the active window
881-
$App.Activate() | Out-Null
882-
883859
Try{
884860
$AppWindowState = [System.Windows.Forms.FormWindowState]::Normal
885861
$App.WindowState = $AppWindowState
886862
}
887863
Catch {
888864
$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"
890866
}
891867
# Create an application context for it to all run within.
892868
# This helps with responsiveness, especially when clicking Exit.
893869
$appContext = New-Object System.Windows.Forms.ApplicationContext
894-
[System.Windows.Forms.Application]::Run($appContext)
870+
[System.Windows.Forms.Application]::Run($appContext)

0 commit comments

Comments
 (0)