Skip to content

Commit

Permalink
Separate package with ps1 script only
Browse files Browse the repository at this point in the history
seerge committed Feb 14, 2023
1 parent c9e25b6 commit 2340563
Showing 7 changed files with 60 additions and 24 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
Binary file added G14-Helper.lnk
Binary file not shown.
13 changes: 13 additions & 0 deletions events.ps1
Original file line number Diff line number Diff line change
@@ -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) {

}
1 change: 1 addition & 0 deletions g14-helper.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
powershell -WindowStyle hidden -file ghelper.ps1
Binary file modified g14-helper.exe
Binary file not shown.
3 changes: 1 addition & 2 deletions ghelper-compile.ps1
Original file line number Diff line number Diff line change
@@ -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
ps2exe .\ghelper.ps1 g14-helper.exe -title 'G14 Helper' -DPIAware -winFormsDPIAware -requireAdmin -iconFile 'standard.ico' -noConsole -copyright 'G14 Helper Tool' -noOutput
59 changes: 40 additions & 19 deletions ghelper.ps1
Original file line number Diff line number Diff line change
@@ -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)
[void][System.Windows.Forms.Application]::Run($appContext)


0 comments on commit 2340563

Please sign in to comment.