diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b2d2d1ba..2353ae6a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,13 +19,15 @@ jobs: - name: Build run: | mkdir release - cp *.exe ./release + cp *.cmd ./release + cp *.lnk ./release cp ghelper.ps1 ./release - zip -r g14-helper.zip ./release + zip -r g14-helper-script.zip ./release - name: Release uses: softprops/action-gh-release@v1 with: files: | - g14-helper.zip + g14-helper-script.zip + g14-helper.exe diff --git a/G14-Helper.lnk b/G14-Helper.lnk new file mode 100644 index 00000000..66a0bdd0 Binary files /dev/null and b/G14-Helper.lnk differ diff --git a/events.ps1 b/events.ps1 new file mode 100644 index 00000000..64b65ab9 --- /dev/null +++ b/events.ps1 @@ -0,0 +1,13 @@ +Get-EventSubscriber | Unregister-Event + + +$ProcessAsusWmiEvent = { + $event_id = $Event.SourceEventArgs.NewEvent.EventID + Write-Host $event_id +} + +Register-CimIndicationEvent -Namespace root\wmi -query "Select * From AsusAtkWmiEvent" ` -sourceIdentifier "GHAsus" ` -action $ProcessAsusWmiEvent + +while (1) { + +} diff --git a/g14-helper.cmd b/g14-helper.cmd new file mode 100644 index 00000000..52f16368 --- /dev/null +++ b/g14-helper.cmd @@ -0,0 +1 @@ +powershell -WindowStyle hidden -file ghelper.ps1 diff --git a/g14-helper.exe b/g14-helper.exe index 60749575..f5308364 100644 Binary files a/g14-helper.exe and b/g14-helper.exe differ diff --git a/ghelper-compile.ps1 b/ghelper-compile.ps1 index 5863c32d..2a1349be 100644 --- a/ghelper-compile.ps1 +++ b/ghelper-compile.ps1 @@ -1,2 +1 @@ -ps2exe .\ghelper.ps1 g14-helper.exe -title 'G14 Helper' -DPIAware -winFormsDPIAware -requireAdmin -iconFile 'standard.ico' -noConsole -copyright 'G14 Helper Tool' -noOutput -.\g14-helper.exe \ No newline at end of file +ps2exe .\ghelper.ps1 g14-helper.exe -title 'G14 Helper' -DPIAware -winFormsDPIAware -requireAdmin -iconFile 'standard.ico' -noConsole -copyright 'G14 Helper Tool' -noOutput \ No newline at end of file diff --git a/ghelper.ps1 b/ghelper.ps1 index e280f4d2..93c11390 100644 --- a/ghelper.ps1 +++ b/ghelper.ps1 @@ -1,27 +1,40 @@ -[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | out-null -[System.Reflection.Assembly]::LoadWithPartialName('presentationframework') | out-null -[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | out-null -[System.Reflection.Assembly]::LoadWithPartialName('WindowsFormsIntegration') | out-null - - -Function Get-PSScriptPath { - if ([System.IO.Path]::GetExtension($PSCommandPath) -eq '.ps1') { - $psScriptPath = $PSCommandPath - } else { - $psScriptPath = [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName +# Self-elevate the script +if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { + if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { + $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments + Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine -WindowStyle Hidden + Exit } - return $psScriptPath } +# DPI Awareness +Add-Type -TypeDefinition @' +using System.Runtime.InteropServices; +public class ProcessDPI { + [DllImport("user32.dll", SetLastError=true)] + public static extern bool SetProcessDPIAware(); +} +'@ +$null = [ProcessDPI]::SetProcessDPIAware() +[System.Windows.Forms.Application]::EnableVisualStyles() + +Add-Type -AssemblyName PresentationFramework +Add-Type -AssemblyName System.Windows.Forms +Add-Type -AssemblyName System.Drawing +Add-Type -AssemblyName WindowsFormsIntegration function SetAutostart () { $taskName = "G14Helper" $task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue if ($null -ne $task) {return } - $scriptDir = Get-PSScriptPath + if ([System.IO.Path]::GetExtension($PSCommandPath) -eq '.ps1') { + $action = New-ScheduledTaskAction -Execute "powershell" -Argument "-WindowStyle Hidden -File $PSCommandPath" + } else { + $psScriptPath = [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName + $action = New-ScheduledTaskAction -Execute $psScriptPath + } - $action = New-ScheduledTaskAction -Execute $scriptDir $trigger = New-ScheduledTaskTrigger -AtLogon $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries @@ -406,7 +419,7 @@ function SetPeformanceMode ($performance_mode = 0) { SaveConfigSetting -Name 'performance_mode' -Value $performance_mode UICheckStats - Invoke-CimMethod $asushw -MethodName DEVS -Arguments @{Device_ID=$device_performance ; Control_status=$performance_mode } + Invoke-CimMethod $asushw -MethodName DEVS -Arguments @{Device_ID=$device_performance ; Control_status=$performance_mode } | Out-Null WriteLog("Performance set to "+$performance_mode) } @@ -432,14 +445,14 @@ function SetChargeLimit ($charge_limit = 100) { SaveConfigSetting -Name 'charge_limit' -Value $charge_limit $Submenu_Charge.Text = "Charge Limit: $charge_limit%" - Invoke-CimMethod $asushw -MethodName DEVS -Arguments @{Device_ID=0x00120057 ; Control_status=$charge_limit } + Invoke-CimMethod $asushw -MethodName DEVS -Arguments @{Device_ID=0x00120057 ; Control_status=$charge_limit } | Out-Null WriteLog("Charge limit set to "+$charge_limit) } function SetPanelOverdrive ($overdrive = 1) { SaveConfigSetting -Name 'panel_overdrive' -Value $overdrive - Invoke-CimMethod $asushw -MethodName DEVS -Arguments @{Device_ID=$device_overdrive ; Control_status=$overdrive } + Invoke-CimMethod $asushw -MethodName DEVS -Arguments @{Device_ID=$device_overdrive ; Control_status=$overdrive } | Out-Null WriteLog("Panel Overdrive set to "+$overdrive) } @@ -647,11 +660,19 @@ $Menu_Exit.add_Click({ $Main_Tool_Icon.Visible = $false Stop-Process $pid }) - + + +# Make PowerShell Disappear +$windowcode = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);' +$asyncwindow = Add-Type -MemberDefinition $windowcode -name Win32ShowWindowAsync -namespace Win32Functions -PassThru +$null = $asyncwindow::ShowWindowAsync((Get-Process -PID $pid).MainWindowHandle, 0) + # Force garbage collection just to start slightly lower RAM usage. [System.GC]::Collect() # Create an application context for it to all run within. # This helps with responsiveness, especially when clicking Exit. $appContext = New-Object System.Windows.Forms.ApplicationContext -[void][System.Windows.Forms.Application]::Run($appContext) \ No newline at end of file +[void][System.Windows.Forms.Application]::Run($appContext) + +