Archive: Reaplace Word In INI File


Reaplace Word In INI File
hi
How replace a Word in INI File?!


I want replace /fastdetect TO /fastdetect /safeboot:minimals In File C:\Boot.ini

I test This Code:




section

Push "/fastdetect" #-- text to be replaced within the " "
Push "/fastdetect /safeboot:minimals" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $%HOMEDRIVE%\Boot.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function

sectionend







section

Push "/fastdetect" #-- text to be replaced within the " "
Push "/fastdetect /safeboot:minimals" #-- replace with anything within the " "
Push all #-- replace all occurrences
Push all #-- replace all occurrences
Push $%HOMEDRIVE%\Boot.ini #-- file to replace in
Call AdvReplaceInFile #-- Call the Function

sectionend





;Original Written by Afrow UK
; Rewrite to Replace on line within text by rainmanx
; Creating the temp file in the same directory by lars
; This version works on R4 and R3 of Nullsoft Installer
; It replaces whatever is in the line throughout the entire text matching it.
Function AdvReplaceInFile
Exch $0 ;file to replace in
Exch
Exch $1 ;number to replace after
Exch
Exch 2
Exch $2 ;replace and onwards
Exch 2
Exch 3
Exch $3 ;replace with
Exch 3
Exch 4
Exch $4 ;to replace
Exch 4
Push $5 ;minus count
Push $6 ;universal
Push $7 ;end string
Push $8 ;left string
Push $9 ;right string
Push $R0 ;file1
Push $R1 ;file2
Push $R2 ;read
Push $R3 ;universal
Push $R4 ;count (onwards)
Push $R5 ;count (after)
Push $R6 ;temp file name
;-------------------------------
; Find folder with file to edit:
GetFullPathName $R1 $0\..
; Put temporary file in same folder to preserve access rights:
GetTempFileName $R6 $R1
FileOpen $R1 $0 r ;file to search in
FileOpen $R0 $R6 w ;temp file
StrLen $R3 $4
StrCpy $R4 -1
StrCpy $R5 -1
loop_read:
ClearErrors
FileRead $R1 $R2 ;read line
IfErrors exit
StrCpy $5 0
StrCpy $7 $R2
loop_filter:
IntOp $5 $5 - 1
StrCpy $6 $7 $R3 $5 ;search
StrCmp $6 "" file_write2
StrCmp $6 $4 0 loop_filter
StrCpy $8 $7 $5 ;left part
IntOp $6 $5 + $R3
StrCpy $9 $7 "" $6 ;right part
StrLen $6 $7
StrCpy $7 $8$3$9 ;re-join
StrCmp -$6 $5 0 loop_filter
IntOp $R4 $R4 + 1
StrCmp $2 all file_write1
StrCmp $R4 $2 0 file_write2
IntOp $R4 $R4 - 1
IntOp $R5 $R5 + 1
StrCmp $1 all file_write1
StrCmp $R5 $1 0 file_write1
IntOp $R5 $R5 - 1
Goto file_write2
file_write1:
FileWrite $R0 $7 ;write modified line
Goto loop_read
file_write2:
FileWrite $R0 $7 ;write modified line
Goto loop_read
exit:
FileClose $R0
FileClose $R1
SetDetailsPrint none
Delete $0
Rename $R6 $0
Delete $R6
SetDetailsPrint both
;-------------------------------
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

