Page 1 of 1 1
Topic Options
#47952 - 1999-07-12 05:14 PM Engine
Anonymous
Unregistered


Here's a script I wrote which does several things.. the main point being that it controls the handling of running other kixtart scripts and batch files. I wrote it so that at the end of the kixtart scripts you set $continue=1 to allow the processing of the other scripts to continue. I plan to make this an option so that you can specify whethor or not the sub-script should be run in the background or sequentially (which is useful when you have scripts that depend on other scripts to be completely finished first) There is also a feature for scripts to automatically write staging information to the registry for times when you want your sub-scripts to run in multiple stages (for instance when reboots are needed between stages) You enter a line $stage_completed="x" where x is a number or "finished" in which case the script will never be run again. It also has a feature that saves history logfiles when staging information changes are made. The standard logfile is placed in a hidden folder named "c:\logfiles" and the logfile is named "logon.txt"--it contains redirected output from all the subscripts that you add. The set of scripts to be run, and the environment settings are all contained in a files named "domainname.ini" in a settings folder. This whole structure of settings files and scripts is all contained within the replication path. There is also some test-phase stuff I'm writing to track computers based on their IP address to determine if they are logging into their local server or logging in accross a WAN connection. Actually there is quite a bit of explaining I could do but I'll just post it and maybe some of you will be able to learn some tricks from it and maybe some of you can suggest tips for me.

(BTW, I have written about 15 or so scripts that do various tasks)

Here is an example of the directory structure:

//server/netlogon
[settings] - directory for domain settings files
[standard] - directory for subscripts and batch files

kixtart.kix - main engine script
kix32 - (kixtart exe)

Here is a sample settings file:
[General]
domain=PF
location=Corporate
branch_number=1
division=Corporate

[Servers]
pdc_server=hermana
bdc1_server=scarlett
bdc2_server=boris
bdc3_server=sb_server
loans_server=challenger
prospect_server=pf_prospect
inventory_server=challenger
proxy_server=boris

[Antivirus]
antivirus_server=norad
av_server_ip=172.16.101.254
antivirus_domain=Corporate

[Mappings]


; Enter the run-order for kixtart and dos batch logon script files in the Searchlist.
; By default, if a custom script for a searchlist entry is found, the custom script
; will be executed instead of the corresponding standard script. If no custom script
; is found, then the corresponding standard script will attempt to run.
;
; Standard scripts by default are located in c:\winnt\system32\repl\import\scripts\standard
; Custom scripts by default are located in c:\logon\custom
;
; (not implemented yet)
; By default kixtart scripts are run sequentially (with exception of shell and run commands)
; An entry in the searchlist of %scriptname.xxx specifies that the kixtart script should
; be run as a background process (for faster logon processing).
;
; Kixtart scripts must contain $continue=1 before they return or processing will not resume!
; Searchlist entries beyond 99 are currently not valid

[Searchlist]
1=set_environment.kix
2=map_drives.kix
3=remove_landesk.kix
4=install_viruscan.kix
5=set_proxy.kix
6=update_office.bat
7=update_mdac.kix
8=setup_odbc.kix
9=sa.bat
10=set_time.bat


Here is the main kixtart engine:

;Kixtart Main Logon Script
;
;Description:
;
;
;Revision History
;
;6/15/99 KT created
;
;

; /* Set user defined variables */

$settings_directory = "@LDRIVE\settings"

$std_directory = "@LDRIVE\standard"
$cust_directory = "@LSERVER\logon\custom"
$updates_directory = "@LDRIVE\updates"
$logfile_directory = "c:\logfiles"
$tagfile_directory = "c:\"
$index_directory = "@LDRIVE\settings"

$logfile = "logon.txt"
$index = "index.ini"

$loans_drive = "e:"
$prospect_drive = "g:"

$tagfile_share = "tagfiles"
$loans_share = "pf_data"
$prospect_share = "pf_data"

$reg_location = "HKEY_LOCAL_MACHINE\SOFTWARE\MIS"
$proxy_port = "80"
$sql_server = "dasher"


; /* Set mandatory variables */

$local_domain = "@DOMAIN"
$ini = "$local_domain" + ".ini"
$ini_location = "$settings_directory\$ini"
$ini_unc = "@LSERVER\netlogon\settings\$ini"
$logfile_unc = "$logfile_directory\$logfile"
$index_unc = "$index_directory\$index"
$error_msg = ""
$save_log = ""

; /* MAIN */

gosub "verify_ini"

gosub "create_logfile"

; /* Create registry keys for script updates and tracking */
$subkey = "$reg_location"
gosub "create_key"
$subkey = "$reg_location\Updates"
gosub "create_key"
$subkey = "$reg_location\Tracking"
gosub "create_key"

