Page 1 of 1 1
Topic Options
#49226 - 2000-03-22 08:50 AM Check line and add it
Anonymous
Unregistered


I need to add a files=100 line in the config.sys of every w95 station (130) on our LAN. (For a DOS program).
So first the script does need to read the config.sys if "files=100" is already present, if it is not present then the script needs to add this line else it should just continue the script.
Can someone give me a hand.

Top
#49227 - 2000-03-23 08:04 AM Re: Check line and add it
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Marck...

Here's a really kludgy way to do it.

Unfortunately it seems that we can't use the writeprofilesstring() function to change the config.sys file (cause there's no section headers). Can anyone think of a hack for this ?

I don't have win9x but it works for WinNt. As well, it would be nice to be able to check a registry value (files=n) or a file timestamp before-hand so you wouldn't have to do this everytime a user logged in (anyone?)


code:

break on

$config = "c:\winnt\system32\config.nt"
$temp = "c:\winnt\system32\config.tmp"
$cr = chr(10)

del $temp

$rs = open ( 1, $config, 2 )
$rs = open ( 2, $temp, 5 )

$line = readline(1)
while @error = 0
if $line = "files=20"
$rs = writeline(2,"files=100"+$cr)
else
$rs = writeline(2,$line+$cr)
endif
$line=readline(1)
loop

$rs = close(1)
$rs = close(2)

copy $temp $config

exit


Shawn.

Top
#49228 - 2000-03-23 04:19 PM Re: Check line and add it
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Shawn...

I don't think that your way is "kludgy", config.sys is normally a small textfile, so checking it from start to end is not "kludgy".

The quiestion is for win95 so config.sys will be locatet on c:\

This is a slightly modified code of Shawns example, adding a check for the existense of a line starting with: files=

code:
break on
$config = "c:\config.sys"
$temp = "c:\config.tmp"
$cr = Chr(10)
Del $temp
$rs = Open ( 1, $config, 2 )
$rs = Open ( 2, $temp, 5 )
$line = ReadLine(1)
$NotFnd = -1 ; Line starting with "Files=" not found
While @Error = 0
if SubStr(LTrim($line,1,6)) = "files="
$rs = WriteLine(2,"files=100"+$cr)
$NotFnd = 0 ; Line starting with "File=" found
Else
$rs = WriteLine(2,$line+$cr)
EndIf
$Line=ReadLine(1)
Loop
If $NotFnd ; Line starting with "Files=" not found
$rs = WriteLine(2,"files=100"+$cr)
EndIf
$rs = Close(1)
$rs = Close(2)
Copy $temp $config
Exit


Top
#49229 - 2000-03-24 07:46 AM Re: Check line and add it
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gents...

If I was really doing this, I would probably keep a "master" version of the workstation config.sys on a centralized server share. Then leverage off the "comparefiletimes()" function to copy all revisions to the workstation.

Obviously this example only works when everyone gets the same config.sys, but you could build-in the smarts to handle differences based on user group or whatever.

Also, this gives the added benefit of being more generic and flexible and will run a whole lot faster !

code:

$server_config = "\\dn1cmp\image\config.nt"
$workstation_config = "c:\winnt\system32\config.nt"

$rs = comparefiletimes ( $workstation_config, $server_config )
if $rs = -1
?"Copying new config..."
copy $server_config $workstation_config
else
?"Error or no action required..."
endif

exit


If you do decide to go with the parsing solution, I'd definitely recommend you implement kholm's improved version. It handles the case where there is no files=n line found !

Shawn.

Top
#49230 - 2000-04-06 11:57 AM Re: Check line and add it
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
There is a program called ACSR.EXE that comes on the Office 9x? CD. It is a simple Search and Replace tool for the command line.

There is no documentation or help for it, but the options are like this:

ACSR "search text" "replace text" sourcefile destfile

Unfortunately the source and dest have to be different, but if you have to make two changes, then source -> dest -> source.

If you knew that all the files=xxx lines were files=20 you could just

code:

acsr "files=20" "files=100" c:\config.sys C:\config.new
del c:\config.sys
ren c:\config.new config.sys


This is case sensitive too, so FILES=20 will not be changed.

If the FILES<>20... If the files= are all different, you can (DOS):

code:

for %a in (10, 11, 12...you get the idea...98, 99) do acsr "files=%a" "files=100" c:\config.sys c:\config.new
del c:\config.sys
ren c:\config.new config.sys

This will run ACSR for every number from 10 to 99. ACSR will only create the desfile if the S/R is successful. It will not delete or "0" the file on a fail.

Or you could use KIX to read the textfile line by line and spit out to another file each line until a "files=" is found. Then spit out the new line to the new file and continue the line by line transfer. This is clumsy, but config.sys is usually small.

I have only used ACSR in NT, but I expect it will work in win9x too.
http://www.ozemail.com.au/~chrismat/acsr.exe if you want to download it.

cj

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 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.055 seconds in which 0.026 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