D8TA

Enable a disabled service

21 posts in this topic

I noticed I have users who are disabling services. I am trying to figure out how to re-enable a disable sevice via the command line. I am going to add this to a login script so everytime a user logs in these services will re-enable, if disabled, and restart or start.

0

Share this post


Link to post
Share on other sites

Currently the PCs I manage aren't in a domain environment and that is what I need something from a login script. Hopefully in the near future all these machines will be part of AD.

Which takes me back to my original question, how do I re-enable a disable sevice via the command line. I am going to add this to a login script so everytime a user logs in these services will re-enable, if disabled, and restart or start.

0

Share this post


Link to post
Share on other sites

To get you started from a command line type:

net start /?

or

sc /?

0

Share this post


Link to post
Share on other sites

Thanks but I know the net start or sc commands. I keep getting this error message:

C:\>sc \\pc11091-vm config icollectservice start=auto

[sC] OpenSCManager FAILED 1722:

The RPC server is unavailable.

The RPC service is started and running am I missing something?

0

Share this post


Link to post
Share on other sites

Under what setting, I am looking through them now.

I would still like a command line syntax for use with a login script.

0

Share this post


Link to post
Share on other sites

You can use gpedit on the PC's.

It will give you the same benefit as GPO's in a domain, but you have to apply it on all the PC's seperatly.

Just click start, run, and type gpedit.msc

Here you have all the functions to lock down the PC, but be careful not to shut yourself out of the system.

0

Share this post


Link to post
Share on other sites

I am not finding anything on the services??? I have looked through all the tabs within Group Policy, where can I find the area for the services? I have utilized the Group Policy for a few items and deployed through Radia. But that is one issue I have is users are Disabling the Radia services so I am unable to deploy these settings. Thus the need for a login script, everyone needs to log into the network.

0

Share this post


Link to post
Share on other sites

I would start by restricting users from controlling services. IMHO it sounds like you're approaching this backwards.

0

Share this post


Link to post
Share on other sites
I would start by restricting users from controlling services.  IMHO it sounds like you're approaching this backwards.

How would I go about restricting the services within group policy? Your right I am, this would prevent them from doing it again after I have the service started again.

0

Share this post


Link to post
Share on other sites

To re-enable a disabled service, you can also use a vbscript (if you're familar with using them). That could be run from command line too. In it you can specify which service you are looking for and check whether it's currently running or stopped. If stopped, then start it. (I can give an example if need be).

To prevent users from stopping the services, then listen to the above postings and lock them down via Policies.

0

Share this post


Link to post
Share on other sites

Banditosway, could you give me an example using the service 'icollectservice'

I am looking through the Policies but am not seeing anything that would allow me to specify just certain user(s) can make modification to certain Services.

0

Share this post


Link to post
Share on other sites

Here is a basic batch example using sc.exe, it checks if the services are running, if not starts them.

@echo off &&setlocal
set tocheck=servicename1 servicename2 servicename3
for %%a in (%tocheck%) do (
 sc.exe query %%a | find /i "state" | find /i "4  running" >nul
 if not errorlevel 0 sc start %%a
)
endlocal &&goto :eof

Just replace the required 'Service Names', servicename1 servicename2 servicename3 with the ones you wish to check.

It isn't ideal for your requirements but may help you out!

0

Share this post


Link to post
Share on other sites

I just copied/pasted/modified some .vbs stuff to do what I think you needed to get accomplished (I'm posting so others searching may find this answer since I don't think what he actually wanted to do was successfully posted).

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'YourServiceNameHere'")

For Each objService in colServiceList
objService.ChangeStartMode("Automatic")
Wscript.Sleep 5000
errReturnCode = objService.StartService()
Next

You can set objService.ChangeStartMode mode to Automatic, Manual, or Disabled. YMMV with this, but it worked for me.

0

Share this post


Link to post
Share on other sites
I would start by restricting users from controlling services. IMHO it sounds like you're approaching this backwards.

How would I go about restricting the services within group policy? Your right I am, this would prevent them from doing it again after I have the service started again.

The best way to stop them from messing around with services? Don't make them admins! :)

You can't restrict services with Group Policy until they're in an AD domain. Once you do that then you just create a Group Policy Object (GPO) that has the settings you want for the services. Then you apply that GPO to the OU that the computer accounts are in.

Here is a basic batch example using sc.exe, it checks if the services are running, if not starts them.
Unfortunately, you can't Start a service if it's set to Disabled so the state has to be changed first. :)
I just copied/pasted/modified some .vbs stuff to do what I think you needed to get accomplished (I'm posting so others searching may find this answer since I don't think what he actually wanted to do was successfully posted).

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'YourServiceNameHere'")

For Each objService in colServiceList
objService.ChangeStartMode("Automatic")
Wscript.Sleep 5000
errReturnCode = objService.StartService()
Next

You can set objService.ChangeStartMode mode to Automatic, Manual, or Disabled. YMMV with this, but it worked for me.

That script will do exactly what he wants as far as changing the state of the service. A mixture of that script and the one that Yzöwl posted could be used to both change the state to Automatic and then Start the service. :D Edited by nmX.Memnoch
0

Share this post


Link to post
Share on other sites
Here is a basic batch example using sc.exe, it checks if the services are running, if not starts them.
Unfortunately, you can't Start a service if it's set to Disabled so the state has to be changed first. :)
I was aware of that at the time of posting, as you will note by my full response. However since you have brought it up and I as a result of not fully answering the question haven't slept well in the last 2½ years, the following will do as requested.
@ECHO OFF&SETLOCAL
SET "_=servicename1 servicename2 servicename3"
FOR %%? IN (%_%) DO (CALL :CS_ %%?
IF ERRORLEVEL 4 SC CONFIG %%? START= AUTO)
GOTO :EOF
:CS_
FOR /F "TOKENS=2 DELIMS=: " %%? IN (
'SC QC %1^|FIND "START_TYPE"') DO EXIT/B %%?
GOTO :EOF