gosub "track_domain"

; /* Load and execute the searchlist */
; /* Obtain a string containing all keys in the searchlist section of the initialization file */
$search_keys=ReadProfileString("$ini_location", "Searchlist", "")
; /* Assign last_key a value based upon the last two characters of search_keys */
$last_key=val(substr($search_keys, len($search_keys) - 2, 2))

? "Executing searchlist from $ini_unc"
; /* Run the scripts in the order found in searchlist */
$run_key=1
while ($run_key <= $last_key)

$run_script = ReadProfileString("$ini_location", "Searchlist", "$run_key")
$script_extension = substr($run_script, len($run_script) -3, 4)
$script_name = substr($run_script, 1, len($run_script) -4)
$stage_completed = ""
$error_msg = ""
$finished_msg = ""
$stage_msg = ""

; /* Read the current script stage completed information */
$stage_completed = Readvalue("$reg_location\Updates", "$script_name")
If @ERROR = 0
$stage_msg = $stage_completed
Else
$stage_msg = "none"
; /* No stage key has been written */
EndIf

; /* Check for existance of the finished flag, if found don't run the current script */
If $stage_completed = "finished"
$script_extension = "skip"
EndIf

; /* Determine if a custom script exists */
If exist("$cust_directory\$run_script") = 1
$script_location = "$cust_directory"
$location_msg = "$cust_directory"
Else
If exist("$std_directory\$run_script") = 1
$script_location = $std_directory
$location_msg = "@LSERVER\netlogon\standard"
Else
; /* If a script isn't found, flag an error */
$error_msg="Warning: Script not found"
$script_extension = "skip"
Endif
Endif
? ?"[$run_key:$location_msg\$run_script] $error_msg"
? "[Stages completed: $stage_msg]"

Select
Case $script_extension = ".kix"
call "$script_location\$run_script"
gosub "wait"
Case $script_extension = ".bat"
shell "c:\command.com /e:1024 /c $script_location\$run_script"
; /* Script has finished, do not run again */
EndSelect

; /* Write any new stage completed information returned by the subscript */
If ($stage_completed <> "") and ($script_extension = ".kix")
; /* Write the current value of stage_completed */
$Rtn = WriteValue("$reg_location\Updates", "$script_name", "$stage_completed", "REG_SZ")
If @ERROR = 0
? "[Stage completed key $script_name set to: $stage_completed]"
Else
? "[Error updating stage completed key: $script_name]"
? "[@SERROR]"
Endif
; /* Because staging info was updated for a kixtart script, */
; /* flag this logon script's logfile to be saved in history */
? "[Logfile will be saved to history]"
$save_log = "yes"
Endif
$run_key=$run_key+1
loop

?
? "Script searchlist execution completed successfully"

gosub "save_history"

; /* EXIT MAIN */
exit


:create_key
; /* Verifies the existance of a registry subkey and creates it if not found */
; /* Uses value: $subkey */

$ReturnCode = ExistKey("$subkey")
If $ReturnCode = 0
? "Found: $subkey"
Else
? "Missing: $subkey"
; /* add the key | writevalue ("subkey", "entry, "expression", "data type") */
$ReturnCode = AddKey("$subkey")
If $ReturnCode = 0
? "Created: $subkey"
Else
? "Cannot create: $subkey"
? "Error: @SERROR"
Endif
Endif
Return

:verify_ini
; /* Verifies the existance of the initialization file */
$Rtn = 1
$Rtn = Exist ("$ini_location")
If $Rtn = 0
? "SEVERE ERROR: $ini_unc not found"
? "Please contact the MIS Dept."
Exit
Endif
Return


:create_logfile
; /* Verifies the logfile directory exists on client, else create and hide it */

$Returncode = 1
$Returncode = Exist ("$logfile_directory")
If $Returncode = 0
md "c:\logfiles"
run "c:\windows\command\attrib.exe +h c:\logfiles"
Endif

; /* Redirect output of the screen to the logfile */
If RedirectOutput ("$logfile_unc", 1) = 0
"Main logon routine logfile created " + @DATE + " " +@TIME
If $Returncode = 0
? "Created: $logfile_unc"
Endif
Else
? "$logfile_unc could not be written, please contact the MIS"
? "Error: @SERROR"
Exit
Endif
Return


:track_domain
; /* Determine host IP address */
$ip_oct1 = Ltrim(substr(@IPADDRESS0, 1, 3))
$ip_oct2 = Ltrim(substr(@IPADDRESS0, 5, 3))
$ip_oct3 = Ltrim(substr(@IPADDRESS0, 9, 3))
$ip_oct4 = Ltrim(substr(@IPADDRESS0, 13, 3))

