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 16:24] pandel old revision restored (2019/10/25 18:22) |
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 65: | Line 69: | ||
This example expects winst32_preproc.exe and its ini file in %global.base_dir% (see opsiclientd.conf). If you put it somewhere else, modify the line accordingly. | This example expects winst32_preproc.exe and its ini file in %global.base_dir% (see opsiclientd.conf). If you put it somewhere else, modify the line accordingly. | ||
- | ==== Command line parameters | + | === Command line parameters === |
The program contains a short help regarding the command line parameters. Simply issue " | The program contains a short help regarding the command line parameters. Simply issue " | ||
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 88: | Line 92: | ||
</ | </ | ||
- | ==== Standard mode = Test mode ==== | + | === Standard mode = Test mode === |
For security reasons, the default mode of winst32_preproc ist test mode. That means, if you not explicitely specify production mode via command line, the program will only show you what would happen, but don't actually do anything. So, if you have configured the ini file according to your needs you can simple put both files in a directory on your test client and start the program from an administrator console to test it. | For security reasons, the default mode of winst32_preproc ist test mode. That means, if you not explicitely specify production mode via command line, the program will only show you what would happen, but don't actually do anything. So, if you have configured the ini file according to your needs you can simple put both files in a directory on your test client and start the program from an administrator console to test it. | ||
Line 97: | Line 101: | ||
* opsi config service url: https:// | * opsi config service url: https:// | ||
- | Now execute a test run and get detailed information on the console like so: | ||
<code text> | <code text> | ||
winst32_preproc.exe -d -t -f=" | winst32_preproc.exe -d -t -f=" | ||
</ | </ | ||
- | **NOTE: the path to winst32.exe must be correct, otherwise | + | **NOTE: the path to winst32.exe must be the right one, otherwise |
- | **NOTE2: production is activated via " | + | |
==== 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 117: | 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 123: | Line 132: | ||
== Configuration values == | == Configuration values == | ||
+ | |||
+ | __Registry checks__ | ||
A configuration entry like | A configuration entry like | ||
Line 161: | 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 === |
<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 183: | Line 203: | ||
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 189: | 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 220: | 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 237: | Line 262: | ||
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 259: | Line 288: | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include " | + | #include "UDFs\AssoArrays.au3" |
- | #include " | + | #include "UDFs\GetOpt.au3" |
- | #include " | + | #include "UDFs\json.au3" |
Global Const $HTTP_STATUS_OK = 200 | Global Const $HTTP_STATUS_OK = 200 | ||
Line 268: | 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 286: | 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 308: | Line 342: | ||
_debug(" | _debug(" | ||
_debug(" | _debug(" | ||
- | |||
- | ; Load ini data | ||
- | _getIniValues($iniName) | ||
; for debugging purpose | ; for debugging purpose | ||
Line 320: | 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 331: | 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 358: | Line 399: | ||
_exit(0) | _exit(0) | ||
Else | Else | ||
+ | ; production run | ||
If x($iniName & " | If x($iniName & " | ||
If x($iniName & " | If x($iniName & " | ||
Line 373: | Line 415: | ||
Func _runRegistryCheck() | Func _runRegistryCheck() | ||
Local $rc = False | Local $rc = False | ||
- | _debug(" | + | _debug(" |
If x($iniName & " | If x($iniName & " | ||
Line 407: | 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 633: | 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 658: | 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 735: | 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 --------- |