;Original Written by Afrow UK
; Rewrite to Replace on line within text by rainmanx
; Creating the temp file in the same directory by lars
; This version works on R4 and R3 of Nullsoft Installer
; It replaces whatever is in the line throughout the entire text matching it.
Function AdvReplaceInFile
Exch $0 ;file to replace in
Exch
Exch $1 ;number to replace after
Exch
Exch 2
Exch $2 ;replace and onwards
Exch 2
Exch 3
Exch $3 ;replace with
Exch 3
Exch 4
Exch $4 ;to replace
Exch 4
Push $5 ;minus count
Push $6 ;universal
Push $7 ;end string
Push $8 ;left string
Push $9 ;right string
Push $R0 ;file1
Push $R1 ;file2
Push $R2 ;read
Push $R3 ;universal
Push $R4 ;count (onwards)
Push $R5 ;count (after)
Push $R6 ;temp file name
;-------------------------------
; Find folder with file to edit:
GetFullPathName $R1 $0\..
; Put temporary file in same folder to preserve access rights:
GetTempFileName $R6 $R1
FileOpen $R1 $0 r ;file to search in
FileOpen $R0 $R6 w ;temp file
StrLen $R3 $4
StrCpy $R4 -1
StrCpy $R5 -1
loop_read:
ClearErrors
FileRead $R1 $R2 ;read line
IfErrors exit
StrCpy $5 0
StrCpy $7 $R2
loop_filter:
IntOp $5 $5 - 1
StrCpy $6 $7 $R3 $5 ;search
StrCmp $6 "" file_write2
StrCmp $6 $4 0 loop_filter
StrCpy $8 $7 $5 ;left part
IntOp $6 $5 + $R3
StrCpy $9 $7 "" $6 ;right part
StrLen $6 $7
StrCpy $7 $8$3$9 ;re-join
StrCmp -$6 $5 0 loop_filter
IntOp $R4 $R4 + 1
StrCmp $2 all file_write1
StrCmp $R4 $2 0 file_write2
IntOp $R4 $R4 - 1
IntOp $R5 $R5 + 1
StrCmp $1 all file_write1
StrCmp $R5 $1 0 file_write1
IntOp $R5 $R5 - 1
Goto file_write2
file_write1:
FileWrite $R0 $7 ;write modified line
Goto loop_read
file_write2:
FileWrite $R0 $7 ;write modified line
Goto loop_read
exit:
FileClose $R0
FileClose $R1
SetDetailsPrint none
Delete $0
Rename $R6 $0
Delete $R6
SetDetailsPrint both
;-------------------------------
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd





This Code Not Good Work! Whay? Because:

My Ini File Text Is :

/fastdetect


Im Replace This Code :

/safeboot:minimals


When Replace Text With This Code Then My INI File Is:

/fastdetect /safeboot:minimals/fastdetect

This Is Not Good! Because My Ini File Broken!



What solution do you recommend?
What code do I use?
tanks

FileOpen $0 "C:\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
CopyFiles "$PLUGINSDIR\Boot.ini" "C:\"


And what if boot.ini does not contain /fastdetect?


Originally posted by world80
FileOpen $0 "C:\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
CopyFiles "$PLUGINSDIR\Boot.ini" "C:\"

Tanks world80
But This code not Compile!
What "!INCLUDE" should be added to the program؟
tanks

Quote:

Originally Posted by Anders (Post 2974836) And what if boot.ini does not contain /fastdetect? "/fastdetect" IS Windows determines the boot mode In Windows XP
Whit /fastdetect /safeboot:minimals We set run Windows In Safe mode...

Originally posted by world80
FileOpen $0 "C:\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
CopyFiles "$PLUGINSDIR\Boot.ini" "C:\"

Tanks world80
But This code not Compile!
What "!INCLUDE" should be added to the program؟
tanks

Quote:

Originally Posted by Anders (Post 2974836) And what if boot.ini does not contain /fastdetect? "/fastdetect" IS Windows determines the boot mode In Windows XP
Whit /fastdetect /safeboot:minimals We set run Windows In Safe mode...

Originally posted by world80
FileOpen $0 "C:\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
CopyFiles "$PLUGINSDIR\Boot.ini" "C:\"

Tanks world80
But This code not Compile!
What "!INCLUDE" should be added to the program؟
tanks

Quote:

Originally Posted by Anders (Post 2974836) And what if boot.ini does not contain /fastdetect? "/fastdetect" IS Windows determines the boot mode In Windows XP
Whit /fastdetect /safeboot:minimals We set run Windows In Safe mode...

tanks
im test this code,But Code not Work and Not Save cheange to file!

Originally posted by Anders
And what if boot.ini does not contain /fastdetect?
"/fastdetect" IS Windows determines the boot mode In Windows XP
Whit /fastdetect /safeboot:minimals We set run Windows In Safe mode...

