#123968 - 2004-07-27 11:41 AM
how to edit the services file in windows ?
|
slorf
Fresh Scripter
Registered: 2004-07-27
Posts: 5
Loc: Netherlands
|
HI All,
I am trying to use kixstart to edit multple ini files, which worked fine :-)
Now there is a bigger challange..
I have to edit the windows\system32\drivers\etc\services file.
Every user has local admin rights, so that should not be a problem.
In the services file there are a list of SAP entries, starting like this:
sapdp00 3200/tcp sapdp01 3201/tcp sapdp02 3202/tcp sapdp03 3203/tcp
And it goes on and on.
Before the first one i have to insert: SapmsPRD 3601/tcp
I tried to replace the first entry with the new one, and then append the original to the end, but this did not work :-(
Does anyone have a clue ?
|
|
Top
|
|
|
|
#123970 - 2004-07-27 12:37 PM
Re: how to edit the services file in windows ?
|
slorf
Fresh Scripter
Registered: 2004-07-27
Posts: 5
Loc: Netherlands
|
we have been told this entry should be the first one if you are using "groups" in sap.
I tried using the following script to replace the first entry, but it did not work?
$sMyIni="c:\windows\system32\drivers\etc\services" $sOldString="3200/tcp" $sNewString="3601/tcp"
For Each $sSection in Split(ReadProfileString($sMyIni,"",""),Chr(10)) If $sSection "Checking section "+$sSection+@CRLF For Each $sEntry in Split(ReadProfileString($sMyIni,$sSection,""),Chr(10)) If $sEntry $sValue=ReadProfileString($sMyIni,$sSection,$sEntry) "Entry "+$sEntry+" has value "+$sValue+" status:" If $sValue=$sOldString " **UPDATED**"+@CRLF $=WriteProfileString($sMyIni,$sSection,$sEntry,$sNewString) Else " No change"+@CRLF EndIf EndIf Next EndIf Next
|
|
Top
|
|
|
|
#123971 - 2004-07-27 05:06 PM
Re: how to edit the services file in windows ?
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
I had to edit that file at one point myself (not for SAP). So i just edited my script for your needs, but haven't tested.
Code:
Break ON dim $path, $servicesFile, $newLine, $tempFile, $backUp
$newLine = "SapmsPRD 3601/tcp" $path = "%windir%" + "\system32\drivers\etc\" $servicesFile = $path + "services" $tempFile = $path + "temp.txt" $backUp = $servicesFile + ".bak"
if open(1, $servicesFile) = 0 if exist($tempFile) del $tempFile endif
if open(2, $tempFile, 5) = 0 $curLine = readline(1) while $curLine <> "sapdp00 3200/tcp" and @error = 0 $ = writeline(2, $curLine + @crlf) $curLine = readline(1) loop
if $curLine = "sapdp00 3200/tcp" $ = writeline(2, $newLine + @crlf) endif
while @error = 0 $ = writeline(2, $curLine + @crlf) $curLine = readline(1) loop
$ = close(1) $ = close(2)
copy $servicesFile $backUp copy $tempFile $servicesFile del $tempFile else $ = close(1) endif endif
exit
_________________________
Eric
|
|
Top
|
|
|
|
#123972 - 2004-07-28 10:46 PM
Re: how to edit the services file in windows ?
|
acmp
Getting the hang of it
Registered: 2004-07-02
Posts: 69
Loc: Bingham, Nottinghamshire, Engl...
|
Quote:
Every user has local admin rights,
Man that's scary.
Another approach to 'put it in an array and write it back' is to create a new file on your server with the correct first line.
Then use KiX to rename hte existing file, copy over the new 'header file' then pipe the contents of the 'old' file in.
This way may be easier (I used something similar to reset NT host files) If you need some code let me know and I'll post it (it's at work and I'm not)
acmp<><
_________________________
Every day is a school day
|
|
Top
|
|
|
|
#123974 - 2004-07-29 10:00 AM
Re: how to edit the services file in windows ?
|
slorf
Fresh Scripter
Registered: 2004-07-27
Posts: 5
Loc: Netherlands
|
hi,
if you can send me the code you used that would be great
|
|
Top
|
|
|
|
#123975 - 2004-07-29 10:01 AM
Re: how to edit the services file in windows ?
|
slorf
Fresh Scripter
Registered: 2004-07-27
Posts: 5
Loc: Netherlands
|
Our users have local admin rights ( only on their pc's ) if not, they would not be able to run certain s/w packages we have.
|
|
Top
|
|
|
|
#123978 - 2004-07-29 10:03 PM
Re: how to edit the services file in windows ?
|
acmp
Getting the hang of it
Registered: 2004-07-02
Posts: 69
Loc: Bingham, Nottinghamshire, Engl...
|
hey! I'm listed as a noob! I guess he just wants me to post the code here, which I will when I go into work tomorrow (friday).
acmp<><
_________________________
Every day is a school day
|
|
Top
|
|
|
|
#123980 - 2004-07-29 10:14 PM
Re: how to edit the services file in windows ?
|
acmp
Getting the hang of it
Registered: 2004-07-02
Posts: 69
Loc: Bingham, Nottinghamshire, Engl...
|
Your code looks good to me, I just had another idea up my sleeve from a problem that I had.
The only draw back with your code that I can see is that you will always rewrite the file. Yeah, I know it's an easy thing to fix, just add a 'if not readline=whatever the do the code' bit and it's fixed.
Maybe we can all share code and come to an appreciation of others ideas?
acmp<><
_________________________
Every day is a school day
|
|
Top
|
|
|
|
#123982 - 2004-07-30 09:58 AM
Re: how to edit the services file in windows ?
|
slorf
Fresh Scripter
Registered: 2004-07-27
Posts: 5
Loc: Netherlands
|
Hi there
Sorry, i did not know my location and email was not listed, i will try to change it. Yes, i am very very new.. :-)
|
|
Top
|
|
|
|
#123983 - 2004-07-30 09:04 PM
Re: how to edit the services file in windows ?
|
acmp
Getting the hang of it
Registered: 2004-07-02
Posts: 69
Loc: Bingham, Nottinghamshire, Engl...
|
I think I'll fix that my self by getting my posts up, but thanks for the offer.
acmp<><
_________________________
Every day is a school day
|
|
Top
|
|
|
|
#123984 - 2004-07-30 09:12 PM
Re: how to edit the services file in windows ?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Okay, if none of these solutions are sufficient then just walk out to these desktops, open up notepad and edit the file manually. 
Does that count for a post count increase ?
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 302 anonymous users online.
|
|
|