This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
userspace:winst32_preproc.exe [2019/10/25 14:43] pandel [Winst32 Preprocessor] |
userspace:winst32_preproc.exe [2021/08/23 08:37] (current) |
||
---|---|---|---|
Line 5: | Line 5: | ||
At the moment it is capable of: | At the moment it is capable of: | ||
* Checking registry values before starting WINST as a action precondition | * Checking registry values before starting WINST as a action precondition | ||
+ | * Checking list of running processes before starting WINST as a action precondition | ||
* Setting registry values before and/or after starting WINST | * Setting registry values before and/or after starting WINST | ||
* Logging current product configuration of the client and the action request(s) being processed | * Logging current product configuration of the client and the action request(s) being processed | ||
- | [[winst32_preproc.exe# | + | **But beware:** |
- | __**BUT BEWARE - DONT' BREAK YOUR ENVIRONMENT: | + | __**It is ABSOLUTELY |
- | + | ||
- | __**THIS | + | |
__**THIS IS NOT FOR THE FAINT-HEARTED AND YOU SHOULD BE ABSOLUTELY SURE OF WHAT YOU ARE DOING! I WILL NOT GIVE ANY IN-DEPTH EXPLANATION FOR THE NEWBY USERS!**__ | __**THIS IS NOT FOR THE FAINT-HEARTED AND YOU SHOULD BE ABSOLUTELY SURE OF WHAT YOU ARE DOING! I WILL NOT GIVE ANY IN-DEPTH EXPLANATION FOR THE NEWBY USERS!**__ | ||
Line 28: | Line 27: | ||
v1.0, Tested with Windows 10 x64 1809 Enterprise | v1.0, Tested with Windows 10 x64 1809 Enterprise | ||
--- // | --- // | ||
+ | |||
+ | v1.1, Tested with Windows 10 x64 1809 Enterprise | ||
+ | --- // | ||
==== Motivation ==== | ==== Motivation ==== | ||
Line 41: | Line 43: | ||
The preprocssor is run instead of the original winst32.exe via opsiclientd and takes control over the execution of winst32.exe based on registry checks itself. It acts as a wrapper to winst32.exe. | The preprocssor is run instead of the original winst32.exe via opsiclientd and takes control over the execution of winst32.exe based on registry checks itself. It acts as a wrapper to winst32.exe. | ||
Everything is controlled via a single configuration file. | Everything is controlled via a single configuration file. | ||
+ | |||
+ | You can create an example configuration file in the same directory by running winst32_preproc.exe without any command line parameter. | ||
=== Where to install === | === Where to install === | ||
Line 71: | Line 75: | ||
<code text> | <code text> | ||
------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | ||
- | winst32_preproc (MIT licensed) v1.0.0.0 Command Line | + | winst32_preproc (MIT licensed) v1.1.0.0 Command Line |
Available command line options: | Available command line options: | ||
Line 106: | Line 110: | ||
==== The configuration: | ==== The configuration: | ||
- | The structure of the configuration file is rather simple. It consists of three blocks: | + | The structure of the configuration file is rather simple. It consists of five blocks: |
+ | * general - logging configuration and version information | ||
* registry_check - registry value(s) that should be checked to decide if winst32.exe is being executed | * registry_check - registry value(s) that should be checked to decide if winst32.exe is being executed | ||
* registry_pre - registry value(s) that should be set BEFORE winst32.exe is being executed | * registry_pre - registry value(s) that should be set BEFORE winst32.exe is being executed | ||
* registry_post - registry value(s) that should be set AFTER winst32.exe is being executed | * registry_post - registry value(s) that should be set AFTER winst32.exe is being executed | ||
+ | * process_check - list of processes that should be checked to decide if winst32.exe is being executed | ||
=== How the blocks work === | === How the blocks work === | ||
Line 116: | Line 122: | ||
The keys and values you specify here will be checked for their existance AND values. They a treated as ONE single result, that means, if you specify multiple values to check for and one (ore more) values cannot be read or found, this check is considered " | The keys and values you specify here will be checked for their existance AND values. They a treated as ONE single result, that means, if you specify multiple values to check for and one (ore more) values cannot be read or found, this check is considered " | ||
+ | |||
+ | == process_check == | ||
+ | |||
+ | The process names you specify here will be checked if they are running. They a treated as ONE single result, that means, if you specify multiple process names to check for and one (ore more) will found, this check is considered " | ||
== registry_pre / registry_post == | == registry_pre / registry_post == | ||
Line 122: | Line 132: | ||
== Configuration values == | == Configuration values == | ||
+ | |||
+ | __Registry checks__ | ||
A configuration entry like | A configuration entry like | ||
Line 137: | Line 149: | ||
In general, a single line can be seen as: | In general, a single line can be seen as: | ||
- | <code text> | + | <code text> |
== Possible registry leaf values: == | == Possible registry leaf values: == | ||
Line 160: | Line 172: | ||
* REG_DWORD | * REG_DWORD | ||
* (REG_MULTI_SZ can be specified, but you are only able to read or set the first element, so it is not very useful here.) | * (REG_MULTI_SZ can be specified, but you are only able to read or set the first element, so it is not very useful here.) | ||
+ | |||
+ | __Process checks__ | ||
+ | |||
+ | Process checks are much simpler: | ||
+ | |||
+ | A line like | ||
+ | <code text> | ||
+ | will check, if winword.exe is found in the list of active processes. | ||
=== Example === | === Example === | ||
Line 165: | Line 185: | ||
<file ini winst32_preproc.ini> | <file ini winst32_preproc.ini> | ||
[general] | [general] | ||
+ | version=1.1.0.0 | ||
logInstalled=1 | logInstalled=1 | ||
logActions=1 | logActions=1 | ||
Line 174: | Line 195: | ||
[registry_pre] | [registry_pre] | ||
count=2 | count=2 | ||
- | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|1 | + | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|1|REG_SZ |
reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|1|REG_SZ | reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|1|REG_SZ | ||
[registry_post] | [registry_post] | ||
count=3 | count=3 | ||
- | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|0 | + | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|0|REG_SZ |
reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|0|REG_SZ | reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|0|REG_SZ | ||
reg3=HKLM|32|SOFTWARE\Somewhere\Else|SomeOtherValue|50|REG_DWORD | reg3=HKLM|32|SOFTWARE\Somewhere\Else|SomeOtherValue|50|REG_DWORD | ||
+ | |||
+ | [process_check] | ||
+ | count=1 | ||
+ | proc1=svchost.exe | ||
</ | </ | ||
Line 188: | Line 213: | ||
// | // | ||
- | __What | + | What this example will do (in pseudo-lingo): |
<code text> | <code text> | ||
- | if " | + | if (" |
log currently installed products on client | log currently installed products on client | ||
log current action requests | log current action requests | ||
Line 219: | Line 244: | ||
<file ini winst32_preproc.ini> | <file ini winst32_preproc.ini> | ||
[general] | [general] | ||
+ | version=1.1.0.0 | ||
logInstalled=1 | logInstalled=1 | ||
logActions=1 | logActions=1 | ||
Line 228: | Line 254: | ||
[registry_pre] | [registry_pre] | ||
count=2 | count=2 | ||
- | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|1 | + | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|1|REG_SZ |
reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|1|REG_SZ | reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|1|REG_SZ | ||
[registry_post] | [registry_post] | ||
count=3 | count=3 | ||
- | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|0 | + | reg1=HKLM|64|SOFTWARE\RZ\FSV|FSVActive|0|REG_SZ |
reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|0|REG_SZ | reg2=HKLM|64|SOFTWARE\opsi.org\Winst|Active|0|REG_SZ | ||
reg3=HKLM|32|SOFTWARE\Somewhere\Else|SomeOtherValue|50|REG_DWORD | reg3=HKLM|32|SOFTWARE\Somewhere\Else|SomeOtherValue|50|REG_DWORD | ||
+ | |||
+ | [process_check] | ||
+ | count=1 | ||
+ | proc1=svchost.exe | ||
</ | </ | ||
Line 267: | Line 297: | ||
; appplication title and version | ; appplication title and version | ||
Global $header = " | Global $header = " | ||
- | Global $version = "1.0.0.0" | + | Global $version = "1.1.0.0" |
Global $logdir = @TempDir & " | Global $logdir = @TempDir & " | ||
Global $log_mode = True ; write log file = true | Global $log_mode = True ; write log file = true | ||
Line 285: | Line 315: | ||
Global $test = True | Global $test = True | ||
+ | Local $msg = ' | ||
+ | $msg &= $header & ' v' & $version & ' Command Line' & @CRLF & @CRLF ; Message. | ||
+ | |||
+ | ; Load ini data | ||
Global $iniName = " | Global $iniName = " | ||
+ | _getIniValues($iniName) | ||
; let's have a look at the CmdLine | ; let's have a look at the CmdLine | ||
If $CmdLine[0] = 0 Then | If $CmdLine[0] = 0 Then | ||
- | Local $msg = ' | ||
- | $msg &= $header & ' v' & $version & ' Command Line' & @CRLF & @CRLF ; Message. | ||
$msg &= "No arguments passed. See -h for help or use -d for a test run. Exiting." | $msg &= "No arguments passed. See -h for help or use -d for a test run. Exiting." | ||
ConsoleWrite($msg) | ConsoleWrite($msg) | ||
Exit 0 | Exit 0 | ||
+ | Else | ||
+ | _debug($msg) | ||
EndIf | EndIf | ||
Line 307: | Line 342: | ||
_debug(" | _debug(" | ||
_debug(" | _debug(" | ||
- | |||
- | ; Load ini data | ||
- | _getIniValues($iniName) | ||
; for debugging purpose | ; for debugging purpose | ||
Line 319: | Line 351: | ||
; ---- MAIN --------- | ; ---- MAIN --------- | ||
- | ; run registry tests | ||
If x($iniName & " | If x($iniName & " | ||
- | $isRegOk = _runRegistryCheck() | + | Local $isRegOk = _runRegistryCheck() |
If $isRegOk Then | If $isRegOk Then | ||
_debug(" | _debug(" | ||
Line 330: | Line 361: | ||
EndIf | EndIf | ||
- | ; test ? | + | If x($iniName & " |
+ | Local $isProcOk = _runProcessCheck() | ||
+ | If $isProcOk Then | ||
+ | _debug(" | ||
+ | Else | ||
+ | _debug(" | ||
+ | _exit(0) | ||
+ | EndIf | ||
+ | EndIf | ||
+ | |||
if $test Then | if $test Then | ||
+ | ; test run | ||
$Cmdout = '"' | $Cmdout = '"' | ||
_debug("" | _debug("" | ||
Line 357: | Line 399: | ||
_exit(0) | _exit(0) | ||
Else | Else | ||
+ | ; production run | ||
If x($iniName & " | If x($iniName & " | ||
If x($iniName & " | If x($iniName & " | ||
Line 372: | Line 415: | ||
Func _runRegistryCheck() | Func _runRegistryCheck() | ||
Local $rc = False | Local $rc = False | ||
- | _debug(" | + | _debug(" |
If x($iniName & " | If x($iniName & " | ||
Line 406: | Line 449: | ||
return $rc | return $rc | ||
+ | EndFunc | ||
+ | |||
+ | ; check if specified process exist | ||
+ | Func _runProcessCheck() | ||
+ | Local $rc = False | ||
+ | _debug(" | ||
+ | |||
+ | If x($iniName & " | ||
+ | _debug(" | ||
+ | return True | ||
+ | EndIf | ||
+ | |||
+ | ; Example entry: proc1=winword.exe | ||
+ | For $i = 1 To x($iniName & " | ||
+ | Local $a = x($iniName & " | ||
+ | _debug(" | ||
+ | Local $pid = ProcessExists($a) | ||
+ | If $pid > 0 Then | ||
+ | $rc = False | ||
+ | _debug(" | ||
+ | _debug(" | ||
+ | return $rc | ||
+ | Else | ||
+ | $rc = True | ||
+ | _debug(" | ||
+ | return $rc | ||
+ | EndIf | ||
+ | Next | ||
EndFunc | EndFunc | ||
Line 632: | Line 703: | ||
Else ;--- INI not existing, creating new one in script directory | Else ;--- INI not existing, creating new one in script directory | ||
- | $msg = "INI file not found: " & $iniFile | + | $msg = "INI file not found: " & $iniFile |
- | _debug($msg) | + | "A new INI file with example values will be created in the script directory." |
- | _exit(1) | + | " |
+ | ConsoleWrite($msg) | ||
+ | _createIni($appPath & $iniName) | ||
EndIf | EndIf | ||
Line 657: | Line 731: | ||
If (@error) Then Return SetError(2, 0, "Error on send") | If (@error) Then Return SetError(2, 0, "Error on send") | ||
- | If ($REST.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, "Error on request" | + | If ($REST.Status <> $HTTP_STATUS_OK) Then Return SetError(3, 0, "Error on request |
return $REST.ResponseText | return $REST.ResponseText | ||
Line 734: | Line 808: | ||
Exit $rc | Exit $rc | ||
EndFunc | EndFunc | ||
+ | |||
+ | ; create default example ini file | ||
+ | Func _createIni($ini) | ||
+ | |||
+ | x($ini & " | ||
+ | x($ini & " | ||
+ | x($ini & " | ||
+ | |||
+ | x($ini & " | ||
+ | |||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | |||
+ | x($ini & " | ||
+ | |||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | |||
+ | x($ini & " | ||
+ | |||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | |||
+ | x($ini & " | ||
+ | |||
+ | Local $a = [" | ||
+ | x($ini & " | ||
+ | |||
+ | _WriteAssocToIni($ini) | ||
+ | EndFunc | ||
+ | |||
; --------------------------------------------------------------------------------------------------------------------- | ; --------------------------------------------------------------------------------------------------------------------- | ||
; ---- TOOLS --------- | ; ---- TOOLS --------- |