I'm not sure that the service would need starting as well, especially at login. If that is necessary then the appropriate line could be added to the batch file code now provided.

0

Share this post


Link to post
Share on other sites

Sorry for the length of the script, this is what it does

1:\ Creates Folder Windir\Logs\Service

2:\ It produces a text file named Windir\Logs\Service\ComputerName_UserName.txt

3:\ List all the services and there status.

Uncomment the areas needed to use

4:\ Start any service that not running,

5:\ Set how you want it the service to start

I thought this might be a better way to do what you want because you are going to run it as a log on script so you will be able to tell who is changing what. You will have to make some changes to the script, as I only tested this so there was no

run time errors.

Save As ServiceStartLog.vbs

'/-> This Is My Text Comment Line
' This Is A Standard Comment Line Remove This To Make That Part Of The Script Active
Option Explicit
'/-> Like Varibles But Never Change
Const NewText=2, AddText=8
'/-> Varibles
Dim ColItems, Computer, ObjItem, ObjS, Service, Ts
Computer = "."
'/-> Objects
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Wmi :Set Wmi = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Dim Sys :Set Sys = Act.Environment("Process")
Dim Loc :Loc = Sys("windir") & "\Logs\Service\"
Dim ArL :ArL = Chr(160) & Chr(171) & Chr(160)
Dim ArR :ArR = Chr(160) & Chr(187) & Chr(160)
Dim Lne :Lne = ArL & "----------------------------------------" & ArR
Dim Rpt :Rpt = Loc & Sys("ComputerName") & "_" & Sys("UserName") & ".txt"
'/-> Create Folder Windir\Logs If Missing
If Not Fso.FolderExists(Sys("windir") & "\Logs") Then
Fso.CreateFolder(Sys("windir") & "\Logs")
End If
'/-> Create Folder Windir\Logs\Service For Text File
If Not Fso.FolderExists(Sys("windir") & "\Logs\Service") Then
Fso.CreateFolder(Sys("windir") & "\Logs\Service")
End If
'/-> Checks If The Text File There
If Fso.FileExists(Rpt) Then
'/-> Add Text To The Text File, File Was There
Set Ts = Fso.OpenTextFile(Rpt,AddText,True)
StartReport()
Else
'/-> Creates New Text File, File Was Not There
Set Ts = Fso.OpenTextFile(Rpt,NewText,True)
StartReport()
End If
'/-> Start Collection
Set ColItems = Wmi.ExecQuery("SELECT * FROM Win32_Service",,48)
For Each ObjItem in ColItems
If ObjItem.Started = False Then
Ts.WriteLine Chr(160) & ArL & "Process Name " & ArR & ObjItem.Name
Ts.WriteLine Chr(160) & ArL & "Process State " & ArR & ObjItem.State
Ts.WriteLine Chr(160) & ArL & "Process Start Mode" & ArR & ObjItem.StartMode
Ts.WriteLine Chr(160) & ArL & "Process Full Name " & ArR & ObjItem.DisplayName
Ts.WriteLine Chr(160) & ArL & "Process Cmd Path " & ArR & ObjItem.PathName
Ts.WriteLine Lne
' Return = ObjS.StartService()
' WScript.Sleep 5000
'/-> Other Start Modes
'/-> ObjItem.ChangeStartMode("Disabled")
'/-> ObjItem.ChangeStartMode("Manual")
' Return = ObjItem.ChangeStartMode("Automatic")
End If
Next
'/-> Add Text Functions
Function StartReport()
Ts.WriteLine Lne
Ts.WriteLine Chr(160) & ArL & "Start Of The Script" & ArR & Now()
Ts.WriteLine Chr(160) & ArL & "Computer Name " & ArR & Sys("ComputerName")
Ts.WriteLine Chr(160) & ArL & "User Login Name " & ArR & Sys("UserName")
Ts.WriteLine Lne
End Function
Ts.WriteLine Chr(160) & ArL & "End Of The Script " & ArR & Time
Ts.WriteLine Lne & vbCrLf & Lne & vbCrLf
'/-> Close The Text File Object
Ts.Close()
'/-> Run Report
' Act.Run("notepad.exe " & Chr(34) & Rpt & Chr(34)),1,True

Desided to add a script that will just turn on any service that is turned off.

I have tested this and got no run time errors.

Save As ServiceStart.vbs

'/-> Varibles
Dim ColItems, Computer, ObjItem
Computer = "."
'/-> Objects
Dim Wmi :Set Wmi = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
'/-> Start Collection
Set ColItems = Wmi.ExecQuery("SELECT * FROM Win32_Service",,48)
For Each ObjItem in ColItems
If ObjItem.Started = False Then
' Return = ObjItem.StartService()
' WScript.Sleep 5000
'/-> Other Start Modes
'/-> ObjItem.ChangeStartMode("Disabled")
'/-> ObjItem.ChangeStartMode("Manual")
' Return = ObjItem.ChangeStartMode("Automatic")
End If
Next

Edited by gunsmokingman
0

Share this post


Link to post
Share on other sites
haven't slept well in the last 2½ years

Yeah...I didn't notice how old the original thread was until after I'd already replied. I could've edited the post but it was already too late anyway... :D

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.