$local_domain = "@DOMAIN"
; /* Gather RPC information */
$logon_domain = "@LDOMAIN"

; /* Obtain the IP network for the local domain */
$index_ip_addr = ReadProfileString("$index_unc", "Networks", "$local_domain")

; /* If this host has an IP address, then use the local domain name to determine initialization */
If val($ip_oct3) <> 0
$host_ip_addr="$ip_oct1.$ip_oct2.$ip_oct3.$ip_oct4"

; /* Here's where we could do some serious system tracking */
; The index file provides us with the IP network of the domain they are logging into.
; We could compare this to their real IP network to determine if they are logging into
; their local domain on their LAN or to a remote domain across the WAN.

; Once a method of parsing the IP address from a ping'ed logon server is written,
; then there is no more need for an index file to be maintained
Else
; /* Host only has netbeui */
$host_ip_addr="none"
; /* Log this computername to a central logon logfiles location for review */
Endif

? "Host domain: $local_domain"
? "Logon domain: $logon_domain"
? "Host IP: $host_ip_addr"
? "Index IP: $index_ip_addr"

If $logon_domain = ""
? "Warning: Logon server @LSERVER is not configured for Kixtart RPC"
Else
If $logon_domain <> $local_domain
? "Warning: Host is not configured to log into domain $logon_domain"
Endif
Endif
Return


:wait
; /* Wait pauses script execution until the $continue variable is set to 1 */
do
;nothing
until $continue=1
$continue=0
; /* Resume logging to the main logfile (append) */
;$Returncode = RedirectOutput ("$logfile_unc", 0)
return

:save_history
If $save_log = "yes"
; Generate a unique filename based on the date/time
$date = "@DATE"
$sub_date = substr($date, 6, 2) + substr($date, 9, 2) + substr($date, 3, 2)
$time = "@TIME"
$sub_time = substr($time, 1, 2) + substr ($time, 4, 2) + substr($time, 7, 2)
$date_time= "$sub_date" + "-" + "$sub_time" + ".txt"
? "[Saving logfile to history: $logfile_directory\$date_time]"
; Close the file
$Rtn = RedirectOutput ("")
copy "$logfile_unc" "$logfile_directory\$date_time"
EndIf
Return


In order for this to be really useful I also have to include the set_environment sub-script (which is a bit messy to say the least...heh) In fact it REALLY needs to be cleaned up heheh oh well

; /* LOAD ENVIRONMENT SETTINGS */
;
;Description:
;
;
;Revision History
;
;5/27/99 KT created
;
;
;
;
; Special notes regarding the environment in Kixtart:
; Environment variables set by this program do not take effect until
; after Kixtart exits and the login procedure has ended.
;
; Environment variables will work from any batch file called by
; the Kixtart scripts using the run or shell commands.
;
; To reference environment settings from within Kixtart scripts, use the program
; variable which corresponds to the environment variable's name.
; example: $pdc_server instead of %pdc_server%
;
;**************************************
;
; /* MAIN */

? "Environment settings logfile entry created " + @DATE + " " +@TIME

? "Setting local environment"

; /* Read the settings from the initialization file */
? "Reading environment settings from $ini_unc"

;While @ERROR = 0

; /* General settings */
$location = ReadProfileString("$ini_location", "General", "location")
$branch_number = ReadProfileString("$ini_location", "General", "branch_number")
$division = ReadProfileString("$ini_location", "General", "division")

; /* Server settings */
$pdc_server = ReadProfileString("$ini_location", "Servers", "pdc_server")
$bdc1_server = ReadProfileString("$ini_location", "Servers", "bdc1_server")
$bdc2_server = ReadProfileString("$ini_location", "Servers", "bdc2_server")
$bdc3_server = ReadProfileString("$ini_location", "Servers", "bdc3_server")
$loans_server = ReadProfileString("$ini_location", "Servers", "loans_server")
$prospect_server = ReadProfileString("$ini_location", "Servers", "prospect_server")
$inventory_server = ReadProfileString("$ini_location", "Servers", "inventory_server")
$proxy_server = ReadProfileString("$ini_location", "Servers", "proxy_server")

$antivirus_server = ReadProfileString("$ini_location", "Antivirus", "antivirus_server")
$av_server_ip = ReadProfileString("$ini_location", "Antivirus", "av_server_ip")
$antivirus_domain = ReadProfileString("$ini_location", "Antivirus", "antivirus_domain")

