Services file

I administrate a Domain, I need a bat file to run at login that will add this entry into the
c:\winnt\system32\drivers\etc\services file
"sapmsP02   3600/tcp"
I have 300 workstations all NT workstation and need to automate this process.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


> I administrate a Domain, I need a bat file to run at login that will add this entry into the
> c:\winnt\system32\drivers\etc\services file
> "sapmsP02   3600/tcp"
> I have 300 workstations all NT workstation and need to automate this process.

You're probably better off providing the updated services file, instead of trying to alter the existing ones.  In your login script, you can do this:

copy \\SERVER\Share\Services.Txt %WINDIR%\system32\drivers\etc\services

Hope that helps,
Probably this will help :

echo sapmsP02   3600/tcp >> c:\winnt\system32\drivers\etc\services

Usually, that file is only writeable for administrators, so i doubt a logon script will help (unless all your users are administrators, which is unlikely).

I'm not really a network admin, so I would just copy the new services file on \\station\admin$\system32\drivers\etc. Provided I have a list of the workstations, I would write a small batch parsing that list and deploying the new file. Though, I guess that 'real' admins have better tools, GPO(?), administration kits, you name it, in order to deploy new system files. Maybe you should ask in the OS-related Topic Areas (WinNT and/or Win2K) or in the networking ones (WinNT Network and/or Microsoft Networking)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.


What _nn_ said about security is true.  This is going to have to be done from an admin account.  You could use a VBScript that will enumerate all the machines on your network, connect to the admin share, edit the text file, and then move on to the next one.

That's how I would do it.

bthornAuthor Commented:
tkalchev that worked fine in a script from my Domain Controller, the only remainig problem is that the line gets added to the end of the rest of the lines.  And in about the middle of these lines there is a statement saying "sapmstnt    3600/tcp" . so I need the new line before the old line or delete the old line out and add the new line.  Any idea?
echo sapmsP02   3600/tcp >> c:\winnt\system32\drivers\etc\services
type c:\winnt\system32\drivers\etc\services | find /v "sapmstnt    3600/tcp" > c:\winnt\system32\drivers\etc\services

The commands will add the line "sapmsP02   3600/tcp " to the end of the file and then will delete the old line "sapmstnt    3600/tcp".

Is this OK for you ?
bthornAuthor Commented:
the type line deleted all entries in services file...I did use the quotes, was I supposed to?
Ok, maybe it is a problem of the format. Change the second command to :

type c:\winnt\system32\drivers\etc\services | find /v "3600/tcp" > c:\winnt\system32\drivers\etc\services

This should work 100%
Ops, sorry, line should be :

type c:\winnt\system32\drivers\etc\services | find /v "sapmstnt" > c:\winnt\system32\drivers\etc\services
bthornAuthor Commented:
I've really got a problem here the echo command from tkalchev added the line but it was only tested on a workstation that did have admin rights. A generic user and the command that i put in the bat file to run at logon does not work.
Of course only the administartor can do this, normal users cannot edit anything under c:\winnt\system32
bthornAuthor Commented:
I am the Domain Administrator and have rights to the local administrator group which includes Domain Admin which resides on all local pc"s.
Just as I told you. Dex* proposed a VBscript, I could propose you a batch you would have to run with admin rights :

@echo off
for /f "skip=3" %%a in ('net view') do call :do_it %%a
goto end

net use %1
if ERRORLEVEL 1 goto end
if not exist %1\admin$\system32\drivers\etc\services goto disconnect
find /I "sapmsP02" %1\admin$\system32\drivers\etc\services
:: bypass if the target file already has the correct mapping
if "%ERRORLEVEL%" == "0" goto disconnect
:: overwrite with a locally prepared new file
copy /Y c:\somewhere\new_services.txt %1\admin$\system32\drivers\etc\services
net use %1 /del
bthornAuthor Commented:
_nn_  It looks like your telling me if I run this From the administrators account it will go out to my domain pc's and copy the new file. I need to know how I could test this on a small scale instead of globally also if I copy and paste your file into a bat file I would assume I need only change c:\somewhere\new_services.txt to \\SERVERNAME\SHARE\services
>> I would assume I need only change c:\somewhere\new_services.txt to \\SERVERNAME\SHARE\services


>> I need to know how I could test this on a small scale instead of globally

Create a small text file with 2~3 PC names like


and use

for /f %%a in (list.txt) do call :do_it %%a

instead of

for /f "skip=3" %%a in ('net view') do call :do_it %%a

On the other side, I believe you got a more elaborated script in that other question you posted in WinNT. I know that expert, you can trust him, he knows his "****" ;)
bthornAuthor Commented:
nn this seems to work great one more test and were done
You should use nn's batch file to do the work, and then use this utility to exec it on each PC without having to visit each one:

bthornAuthor Commented:
nn it works fine and touches all pc's including servers, so i need to only alter pc's so have decided to  substitute line with the text file entry. put the list.txt in the dir that i'm running script from and the dir that the services file is in. Cannot get it to work with the list. I substituted the line exactly how you indicated previously.

- is the list file visible to the batch at the moment it needs it ?
- what is the format of the names inside ? "PC1" or "\\PC1" ?
bthornAuthor Commented:
i made a test on my network domain at home, made a list.txt file with this format


substituted the line you said to, then copied the file list.txt to the same directory where the script is being run from and also to the directory where the services file \\SERVERNAME\SHARE\services is at.
Hmm, setup looks fine... Can you please comment out the @echo off, run the script and paste its output here ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bthornAuthor Commented:
was my mistake the pc i checked had a problem all others worked i'm happy
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.