Announcement

Collapse
No announcement yet.

Start Service, set to Automatic - AD

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Start Service, set to Automatic - AD

    I was hoping to find a scrip that would start the "TCP/IP NetBIOS Helper" service on machines that are currently joined to a domain. I have about 500 client machines that need to have this service enabled in order to get group policies to begin working. Thanks.
    Brad

  • #2
    Re: Start Service, set to Automatic - AD

    That's pretty simple for NT/2000/XP clients.

    Create a batch file. Add the following to it...

    Apply logon script to OU/GPO etc.

    Code:
    sc.exe config "lmhosts" start = auto
    sc.exe start "lmhosts"
    Last edited by ahinson; 22nd August 2005, 22:40.
    Andrew

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment


    • #3
      Re: Start Service, set to Automatic - AD

      The problem that I am running into is that when I execute a 'gpupdate /force' it cannot find the gp.ini file that contains the policies, will this cause an issue. What I was hoping for was a particular script that doesn't require group policies since this is where I run into the problem.
      Brad

      Comment


      • #4
        Re: Start Service, set to Automatic - AD

        If you're worried about creating a GPO you can always apply it as a user level script. Granted its more work, but you can script adding the script
        Andrew

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        Comment


        • #5
          Re: Start Service, set to Automatic - AD

          Its not really that, the problem is that the computers are not taking policies because the "TCP/IP NetBIOS Helper" service is not running. I was hoping to find a way to minimize workload and therefore push this policy to each machine through Active Directory. I was hoping to not have to log into each machine.
          Brad

          Comment


          • #6
            Re: Start Service, set to Automatic - AD

            Have you tried to remotely run a script which will start these services?

            That should do the trick....

            Let me know if you need some sample code for that, if I don't have it, I can fairly easily locate it on the web.

            Comment


            • #7
              Re: Start Service, set to Automatic - AD

              Yeah, that is what I was hoping for. I found some stuff here:

              http://support.microsoft.com/default...b;en-us;887303

              I changed what I thought would've been straight answers.

              Code:
              Set objDictionary = CreateObject("Scripting.Dictionary")
              i = 0
              Set objOU = GetObject("LDAP://OU=Computers, OU=OUName, OU=OUName, DC=OUName,
              DC=OUName,DC=CompanyName,
              DC=com")
              objOU.Filter = Array("Computer")
              For Each objComputer In objOU
                      objDictionary.Add i, objComputer.CN
                      i = i + 1
              Next
              For Each objItem In objDictionary
                      strComputer = objDictionary.Item(objItem)
                      Set objWMIService =
              GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &
              "\root\cimv2")
              
                      Set colServices = objWMIService.ExecQuery _
                              ("Select * from Win32_Service where Name = 'TCP/IP NetBIOS Helper'")
                      For Each objService In colServices
                              If objService.StartMode = "Disabled" Then
                                      objService.Change( , , , , "Automatic")
                              End If
                      Next
              Next
              Assuming that is correct, Where would I need to put the OU and DOMAIN in that particular section of code. Thanks.
              Brad

              Comment


              • #8
                Re: Start Service, set to Automatic - AD

                Well found MSKB Article!

                I've attached a text file containing a basic script which should also do what you want to do.

                Okay - the script does what to pick up the machine names of the clients from a text file, but that can be changed it you wish to pick it up from the AD.

                I've done some basic tests with the script and the logic does work, all it needs is the reporting capability added to report which machines it was successful with and which ones it failed to start the service on for whatever reason.

                It takes about 2 to 4 seconds per machine, depending on the responsiveness of your network and workstations, so if you have about 500 workstations to run it against, it'll take about 15 to 40 minutes to execute. (Hey! its the ping test to check if the computer is alive which slows it down!) At least you can run it, walk away and do something else while it is busy.

                Hope this also helps!

                James
                Attached Files

                Comment


                • #9
                  Re: Start Service, set to Automatic - AD

                  Thanks James!

                  So I could essentially export the computers from AD into a text file. The only potential problem I see is with Windows XP clients that have the firewall turned on as they do not respond to pings. Did you think of anything that may allow me to get around this?
                  Brad

                  Comment


                  • #10
                    Re: Start Service, set to Automatic - AD

                    Originally posted by bredinger
                    So I could essentially export the computers from AD into a text file.
                    Thats one way to do it to restrict it to just the computers to want to apply it to.

                    Originally posted by bredinger
                    The only potential problem I see is with Windows XP clients that have the firewall turned on as they do not respond to pings. Did you think of anything that may allow me to get around this?
                    Gee thanks! Now that would be one way to quickly blow that nice little script out the water! Well spotted though....

                    And since the ping won't work, 50% chance the firewall may prevent the script from running even if you removed the ping check.

                    Maybe it can be integrated somehow into the logon script so that it is run when the user logs on. That means script would need to be changed; it would actually be a simpler script. I just noticed that ahinson provided the 2 lines which could go into the logon script which would do the trick.

                    Otherwise, I don't have any bright ideas straight off the top of my head. Maybe someone else knows of a workaround for that.

                    Comment


                    • #11
                      Re: Start Service, set to Automatic - AD

                      And since the ping won't work, 50% chance the firewall may prevent the script from running even if you removed the ping check.
                      You are correct sir...

                      I was testing this in my house last evening. I have now returned to work and I will see what possibilities there are for running this as a logon script. This user will need to have administrative rights to the workstation in order to change a service. I have just tested manually modifying this particular service while logged in as a Domain Admin, I am assuming that this should work. I will be sure to keep you posted, thanks for your help, but unfortunately I don't think we will be able to do this without visiting each workstation.
                      Brad

                      Comment


                      • #12
                        Re: Start Service, set to Automatic - AD

                        Code:
                        strComputer = "."
                        	arrTargetSvcs = Array("LmHosts")
                        
                        		Set objWMIService = GetObject("winmgmts:" & 
                        
                        "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                        		Set colServices = objWMIService.ExecQuery("SELECT * FROM 
                        
                        Win32_Service")
                        
                        		For Each objService in colServices
                        		  For Each strTargetSvc In arrTargetSvcs
                        		    If LCase(objService.Name) = LCase(strTargetSvc) Then
                        		      If objService.State = "Stopped" Then
                        		      	wscript.echo "Service is not started"
                        		        intStop = objService.StartService
                        		        If intStop = 0 Then
                        		          wscript.echo "Service has started"
                        		        Else
                        		          'Service was not started
                        		        End If
                        		      Else
                        			'Service already started
                        		      End If
                        		      If objService.StartMode = "Disabled" Then
                        		        intDisable = objService.ChangeStartMode("Automatic")
                        		        If intDisable = 0 Then
                        			  'Startup state succesfully changed
                        		        Else
                        		          'Startup state was not changed
                        		        End If
                        		      End If
                        		      If objService.StartMode = "Manual" Then
                        		        intDisable = objService.ChangeStartMode("Automatic")
                        		        If intDisable = 0 Then
                        			  'Startup state succesfully changed
                        		        Else
                        		          'Startup state was not changed
                        		        End If
                        		      End If
                        		    End If
                        		Next
                        		Next
                        
                        wscript.echo "Finished!"
                        wscript.quit
                        Well, I modified your code and this is what I get. My only problem right now is that it needs to be run twice. Once to change service from Disabled to Automatic and then a second time to start the service.

                        Code:
                        		        intStop = objService.StartService
                        		        If intStop = 0 Then
                        		          wscript.echo "Service has started"
                        That only displays the second time around...I know its possible for me to run this twice in a batch script but it will take some time that way.
                        Brad

                        Comment


                        • #13
                          Re: Start Service, set to Automatic - AD

                          Hmmm..... Now that is a little weird that you had to run it twice in order to get the state changed and to get it started. The test on my network did it all in 1 run.

                          Anyways - maybe try changing the order of things around. First change the state of startup and then actually start the service - maybe it'll work in 1 run like that.

                          It looks like you're on the right track to a solution now.....

                          Comment


                          • #14
                            Re: Start Service, set to Automatic - AD

                            Well, thanks for the insight. I created a batch script:

                            Code:
                            lmhosts.vbs
                            lmhosts.vbs
                            gpupdate /force
                            gpupdate /force
                            For the Windows 2000 workstations my boss just ran the script twice and then manually updated the group policies.

                            Thanks!
                            Brad

                            Comment


                            • #15
                              Re: Start Service, set to Automatic - AD

                              Originally posted by bredinger
                              Code:
                              Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service")
                              You can simplify and speed up the script greatly if you change the WQL query to:
                              Code:
                              Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name='lmhosts'")
                              This way only the LmHosts service will be selected and you won't need to perform additional checks and loop through all the services returned.
                              Guy Teverovsky
                              "Smith & Wesson - the original point and click interface"

                              Comment

                              Working...
                              X