[Actions]
requiredWinstVersion >= "4.11.2.1"
 
setLogLevel=7
DefVar $ProductId$
DefVar $ProductName$
DefVar $OpsiAdminPass$
DefVar $local_user$
DefVar $AdminGroup$
DefVar $SearchResult$
DefVar $flag_active$
DefVar $val_userpasswd$
DefVar $val_username$
DefVar $UserExists$
DefVar $LocalTempPath$
DefStringlist $ResultList2$

; The token BUILDER_VARIABLES will be replaced by opsi-builder.sh
; and adds the following variables:
;   from builder-product.cfg :  all variables definded by attribute WINST[index]
;   from builder-product.cfg :  VENDOR PN VERSION RELEASE PRIORITY ADVICE TYPE   
;   from opsi-builder.cfg    :  CREATOR_TAG CREATOR_NAME CREATOR_EMAIL           
;   auto generated winst-variables
;         $IconFile$: path to product picture
;
@@BUILDER_VARIABLES@@
 
sub_get_properties
 
comment "Check if user exists."
set $ResultList2$ = getOutStreamFromSection("DosInAnIcon_checkuser")
set $UserExists$ = takeString(0,$ResultList2$)
set $UserExists$ = takeString(0,splitstring($UserExists$," "))
 
 
if $UserExists$ = "yes"
	DosInAnIcon_deleteuser
else
	LogError "User '" + $local_user$ + "' does not exist!" 
	isFatalError
endif
 
 
[sub_get_properties]
comment "val_username"
comment "description: username"
set $local_user$= GetProductProperty("val_username", "locsupp")
 
[DosInAnIcon_checkuser]
@echo off
net user $local_user$ >nul 2>&1 && echo yes || echo no
 
[DosInAnIcon_deleteuser]
NET USER $local_user$ /DELETE
 
[DosInAnIcon_deleteprofile]
rmdir /S /Q "%ProfileDir%\$local_user$"
