Dear,

A very important possible for config.sys is the usage of
sections, which make it possible to use the WriteProfileString
function to change a specified key.
Important in such situation is:
your CONFIG.SYS file should have a section
name before your key value.
A good section name will be common.

Normally your script only contains one statement, but to remove double lines
and to create the necessary section name we must use some additional state-
ments.
For a RunOnce update we are using another key in your config.sys file.
Our script example:

code:

$config="c:\config.sys"
$config_temp="%temp%\config.tmp"
$debug_mode="yes"
IF (Exist($config) = 1) AND (Len(ReadProfileString($config,"common","set prompt")) <> Len("$p$g $t$h$h$h"))
DEL $config_temp
IF (Open(1,$config,2) = 0) ; -read access-
IF (Open(2,$config_temp,5) = 0) ; -write access-
$line=ReadLine(1)
; -create '[common]' section
IF (WriteLine(2,"[common]"+CHR(13)+CHR(10)) <> 0)
ENDIF
; -add 'shell' key-
IF (WriteLine(2,"shell=c:\command.com /e:1024 /p"+CHR(13)+CHR(10)) <> 0)
ENDIF
; -we are using the 'set prompt' key to check has already been updated-
IF (WriteLine(2,"set prompt=$p$g $t$h$h$h"+CHR(13)+CHR(10)) <> 0)
ENDIF
WHILE (@error = 0)
IF ($debug_mode = "yes")
? " -> "+$line
ENDIF
IF (Instr($line,"shell=") = 0) AND (Instr($line,"[common]") = 0) AND (Instr($line,"prompt=") = 0)
IF (WriteLine(2,$line+CHR(13)+CHR(10)) <> 0)
ENDIF
IF ($debug_mode = "yes")
" (copy)"
ENDIF
ELSE
IF ($debug_mode = "yes")
" (skip)"
ENDIF
ENDIF
$line=ReadLine(1)
LOOP
IF Close(2)
ENDIF
ENDIF
IF Close(1)
ENDIF
?
IF (Exist($config_temp) = 1)
COPY $config_temp $config /H
IF (@error <> 0)
? "Warning KIX: update config.sys returns error @error (@serror)"
ELSE
DEL $config_temp
ENDIF
? "update "+Ucase($config)+" file."
ENDIF
ENDIF
? "update completed."
ELSE
? "already updated."
ENDIF


Our input file was:
code:

SHELL=C:\COMMAND.COM /E:1024 /P
DEVICE=C:\WINDOWS\HIMEM.SYS
DEVICE=C:\WINDOWS\EMM386.EXE NOEMS
FILESHIGH=100
BUFFERSHIGH=30
DOS=HIGH,UMB
LASTDRIVE=Z
FCBSHIGH=4,0
SHELL=C:\COMMAND.COM /E:4096 /P
SHELL=C:\COMMAND.COM /E:1024 /P
SHELL=C:\COMMAND.COM /E:1024 /P
SHELL=C:\COMMAND.COM /E:1024 /P
SHELL=C:\COMMAND.COM /E:1024 /P
SHELL=C:\COMMAND.COM /E:1024 /P
SHELL=C:\COMMAND.COM /E:1024 /P
SHELL=C:\COMMAND.COM /E:1024 /P


Our result file is:
code:

[common]
shell=c:\command.com /e:1024 /p
set prompt=$p$g $t$h$h$h
DEVICE=C:\WINDOWS\HIMEM.SYS
DEVICE=C:\WINDOWS\EMM386.EXE NOEMS
FILESHIGH=100
BUFFERSHIGH=30
DOS=HIGH,UMB
LASTDRIVE=Z
FCBSHIGH=4,0


Your screen output will be something like this:
first run[b]
code:

-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> DEVICE=C:\WINDOWS\HIMEM.SYS (copy)
-> DEVICE=C:\WINDOWS\EMM386.EXE NOEMS (copy)
-> FILESHIGH=100 (copy)
-> BUFFERSHIGH=30 (copy)
-> DOS=HIGH,UMB (copy)
-> LASTDRIVE=Z (copy)
-> FCBSHIGH=4,0 (copy)
-> SHELL=C:\COMMAND.COM /E:4096 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
-> SHELL=C:\COMMAND.COM /E:1024 /P (skip)
update C:\CONFIG.SYS file.
update completed.


Second run:
code:

already updated.

Greetings.


btw: we must take some precaution for a known flushing problem
with write-buffers. We are only use the [b]WriteLine
functions.
For new changes with other scripts you can use the WriteProfileString
function to do that.
A call can be something like this:

code:

IF (WriteProfileString("c:\config.sys","common","set dircmd","/o:n") <> 0)
ENDIF

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA