Page 1 of 1 1
Topic Options
#48185 - 1999-09-22 11:21 AM Spawning new processes
Anonymous
Unregistered


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


Top
#48186 - 1999-09-24 02:11 AM Re: Spawning new processes
Anonymous
Unregistered


you also could start this script with:

run "kix32.exe daemon.kix $variable1=.."

from within the logon script, as the run command just starts a program and directly continues with the script it can run parallel and will not stop after the logon script ends..

------------------
Lon Geefshuysen (MCP)
kixtart.to/lon
lon@kixtart.to


Top
#48187 - 1999-09-24 11:49 AM Re: Spawning new processes
Anonymous
Unregistered


You da man Lon, thanks.
I'll give it a try

Top
#48188 - 1999-09-29 03:57 PM Re: Spawning new processes
Anonymous
Unregistered


Okay I got it working good now.
I'm even working on converting it into a command-scheduler (besides instant on-demand commands).

My current problem is that when the user wants to shutdown windows... well having a hidden kix32 running in the background causes Windows to spaz out about a program running in the background, then prompts for an "OK" and an "END TASK" (you probabaly all know the routine). Is there any way that anyone knows of to make Kixtart aware that the system is trying to shut-down so it can shut itself down.. ?

Thanks, -Sven

Top
#48189 - 1999-10-01 01:27 PM Re: Spawning new processes
Anonymous
Unregistered


Svendre:

Would you consider posting your successful script? I need to do something similar but am not as experinced at this code so I cannot just "figure it out" from the hints in this posting so far. What I need is to be able to spawn off a process that I do not want to start running until 5 minutes after the logon has completed. BUT I need it to use the variables from the logon script as you stated in your posting. Any clues would be helpful. Thanks

Top
#48190 - 1999-10-04 11:41 AM Re: Spawning new processes
Anonymous
Unregistered


Actually, the code for the spawning stuff is not written into my daemon project (which btw is now a C++ project). I wrote it into my main kixtart script which does a lot of other things and is probably way too convoluted if you're just getting started. But here is some specific help:

1.) don't bother trying to pass the information to the clients from the run command.. start out by writing an environment variable with the information you want.

example:
shell @LDRIVE + "\bin\winset.exe pdc_server=qix"

Now you have the environment variable %pdc_server% which = "qix" on your client.

Next, spawn the process which sleeps for 5 minutes then executes a command..

$netlog = "@LDRIVE"
$script_name = "sleeper.kix"
run "$netlog\kix32.exe $netlog\$scriptname"

Okay now lets construct a simple sleeper.kix

sleep 300
; 5 minutes or (60 * 5) seconds
; now run your commands -- example:
shell "%comspec% /e:1024 /c biteme.exe /switch:%pdc_server%"
or
copy "\\%pdc_server%\sharename\myfile.ext" "c:\myfile.ext"

etc etc, you get the idea

Also, check out the kixtart manual kix95.doc, I find that it is generally very helpful.

(note: I didn't actually test these commands, so it wouldn't hurt to doublecheck me)

-Sven



Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.05 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org