Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2792
  • Last Modified:

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.
0
bthorn
Asked:
bthorn
  • 9
  • 5
  • 5
  • +1
1 Solution
 
DexstarCommented:
bthorn:

> 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,
Dex*
0
 
tkalchevCommented:
Probably this will help :

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

0
 
_nn_Commented:
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)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DexstarCommented:
bthorn:

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.

Dex*
0
 
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?
0
 
tkalchevCommented:
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 ?
0
 
bthornAuthor Commented:
the type line deleted all entries in services file...I did use the quotes, was I supposed to?
0
 
tkalchevCommented:
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%
0
 
tkalchevCommented:
Ops, sorry, line should be :

type c:\winnt\system32\drivers\etc\services | find /v "sapmstnt" > c:\winnt\system32\drivers\etc\services
0
 
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.
0
 
tkalchevCommented:
Of course only the administartor can do this, normal users cannot edit anything under c:\winnt\system32
0
 
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.
0
 
_nn_Commented:
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

:do_it
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
:disconnect
net use %1 /del
:end
0
 
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
0
 
_nn_Commented:
>> I would assume I need only change c:\somewhere\new_services.txt to \\SERVERNAME\SHARE\services

Correct.

>> 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

\\PC1
\\PC2

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 "****" ;)
0
 
bthornAuthor Commented:
nn this seems to work great one more test and were done
0
 
DexstarCommented:
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:
http://www.sysinternals.com/ntw2k/freeware/psexec.shtml

Dex*
0
 
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.
0
 
_nn_Commented:
Hmmm,

- 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" ?
0
 
bthornAuthor Commented:
i made a test on my network domain at home, made a list.txt file with this format

\\joe
\\jim
\\jack

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.
0
 
_nn_Commented:
Hmm, setup looks fine... Can you please comment out the @echo off, run the script and paste its output here ?
0
 
bthornAuthor Commented:
was my mistake the pc i checked had a problem all others worked i'm happy
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 9
  • 5
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now