Page 1 of 1 1
Topic Options
#25927 - 2002-07-26 01:00 AM Appending to a host and lmhost file
Stealth Offline
Fresh Scripter

Registered: 2001-08-09
Posts: 48
Loc: Scotland
Is it possible to add entries to these then have it check the next time the user logs on I guess the entries would be added with a >> to add to the file but how do you check to see if has already been added
Thanks in advance....

Top
#25928 - 2002-07-26 01:05 AM Re: Appending to a host and lmhost file
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You can edit every LMHOST file if you want, but you could also:
quote:
# Specifying "#INCLUDE " will force the RFC NetBIOS (NBT)
# software to seek the specified and parse it as if it were
# local. is generally a UNC-based name, allowing a
# centralized lmhosts file to be maintained on a server.
# It is ALWAYS necessary to provide a mapping for the IP address of the
# server prior to the #INCLUDE. This mapping must use the #PRE directive.
# In addtion the share "public" in the example below must be in the
# LanManServer list of "NullSessionShares" in order for client machines to
# be able to read the lmhosts file successfully. This key is under
# \machine\system\currentcontrolset\services\lanmanserver\parameters\nullsessionshares
# in the registry. Simply add "public" to the list found there.

If you want to edit the file locally see OPEN, READLINE, WRITELINE in the manual and search the board.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#25929 - 2002-07-26 01:45 AM Re: Appending to a host and lmhost file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why not just use a WINS and DNS server?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25930 - 2002-07-26 01:49 AM Re: Appending to a host and lmhost file
Stealth Offline
Fresh Scripter

Registered: 2001-08-09
Posts: 48
Loc: Scotland
Yes why not indeed I'm not the machanic I'm just the oily rag [Smile]
Top
#25931 - 2002-07-26 03:30 AM Re: Appending to a host and lmhost file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I would go for DHCP and DNS and skip wins...
_________________________
!

download KiXnet

Top
#25932 - 2002-07-26 04:11 AM Re: Appending to a host and lmhost file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
You won't be skipping WINS in a Windows environment unless you want MORE headaches.
Top
#25933 - 2002-07-26 04:15 AM Re: Appending to a host and lmhost file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I don't have headaches still with no proper wins config.
it just runs there and helps with local machine info.
and it's the most unstable naming service I've found.
anyway, only reason for it is to get wksta stuff out of dns and dynamic
_________________________
!

download KiXnet

Top
#25934 - 2002-07-26 06:30 AM Re: Appending to a host and lmhost file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, so someone else is driving the boat...

If you can't have a centrally managed WINS and DNS then at least your local hosts and lmhosts files should be managed. You should not be appending them but rather replacing them. Basically, what I'm saying is that you should know what is in them and what needs to be in them. Them you institute change management by logging everything in INI files.

If you want to go low tech and parse through them on every logon, then take a look at the FAQ

Topic: File Input/Output Primer

Be aware however that you could encounter NTFS permission issues.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25935 - 2002-07-26 06:46 AM Re: Appending to a host and lmhost file
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I think this is what you are looking for.. [Smile]

code:
BREAK ON CLS

:hostsinstall
If (@inwin = 1)
$windir = READVALUE("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion","SystemRoot")
$hostsdir = $windir + "\SYSTEM32\DRIVERS\ETC"
$hostsdirfile = $windir + "\SYSTEM32\DRIVERS\ETC\LMHOSTS"
ELSE
$windir = READVALUE("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion","SystemRoot")
$hostsdir = $windir
$hostsdirfile = $windir + "\HOSTS"
ENDIF

;This is setup with IP Address and Alias of the Server
$ipalias = "1.2.3.4"+chr(9)+chr(9)+"installs"
$eol = Chr(13)+Chr(10)
$result = 1
IF exist($hostsdirfile)
$result = open( 1 , $hostsdirfile )
ELSE
IF exist($hostsdirfile)
$result = open( 1 , $hostsdirfile )
ELSE
;BEEP
;You could XCOPY a "pre-canned" HOSTS file from a NETLOGON share on the next line instead of an error message
COPY @ldrive+"HOSTS" $hostsdir
;? "Sorry, the HOSTS file appears to be missing."
;Comment out the next COMMAND line to create the HOSTS file anyway
GOTO OUTPUT1
ENDIF
ENDIF

IF $result = 0
$line = readline( 1 )
WHILE @error = 0
$line = readline( 1 )
;We are going to compare the $line and $IPALIAS
IF $line = $ipalias
;Uncomment out the next line to turn on visual results.
;$EDITRESULT = 'The hosts line you were looking for is already there, no mods were made.'
GOTO OUTPUT
ELSE
;Uncomment out the next line to turn on visual results.
;$EDITRESULT = 'We added the hosts line for you - ' + $IPALIAS
ENDIF
LOOP
$result = close( 1 )
ELSE
;BEEP
;You could XCOPY a "pre-canned" HOSTS file from a NETLOGON share on the next line instead of an error message
COPY @ldrive+"HOSTS" $hostsdir
;? "Sorry, failed to open HOSTS, errorcode : [" + @ERROR + "]"
;Comment out the next COMMAND line to create the HOSTS file anyway
GOTO OUTPUT1
ENDIF

:output
;We need to check for the existence of the $IPALIAS and if it not found add in the line
;Uncomment out the next line to turn on visual results.
;? $EDITRESULT SLEEP 3
;IF $EDITRESULT = 'N'
$result = 2
IF Open(2,$hostsdirfile,5) = 0
$o = WriteLine(2,$ipalias+$eol)
ENDIF
IF close(2) = 0
ENDIF
;Make sure the 1st file is closed
$result = close( 1 )
RETURN

:output1
;Make sure the 1st file is closed
$result = close( 1 )
RETURN

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1114 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.056 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org