Ok I wrote this really funky code I call "daemon"... it's supposed to run in the background and at particular intervals it wakes up and looks at an .ini file for the particular domain the hosts is in. Problem-- it needs to continue running after the logon script is done processing. So I've concluded that I'll have to start it up seperately from the logon script (write a command into the registry's run/runservices etc) The things I don't like about that solution are that at startup, it won't have access to all the variables I have defined in my main logon script, it also means that it won't run until the next time they reboot. I also considered sticking it in win.ini under load= run= which solves the issue of rebooting but then I don't want to clash with any other crap in there.

How can I run this script and let it continue running while the logon script completes?

I am thinking I may have to rewrite this in C++.....any comments are welcome

Here's the code:


; /* Try to run this as a background process */
?"Executing Kix Daemon"
$continue=1

; These variables are used by the main logon script....but I have to set them locally
; until I can get this script to run from the main logon script
; CID = Command Identifier (I made up this terminology :p )

DIM $reg_location = "HKEY_LOCAL_MACHINE\SOFTWARE\MIS"
DIM $domain_location = "y:\settings\mis_corp.ini"

$interval = 5
$shell_comspec = %comspec%
?"shell_comspec = $shell_comspec"

;redirect output
setconsole("HIDE")


; /* MAIN */
:main
gosub "initialize"
gosub "read_cid_info"
gosub "read_interval"

If ($host_cid <> $server_cid) and ($server_cid <> "")
?"Processing new cid#: $server_cid"
gosub "exec_shell"
gosub "write_cid"
Endif

sleep $interval
? ?"Looping..."
goto "main"
exit


:initialize
; /* Wipe out the variables -- just in case */
$server_cid=""
$host_cid=""
$shell_cmd=""
Return


:read_cid_info
; /* Reads a command id# (cid#) from domain.ini located on the logon server */
; /* Reads a command id# (cid#) from the registry of the local host */
; /* Reads the value of shell_cmd which is the command line to be executed on the host */

; /* Read a command id# from the domain.ini located on the logon server */
$server_cid = ReadProfileString("$domain_location", "Daemon", "cid")
If @ERROR = 0
?"Server cid# = $server_cid"
Else
?"Error reading cid# from server"
? "@SERROR"
Return
Endif

; /* Read the host's registry for the value of the last processed cid# */
$host_cid = Readvalue("$reg_location\Tracking", "cid")
If @ERROR = 0
?"Host cid# = $host_cid"
Else
?"Error reading host cid#"
?"@SERROR"
EndIf

; /* Read the value of shell_cmd which is the command line to be executed on the host */
; /* Add support for more specific types */
; $kix_cmd
$shell_cmd=ReadProfileString("$domain_location", "Daemon", "shell_cmd")
If @ERROR = 0
; /* Value read okay */
?"Read shell_cmd from server: $shell_cmd"
Else
; /* Error reading the shell-command */
?"Error reading shell_cmd from domain.ini file"
? "@SERROR"
Return
Endif
Return

:read_interval
; /* Read the value of the daemon interval which controls how often the program checks cids */

$new_interval=ReadProfileString("$domain_location", "Daemon", "interval")
If @ERROR = 0
; /* Value read okay */
$interval = $new_interval
?"Interval = $interval"
Else
; /* Error reading the shell-command */
?"Error reading interval from domain.ini file"
? "@SERROR"
Return
Endif
Return


:exec_shell
?"Executing shell command: $shell_cmd"
shell "$shell_comspec /e:1024 /c $shell_cmd"
; replace c:\command.com with a variable specifying the particular OS shell's COMSPEC
Return

:write_cid
$Rtn = WriteValue("$reg_location\Tracking", "cid", "$server_cid", "REG_SZ")
If @ERROR = 0
?"Wrote to host new cid#: $server_cid"
Else
? "Error updating host for cid#: $server_cid"
? "@SERROR"
EndIf
Return