; /* Settings completed successfully without error */
? "Standard environment variables:"
? "location=" + $location
? "branch_number=" +$branch_number
? "division=" +$division
? "pdc_server=" + $pdc_server
? "bdc1_server=" + $bdc1_server
? "bdc2_server=" + $bdc2_server
? "bdc3_server=" + $bdc3_server
? "loans_server=" + $loans_server
? "prospect_server=" + $prospect_server
? "inventory_server=" + $inventory_server
? "proxy_server=" + $proxy_server

? "antivirus_server=" + $antivirus_server
? "av_server_ip=" + $av_server_ip
? "antivirus_domain=" + $antivirus_domain

goto "NOERRORS"

; :LOOP

; :error
; /* Resume logging to the main logfile (append) */

; RedirectOutput ("c:\logfiles\logon.txt",1)
; ?"Error reading environment settings from environ.ini!
; ?"Make sure this file is present in netlogon directory and that all settings are present"
; exit


; /* Verify that no entries are blank */


:NOERRORS
; /* Set the environment */
? "Setting the environment variables..."

; /* Select method based on if the system is running Windows NT or 95 */

; /* Windows NT */
If @INWIN = 1
? "This is a Windows NT system"
;SetM ("pdc_server=" + $pdc_server)
Endif

; /* Windows 95 */
If @INWIN = 2
? "This is a Windows 95 system"

; These commands set the environment variables to function
; in dos batch files spawned by kixtart. These commands only
; have effect while kixtart is still running.

setl ("location=" + $location)
setl ("branch_number=" + $bdc2_server)
setl ("division=" + $division)

setl ("pdc_server=" + $pdc_server)
setl ("bdc1_server=" + $bdc1_server)
setl ("bdc2_server=" + $bdc2_server)
setl ("bdc3_server=" + $bdc3_server)
setl ("loans_server=" + $loans_server)
setl ("prospect_server=" + $prospect_server)
setl ("inventory_server=" + $inventory_server)
setl ("proxy_server=" + $proxy_server)

setl ("antivirus_server=" + $antivirus_server)
setl ("av_server_ip=" + $av_server_ip)
setl ("antivirus_domain=" + $antivirus_domain)

; took effect for all shells until system rebooted
; but didn't take effect until kixtart finished
; changed window name
;shell "c:\winset.exe loans_server=challenger"

; WORKED!
;shell @LDRIVE + "\bin\winset.exe pdc_server=hermana"
; Next Test...ROCK BABY!

;copy @LDRIVE\bin\winset.exe c:\windows\command


;THESE COMMANDS TOASTED A 95 BOX!! Careful..
;shell "c:\windows\command\winset.exe location=$location"
;shell (@LDRIVE + "\bin\winset.exe branch_number=$branch_number")
;shell (@LDRIVE + "\bin\winset.exe division=$division")

;shell (@LDRIVE + "\bin\winset.exe pdc_server=$pdc_server")
;shell (@LDRIVE + "\bin\winset.exe bdc1_server=$bdc1_server")
;shell (@LDRIVE + "\bin\winset.exe bdc2_server=$bdc2_server")
;shell (@LDRIVE + "\bin\winset.exe bdc3_server=$bdc3_server")
;shell (@LDRIVE + "\bin\winset.exe loans_server=$loans_server")
;shell (@LDRIVE + "\bin\winset.exe prospect_server=$prospect_server")
;shell (@LDRIVE + "\bin\winset.exe antivirus_server=$antivirus_server")
;shell (@LDRIVE + "\bin\winset.exe inventory_server=$inventory_server")


; does not work at all!
;shell "c:\command.com c:\winset.exe loans_server=nexttest"

; took effect after kixtart finished until system reboot
;shell "c:\command.com /e:1024 /c c:\winset.exe loans_server=nexttest"

;appears to do nothing
;shell "c:\command.com /e:1024 /c set loans_server=settest"

;run "c:\winset bdc_server=scarlett"
; !! Didn't take effect until next login-- held in memory !!

;sleep 3
;? "environ.kix: pdc_server= %pdc_server%"
;? "environ.kix: bdc_server= %bdc_server%"
;? "environ.kix: loans_server= %loans_server%"
Endif

? "Environment variables set"

$continue=1
Return

~~~~~~~~~~
Ok hope you found something useful in there.. if you're still reading and interested you can reach me at:
ktorkelson@providentfunding.com

Later!



Top
#47953 - 1999-07-15 01:50 AM Re: Engine
Anonymous
Unregistered


Very very nice script !!

Can you give a list of tasks these 15 other scripts do ?

(BTW: I'm collecting different kix32 scripts to put on my Website, Can I use this script to post on my website ?)

------------------
Lon Geefshuysen,
www.xs4all.nl/~longeef/NT/KiXtart
lon_geefshuysen@essentium.com



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
0 registered and 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.118 seconds in which 0.097 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