|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
need to modify lmhosts file for all pc's in network
I need to be able to find the lmhosts file and then modify it with several
lines of information. I am new to scripting, but can see the value in learning this as quickly as possible. The networks have W2K and Win XP machines on it. Any tips would be greatly appreciated. TIA From: "Greg Mohr" <GregM***@discussions.microsoft.com> LMHosts is in; %windir%\system32\drivers\etc| I need to be able to find the lmhosts file and then modify it with several | lines of information. I am new to scripting, but can see the value in | learning this as quickly as possible. | | The networks have W2K and Win XP machines on it. | | Any tips would be greatly appreciated. | | TIA You can either copy a pre-created lmhosts file in this location and then execute; nbtstat -R { that's a capital R } after you drop the file or you can append to the existing file with the correct information you want to add and then execute; nbtstat -R David,
I understand that, but what I need to do is send a script to 5 locations across 4 states and have a line added to the lmhosts file inserting the new entry. I have been playing with sample scripts and scriptomatic2, but am going bonkers trying to figure out the objects. Please note that the txt extension is only for testing. Here is what I am trying to use: strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colOSItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem") For Each objOSItem In colOSItems WScript.Echo "System Directory: " & objOSItem.SystemDirectory Next Dim FileSys Dim Shell Dim File 'Create a new lmhosts file in the system32\drivers\etc directory Set objShell = CreateObject("Shell.Application") Set objFolder = objOSItem.SystemDirectory Set objFolderItem = FileSys.CreateTextFile(objOSItem.SystemDirectory & "\drivers\etc\lmhosts.txt") File.WriteLine "192.168.9.99 name.domain.com #PRE" File.Close 'This is only for the testing phase wScript.Echo "A new file, lmhosts.txt, has been created on your PC." Show quote "David H. Lipman" wrote: > From: "Greg Mohr" <GregM***@discussions.microsoft.com> > > | I need to be able to find the lmhosts file and then modify it with several > | lines of information. I am new to scripting, but can see the value in > | learning this as quickly as possible. > | > | The networks have W2K and Win XP machines on it. > | > | Any tips would be greatly appreciated. > | > | TIA > > LMHosts is in; %windir%\system32\drivers\etc > > You can either copy a pre-created lmhosts file in this location and then execute; > nbtstat -R { that's a capital R } > after you drop the file or you can append to the existing file with the correct information > you want to add and then execute; nbtstat -R > > -- > Dave > http://www.claymania.com/removal-trojan-adware.html > http://www.ik-cs.com/got-a-virus.htm > > >
Show quote
From: "Greg Mohr" <GregM***@discussions.microsoft.com> Instead of pushing it from a central location, have you thought about pulling it via the| David, | | I understand that, but what I need to do is send a script to 5 locations | across 4 states and have a line added to the lmhosts file inserting the new | entry. I have been playing with sample scripts and scriptomatic2, but am | going bonkers trying to figure out the objects. | Please note that the txt extension is only for testing. | | Here is what I am trying to use: | | strComputer = "." | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") | Set colOSItems = objWMIService.ExecQuery("SELECT * FROM | Win32_OperatingSystem") | For Each objOSItem In colOSItems | WScript.Echo "System Directory: " & objOSItem.SystemDirectory | Next | | Dim FileSys | Dim Shell | Dim File | | 'Create a new lmhosts file in the system32\drivers\etc directory | Set objShell = CreateObject("Shell.Application") | Set objFolder = objOSItem.SystemDirectory | Set objFolderItem = FileSys.CreateTextFile(objOSItem.SystemDirectory & | "\drivers\etc\lmhosts.txt") | File.WriteLine "192.168.9.99 name.domain.com #PRE" | File.Close | | 'This is only for the testing phase | wScript.Echo "A new file, lmhosts.txt, has been created on your PC." | Login Script ? Another thought is if the workstation is remote, requireing a LMHOSTS entry, then the remote workstation may not be able to communicate with you in the first place to to push the information. There are no logon scripts as 5 companies have been bought and cobbled
together under a holding company. I have to email it as I have 5 separate networks using a VPN tunnel to a colocated server. I don't have servers in every location and the servers that are there do not "talk" with each other yet. This is what happens when a co. hires a linux groupie! I have to email this script to everyone and have them run it on their PCs, it is the only option I have. I can't push because there are 5 different domains, the servers are too old and don't serve DHCP at the present time. The servers in place are an NT4.0, a W2k and a Linux. All I need to do is find the lmhosts file and add one line of information to it. Greg Show quote "David H. Lipman" wrote: > From: "Greg Mohr" <GregM***@discussions.microsoft.com> > > | David, > | > | I understand that, but what I need to do is send a script to 5 locations > | across 4 states and have a line added to the lmhosts file inserting the new > | entry. I have been playing with sample scripts and scriptomatic2, but am > | going bonkers trying to figure out the objects. > | Please note that the txt extension is only for testing. > | > | Here is what I am trying to use: > | > | strComputer = "." > | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") > | Set colOSItems = objWMIService.ExecQuery("SELECT * FROM > | Win32_OperatingSystem") > | For Each objOSItem In colOSItems > | WScript.Echo "System Directory: " & objOSItem.SystemDirectory > | Next > | > | Dim FileSys > | Dim Shell > | Dim File > | > | 'Create a new lmhosts file in the system32\drivers\etc directory > | Set objShell = CreateObject("Shell.Application") > | Set objFolder = objOSItem.SystemDirectory > | Set objFolderItem = FileSys.CreateTextFile(objOSItem.SystemDirectory & > | "\drivers\etc\lmhosts.txt") > | File.WriteLine "192.168.9.99 name.domain.com #PRE" > | File.Close > | > | 'This is only for the testing phase > | wScript.Echo "A new file, lmhosts.txt, has been created on your PC." > | > > Instead of pushing it from a central location, have you thought about pulling it via the > Login Script ? > > Another thought is if the workstation is remote, requireing a LMHOSTS entry, then the remote > workstation may not be able to communicate with you in the first place to to push the > information. > > -- > Dave > http://www.claymania.com/removal-trojan-adware.html > http://www.ik-cs.com/got-a-virus.htm > > >
Show quote
From: "Greg Mohr" <GregM***@discussions.microsoft.com> Email them the updated LMHOSTS file with a simple copy script that will drop the new LMHOSTS| There are no logon scripts as 5 companies have been bought and cobbled | together under a holding company. I have to email it as I have 5 separate | networks using a VPN tunnel to a colocated server. I don't have servers in | every location and the servers that are there do not "talk" with each other | yet. This is what happens when a co. hires a linux groupie! | | I have to email this script to everyone and have them run it on their PCs, | it is the only option I have. I can't push because there are 5 different | domains, the servers are too old and don't serve DHCP at the present time. | The servers in place are an NT4.0, a W2k and a Linux. | | All I need to do is find the lmhosts file and add one line of information to | it. | | Greg file in their etc folder. That would be great if it were only that simple. I have been told that some
of the PC's may have had the file modified already and I can't risk blowing those entries away. So my only solution is to try and append a line to the file that already exists on each PC. Greg Show quote "David H. Lipman" wrote: > From: "Greg Mohr" <GregM***@discussions.microsoft.com> > > | There are no logon scripts as 5 companies have been bought and cobbled > | together under a holding company. I have to email it as I have 5 separate > | networks using a VPN tunnel to a colocated server. I don't have servers in > | every location and the servers that are there do not "talk" with each other > | yet. This is what happens when a co. hires a linux groupie! > | > | I have to email this script to everyone and have them run it on their PCs, > | it is the only option I have. I can't push because there are 5 different > | domains, the servers are too old and don't serve DHCP at the present time. > | The servers in place are an NT4.0, a W2k and a Linux. > | > | All I need to do is find the lmhosts file and add one line of information to > | it. > | > | Greg > > Email them the updated LMHOSTS file with a simple copy script that will drop the new LMHOSTS > file in their etc folder. > -- > Dave > http://www.claymania.com/removal-trojan-adware.html > http://www.ik-cs.com/got-a-virus.htm > > > Greg Mohr wrote:
Show quote > That would be great if it were only that simple. I have been told Script that simply has:> that some of the PC's may have had the file modified already and I > can't risk blowing those entries away. So my only solution is to try > and append a line to the file that already exists on each PC. > > Greg > > "David H. Lipman" wrote: > >> From: "Greg Mohr" <GregM***@discussions.microsoft.com> >> >>> There are no logon scripts as 5 companies have been bought and >>> cobbled together under a holding company. I have to email it as I >>> have 5 separate networks using a VPN tunnel to a colocated server. >>> I don't have servers in every location and the servers that are >>> there do not "talk" with each other yet. This is what happens when >>> a co. hires a linux groupie! >>> >>> I have to email this script to everyone and have them run it on >>> their PCs, it is the only option I have. I can't push because >>> there are 5 different domains, the servers are too old and don't >>> serve DHCP at the present time. The servers in place are an NT4.0, >>> a W2k and a Linux. >>> >>> All I need to do is find the lmhosts file and add one line of >>> information to it. >>> >>> Greg >> >> Email them the updated LMHOSTS file with a simple copy script that >> will drop the new LMHOSTS file in their etc folder. >> -- >> Dave >> http://www.claymania.com/removal-trojan-adware.html >> http://www.ik-cs.com/got-a-virus.htm echo YOURLMHOSTLINEHERE >> %SystemRoot%\System32\drivers\etc\lmhosts in it? Of course - that is assuming that you can email a batch/other script to them through any email protection they may have on their servers/client. -- Shenan Stanley MS-MVP -- How To Ask Questions The Smart Way http://www.catb.org/~esr/faqs/smart-questions.html Greg,
You have a mix of different variables names. You're declaring FileSys, Shell and File as variables but then right below that you are using different variable names: objShell, objFolder and objFolderItem. Then you are trying to use File.WriteLine and File.Close, but how is the script supposed to know what "File" is? You should get in the habit of always making this the first line of every script you write: Option Explicit You really need to read some primers or books on scripting. If you try to write a script and send this through email for users to run on their system and make changes to name resolution, you're asking for trouble. Scripting is powerful, but can also be dangerous. Show quote "Greg Mohr" <GregM***@discussions.microsoft.com> wrote in message news:2948E6D4-3E7A-46CC-8A9C-AAAFB3832D0F@microsoft.com... > That would be great if it were only that simple. I have been told that > some > of the PC's may have had the file modified already and I can't risk > blowing > those entries away. So my only solution is to try and append a line to > the > file that already exists on each PC. > > Greg > > "David H. Lipman" wrote: > >> From: "Greg Mohr" <GregM***@discussions.microsoft.com> >> >> | There are no logon scripts as 5 companies have been bought and cobbled >> | together under a holding company. I have to email it as I have 5 >> separate >> | networks using a VPN tunnel to a colocated server. I don't have >> servers in >> | every location and the servers that are there do not "talk" with each >> other >> | yet. This is what happens when a co. hires a linux groupie! >> | >> | I have to email this script to everyone and have them run it on their >> PCs, >> | it is the only option I have. I can't push because there are 5 >> different >> | domains, the servers are too old and don't serve DHCP at the present >> time. >> | The servers in place are an NT4.0, a W2k and a Linux. >> | >> | All I need to do is find the lmhosts file and add one line of >> information to >> | it. >> | >> | Greg >> >> Email them the updated LMHOSTS file with a simple copy script that will >> drop the new LMHOSTS >> file in their etc folder. >> -- >> Dave >> http://www.claymania.com/removal-trojan-adware.html >> http://www.ik-cs.com/got-a-virus.htm >> >> >> From: "Greg Mohr" <GregM***@discussions.microsoft.com> The following will concatenate one file to another using;| That would be great if it were only that simple. I have been told that some | of the PC's may have had the file modified already and I can't risk blowing | those entries away. So my only solution is to try and append a line to the | file that already exists on each PC. | | Greg copy file1 + file2 file3 Where file3 is the concatenated version of file1 and file2 UPDATE.CMD ---------------------- @echo off copy "%windir%\system32\drivers\etc\lmhosts" "%windir%\system32\drivers\etc\lmhosts.old" Copy /y c:\lmhosts + "%windir%\system32\drivers\etc\lmhosts.old" "%windir%\system32\drivers\etc\lmhosts" Just an idea to keep it simple. On Sat, 30 Jul 2005 15:14:57 -0400, "David H. Lipman"
<DLipman~nospam~@Verizon.Net> wrote: Show quote >From: "Greg Mohr" <GregM***@discussions.microsoft.com> And as an aside, this is exactly the way I've done it in the past.> >| That would be great if it were only that simple. I have been told that some >| of the PC's may have had the file modified already and I can't risk blowing >| those entries away. So my only solution is to try and append a line to the >| file that already exists on each PC. >| >| Greg > >The following will concatenate one file to another using; >copy file1 + file2 file3 > >Where file3 is the concatenated version of file1 and file2 > >UPDATE.CMD >---------------------- >@echo off >copy "%windir%\system32\drivers\etc\lmhosts" "%windir%\system32\drivers\etc\lmhosts.old" >Copy /y c:\lmhosts + "%windir%\system32\drivers\etc\lmhosts.old" >"%windir%\system32\drivers\etc\lmhosts" > > >Just an idea to keep it simple. (Okay, way far past, since we were updating WFW systems....). Jeff |
|||||||||||||||||||||||