#25927 - 2002-07-26 01:00 AM
Appending to a host and lmhost file
|
Stealth
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
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.
|
|
Top
|
|
|
|
#25930 - 2002-07-26 01:49 AM
Re: Appending to a host and lmhost file
|
Stealth
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
|
|
Top
|
|
|
|
#25935 - 2002-07-26 06:46 AM
Re: Appending to a host and lmhost file
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
I think this is what you are looking for..
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
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1058 anonymous users online.
|
|
|