#196836 - 2009-11-25 09:08 PM
Re: another project any guidance would be appreciated
[Re: itdaddy]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
You could read the file into an array with the ReadFile() UDF, get the location of "pcAlias=" with ASCAN, change the value, and re-write the file with the WriteFile() UDF:
for each $Element in $PClist
$array = ReadFile("fsp.ini")
$loc = AScan($array, "pcAlias=",,,1)
if $loc <> -1
$array[$loc] = "pcAlias="+$Element
$ = WriteFile("fsp.ini",$array)
endif
next However, the logic you have mapped out would ultimately just replace the same line in the same file repeatedly until the end of the array, so I'm a little confused as what you're really trying to do...
Edited by eriqjaffe (2009-11-25 09:08 PM)
|
Top
|
|
|
|
#196843 - 2009-11-25 10:11 PM
Re: another project any guidance would be appreciated
[Re: itdaddy]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
No need to shell out, you could just have WriteFile() directly write the file. Now that I see a bit more what you're going for, there really isn't any need to look for that string every time, either:
$array = ReadFile(@SCRIPTDIR+"\fsp.ini")
$loc = AScan($array, "pcAlias=",,,1)
if $loc <> =1
for each $Element in $PCList
$array[$loc] = "pcAlias="+$Element
$ = WriteFile("\\"+$Element+"\c$\windows\fsp.ini")
next
endif
Edited by eriqjaffe (2009-11-25 10:14 PM)
|
Top
|
|
|
|
#196844 - 2009-11-25 10:41 PM
Re: another project any guidance would be appreciated
[Re: eriqjaffe]
|
itdaddy
Starting to like KiXtart
Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
|
eriqjaffe this is what I have it just hangs? not sure why? can you see what I am doing wrong. It looks right but when I execute it with the command cmd like this
kix32.exe fspreplace.kix
it juts hangs nothing happens??
Break On
Dim $PCList
Dim $array
Dim $loc
$PCList = "isasst", "isasst", "isasst"
$array = ReadFile("fsp.ini")
$loc = AScan($array, "pcAlias=",,,1)
if $loc <> =1
for each $Element in $PCList
$array[$loc] = "pcAlias="+$Element
$ = WriteFile("\\"+$Element+"\c$\windows\fsp.ini")
? $Element
next
endif
;************************************
; ReadFile() UDF
;************************************
;Function ReadFile()
;
;Author Radimus
;
;Contributors Lonky... This is basically his code that I trimmed down to its
; simplest function
;
;Action Reads a file into an array
;
;Syntax $array=ReadFile($file)
;
;Version 1.0.1
;
;Date 10/21/2003
;
;Date Revised 10-22-2003 - dimmed vars
;
;Parameters file
; source filename
;
;Remarks Pair this with WriteFile() to read and write an entire file easily
;
;Returns @error if failed
;
;Dependencies None
;
;KiXtart Ver 4.02
;
;Example(s) $array=ReadFile('c:\file.txt')
Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=chr(10)
$f=freefilehandle
$_=open($f,$file)
if @error exit @error endif
do $t=$t+$lf+readline($f) until @error
$_=close($f)
$ReadFile=split(substr($t,2),$lf)
EndFunction
;************************************
; WriteFile() UDF
;************************************
;Function WriteFile()
;
;Author Radimus
;
;Contributors Lonky
;
;Action Writes an array as a file
;
;Syntax WriteFile('filename','array')
;
;Version 1.1
;
;Date 10/21/2003
;
;Date Revised 11/13/2003
;
;Parameters file
; destination filename
; array
; an array of data to write to a file
;
;Remarks Pair this with ReadFile() to read and write an entire file easily
;
;Returns @error if failed
;
;Dependencies None
;
;KiXtart Ver 4.02
;
;Example(s) $=WriteFile('c:\file.txt',$array)
Function WriteFile($file,$array)
Dim $, $f, $line
If Not VarType($Array) & 8192 Exit(1) EndIf
$f=freefilehandle
$=open($f,$file,5)
if @error exit @error endif
for each $line in $array
$=writeline($f,$line+@crlf)
if @error exit @error endif
next
$=close($f)
EndFunction
_________________________
Robert A+, CCNA, MCP Network Admin Credit Union Wisconsin
|
Top
|
|
|
|
#196849 - 2009-11-26 12:28 PM
Re: another project any guidance would be appreciated
[Re: Glenn Barnas]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Or 3...
For Each $Element in $PClist
$=WriteProfileString("C:\MyIni.ini","MySECTION","pcAlias",$Element)
Next
|
Top
|
|
|
|
#196936 - 2009-12-02 05:07 PM
Re: another project any guidance would be appreciated
[Re: itdaddy]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Well, if the ini file is always structured the same, there's really no need to go looking for the line.
Going back to my original solution...
for each $Element in $PClist
$array = ReadFile("fsp.ini")
$array[2] = "pcAlias="+$Element
$ = WriteFile("\\"+$Element+"\C$\fsp.ini",$array)
next
|
Top
|
|
|
|
#196941 - 2009-12-02 06:23 PM
Re: another project any guidance would be appreciated
[Re: itdaddy]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
I see something I neglected to put in the code. This may be better:
for each $Element in $PClist
$array = ReadFile(@LDRIVE&"\fsp.ini") ;read "master" ini file into array
$array[2] = "pcAlias="+$Element ;set value array(2) to string value
$ = WriteFile("\\"+$Element+"\C$\fsp.ini",$array) ;write array back to file on the target machine.
next From what you've said, I assume that the INI file is static, aside from the one line. That being the case, there's no need to look for the line, or to verify what the line says.
A "master" INI file (which can be located on, say, @LDRIVE or some other network location) gets read into an array (since the INI file can get deleted from the remote systems, this make for a safety net). The value you want to change will always be the third line in the file, so I'm simply changing the value of $array[2] to reflect the correct target. Then, the array gets written to a file on the target machine with the appropriate value in there.
Edited by eriqjaffe (2009-12-02 06:24 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 264 anonymous users online.
|
|
|