Hi,
ja, ich hab' da was! Wie ich gerade gesehen habe ist das Skript schon bald sieben Jahre alt, aber es läuft... und läuft... und läuft
Sicherlich gibt es nach sieben Jahren Optimierungsmöglichkeiten, eigentlich wollte ich noch 'ne Weiche einbauen, dass das Skript erst in "issuspended" geht, wenn Akkustand unter 70% oder so...
Außerdem: Ich baue Pakete in fünf Sprachen und habe mir deswegen eigene und für alle Pakete verwendbare Language-Files gebaut... daher auch die Variable $MSG_POWERCHECK$ (und andere), die aus dem zuvor inkludierten Language-File kommt. Diese Variablen einfach entfernen oder umschreiben.
Auch die Anzeige eigens generierten Bitmaps via
Code: Alles auswählen
ShowBitmap "%ScriptPath%\SPMS\" + "icon_power.png" $ProductName$
musst Du noch auskommentieren...
Hier das Snipplet, deren Aufruf ich inkludiere:
Code: Alles auswählen
encoding=UTF-8
; ################################################################
; Copyright & Maintainer [...entfernt...]
; ################################################################
;
;
; Prüft, ob das System mit Strom oder über Akku versorgt wird
; Version 2018-12-23
;Seit Version 4.11.4.1 kann bei einem Script (egal ob Hauptskript, sub oder include) das encoding auch angegeben werden. Dazu gibt es den Befehl:
;encoding=<encoding>
;Dieser Befehl kann an einer beliebigen Stelle in der Scriptdatei stehen. Das <encoding> ist eines der folgenden Werte:
encoding=utf8
encoding=UTF-8
; ----------------------------------------------------------------------------------
; - Systemtyp: Wir ermitteln, ob es sich überhaupt um ein "tragbares" System hält -
; 8 = Portable
; 9 = Laptop
; 10 = Notebook
; 11 = Handheld
; 14 = Laptop
; 30 = Tablet
; 31 = (convertible)
; 32 = (detachable)
; ----------------------------------------------------------------------------------
DefStringList $resultlist$
DefVar $chassis$
; System bestimmen
Set $chassis$ = getRegistryValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\SYSTEM\BIOS", "EnclosureType")
if ($chassis$ = "8" OR $chassis$ ="9" OR $chassis$ ="10" OR $chassis$ ="11" OR $chassis$ ="14" OR $chassis$ ="30" OR $chassis$ ="31" OR $chassis$ ="32" )
message $MSG_POWERCHECK$
; ----------------------------------------------------------------------------------
; - Loglevel: Alter Wert auslesen und neuen Wert setzen -
; ----------------------------------------------------------------------------------
DefVar $LogLevelBefore_powersupplyins$
set $LogLevelBefore_powersupplyins$ = getLoglevel
Setloglevel = 4
ShowBitmap "%ScriptPath%\SPMS\" + "icon_power.png" $ProductName$
DefStringList $powersupply_list$
DefStringList $powersupply_list1$
DefStringList $powersupply_list2$
DefVar $powersupply_exitcode$
DefVar $powersupply_CompValue$
DefVar $powersupply_TestResult$
DefVar $powersupply_PSSecurityException$
if ((CompareDotSeparatedNumbers("%WinstVersion%","4.11.3.5") >= "0") and (CompareDotSeparatedNumbers(GetMsVersionInfo,"6.1") >= "0"))
DosInAnIcon_setpolicy
set $powersupply_exitcode$ = getLastExitcode
if not ($powersupply_exitcode$ = "0")
comment "powershell script failed"
endif
set $powersupply_list1$ = getOutStreamFromSection ('execwith_powershell_architecture "%System%\WindowsPowerShell\v1.0\powershell.exe" winst /32bit')
comment "check if the script was executed..."
set $powersupply_CompValue$ = takeFirstStringContaining($powersupply_list1$,"powershell opsi-winst-test")
if ("" = $powersupply_CompValue$)
comment "check if the script was not executed because powershell is not activated..."
endif
if not ("" = $powersupply_CompValue$)
set $powersupply_PSSecurityException$ = takeFirstStringContaining($powersupply_list1$,"PSSecurityException")
if ("" = $powersupply_PSSecurityException$)
comment "Execwith assumed passed"
set $powersupply_TestResult$ = "o.k."
comment "Execwith assumed passed"
else
message "Achtung: PSSecurityException"
set $powersupply_TestResult$ = "not o.k. - PSSecurityException"
endif
else
set $powersupply_TestResult$ = "not o.k."
LogWarning "Execwith assumed failed"
endif
endif
; ----------------------------------------------------------------------------------
; - Der eigentliche Test -
; ----------------------------------------------------------------------------------
ShowBitmap "%ScriptPath%\SPMS\" + "icon_power.png" $ProductName$
message $MSG_POWERCHECK$
DefVar $PowerState$
set $powersupply_list1$ = getOutStreamFromSection ('execwith_powershell_checkpowersupply "%System%\WindowsPowerShell\v1.0\powershell.exe" winst /32bit')
set $powersupply_TestResult$ = takeFirstStringContaining($powersupply_list1$,"powershell Powertest")
set $powersupply_CompValue$ = takeFirstStringContaining($powersupply_list1$,"PowerOnline")
set $powersupply_list1$ = splitString($powersupply_CompValue$, ":")
set $PowerState$ = trim(takeFirstStringContaining($powersupply_list1$,"False"))
if ($PowerState$ = "False")
ShowBitmap "%ScriptPath%\SPMS\" + "icon_power_onbattery.png" $ProductName$
message $MSG_POWERCHECK_ONBATTERY$
LogError "System auf Akku - Abbruch"
SetActionProgress "Fail: Akkubetrieb"
sleepSeconds 10
isSuspended
else
comment "System is on powersupply..."
ShowBitmap "%ScriptPath%\SPMS\" + "icon_power_onpower.png" $ProductName$
message $MSG_POWERCHECK_ONSUPPLY$
endif
; ----------------------------------------------------------------------------------
; Loglevel und Grafik wieder auf vorherigen Wert zuruecksetzen
; ----------------------------------------------------------------------------------
ShowBitmap "%ScriptPath%\SPMS\" + "icon.png" $ProductName$
Setloglevel = $LogLevelBefore_powersupplyins$
else
; ToDo: Language-Files anpassen (es-es,fr-fr,it-it,de-de,en-us)
message "System ohne Akku - alles okay"
sleepSeconds 2
endif
; ----------------------------------------------------------------------------------
; Ablauf beendet
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; Sektionen
; ----------------------------------------------------------------------------------
[DosInAnIcon_setpolicy]
echo "powershell set-executionpolicy RemoteSigned ..."
powershell.exe set-executionpolicy RemoteSigned
exit %ERRORLEVEL%
[execwith_powershell_architecture]
echo "powershell opsi-winst-test"
$psversion
$psversiontable
#start-process -wait cmd.exe
$is64BitSystem = ($env:Processor_Architecture -ne "x86")
$is64BitPowerShell = [IntPtr]::Size -eq 8
$env:Processor_Architecture
[IntPtr]::Size
$is64BitSystem
$is64BitPowerShell
gwmi win32_battery
[execwith_powershell_checkpowersupply]
echo "powershell Powertest"
gwmi -Class batterystatus -Namespace root\wmi
Viel Spaß