/fastdetect is optional, you should not depend on it being there...


i want set option Boot fot this programes:
ONE PROGRAM
and
TWO PROGRAM
Im set Automatic program to Safe mode But "bcdedit /set ..." Not Work on Windows xp So I Should I have an idea!
New Programes v 8.2 and 10.1 set windows xp on safe boot But My Codes Have Problem!
I am looking for code without a problem and need good code fore repace in ini file :(


You just linked to something with antivirus crack in the URL, do you really think people want to help you now?


Originally posted by r2du-soft
Tanks world80
But This code not Compile!
What "!INCLUDE" should be added to the program؟
tanks



"/fastdetect" IS Windows determines the boot mode In Windows XP
Whit /fastdetect /safeboot:minimals We set run Windows In Safe mode...
!include "MUI2.nsh" ;or LogicLib.nsh
!include "WordFunc.nsh"

FileOpen $0 "C:\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
Strcmp $3 "" +2 ;$3="" means boot.ini does not contain /fastdetect
CopyFiles "$PLUGINSDIR\Boot.ini" "C:\"

Originally posted by world80
!include "MUI2.nsh" ;or LogicLib.nsh
!include "WordFunc.nsh"

FileOpen $0 "C:\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
Strcmp $3 "" +2 ;$3="" means boot.ini does not contain /fastdetect
CopyFiles "$PLUGINSDIR\Boot.ini" "C:\"


tanks But When Start this code nsis Say "Copy Failed" and not Copy File In Over! And I not See changes in File Boot.ini

Quote:


There may be FileAttributes issue;

${WordFind} "$SYSDIR" "\" "+1" $4
${if} ${FileExists} "$4\Boot.ini"
FileOpen $0 "$4\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
Strcmp $3 "" +4 ;$3="" means boot.ini does not contain /fastdetect
SetFileAttributes "$4\Boot.ini" NORMAL
CopyFiles "$PLUGINSDIR\Boot.ini" "$4\"
SetFileAttributes "$4\Boot.ini" HIDDEN|SYSTEM
${endif}


hi
this code Worked:


CopyFiles "$%HOMEDRIVE%\Boot.ini" "$WINDIR\Boot.ini"
FileOpen $0 "$WINDIR\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}
${if} $3 != 1
${WordFind} $1 "/fastdetect" "+1}" $2
${if} $1 != $2
${WordReplace} "$1" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1
${endif}
${endif}
FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
Strcmp $3 "" +2 ;$3="" means boot.ini does not contain /fastdetect
CopyFiles "$PLUGINSDIR\Boot.ini" "$%HOMEDRIVE%\"



But a small problem!
When in boot.ini has a one "/fastdetect" this code change "/fastdetect" to "/fastdetect /safeboot:minimals"
But if in boot.ini File has Two "/fastdetect" then this code just change first "/fastdetect" to "/fastdetect /safeboot:minimals" and other "/fastdetect" not Change!

How Fix this?!
Very tanks

thankful My Friends My Problem Fix Whit This Code:



CopyFiles "$%HOMEDRIVE%\Boot.ini" "$WINDIR\Boot.ini"
FileOpen $0 "$WINDIR\Boot.ini" r
FileOpen $R0 "$PLUGINSDIR\Boot.ini" w
FileRead $0 $1
Strcpy $3 ""
${DoUntil} ${Errors}

${WordFind} $1 "/fastdetect"}" $2
${WordReplace} "$2" "/fastdetect" "/fastdetect /safeboot:minimals" "+1" $1
Strcpy $3 1

FileWrite $R0 $1
FileRead $0 $1
${Loop}
FileClose $0
FileClose $R0
Strcmp $3 "" +2 ;$3="" means boot.ini does not contain /fastdetect
CopyFiles "$PLUGINSDIR\Boot.ini" "$%HOMEDRIVE%\"




thankful thankful thankful


thankful world80 & thankful Anders


Originally Posted by Anders (Post 2975221) You just linked to something with antivirus crack in the URL, do you really think people want to help you now? i For People comfortable Cracked Antivirus,and people liked this :)