Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Enable a disabled service

- - - - -

  • Please log in to reply
20 replies to this topic

#1
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
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.


How to remove advertisement from MSFN

#2
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
Which OS?
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#3
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
Oops, sorry.

Windows XP

#4
jondercik

jondercik

    Advanced Member

  • Member
  • PipPipPip
  • 445 posts
  • Joined 15-January 04
Use GPO's
Jim
R.I.P. Alienware
1996-2006

#5
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
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.

#6
The-VOICE

The-VOICE

    Newbie

  • Member
  • 35 posts
  • Joined 31-March 05
To get you started from a command line type:


net start /?

or

sc /?

#7
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
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?

#8
jondercik

jondercik

    Advanced Member

  • Member
  • PipPipPip
  • 445 posts
  • Joined 15-January 04
use local gpos
Jim
R.I.P. Alienware
1996-2006

#9
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
Under what setting, I am looking through them now.

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

#10
thomasd

thomasd

    OS Reinstallation Expert

  • Member
  • 28 posts
  • Joined 07-December 04
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.
There's no point in being grown up if you can't be childish sometimes.

#11
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
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.

#12
The-VOICE

The-VOICE

    Newbie

  • Member
  • 35 posts
  • Joined 31-March 05
I would start by restricting users from controlling services. IMHO it sounds like you're approaching this backwards.

#13
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05

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

<{POST_SNAPBACK}>



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.

#14
Banditosway

Banditosway
  • Member
  • 6 posts
  • Joined 27-May 04
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.

#15
D8TA

D8TA

    Member

  • Member
  • PipPip
  • 136 posts
  • Joined 18-February 05
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.

#16
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

#17
cwuga

cwuga
  • Member
  • 1 posts
  • Joined 02-November 07
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.

#18
nmX.Memnoch

nmX.Memnoch

    MSFN Master

  • Patrons
  • 2,086 posts
  • Joined 15-September 04
  • OS:Windows 7 x64
  • Country: Country Flag

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 colServiceListobjService.ChangeStartMode("Automatic")Wscript.Sleep 5000errReturnCode = 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, 02 November 2007 - 02:22 PM.


#19
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#20
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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, 03 November 2007 - 01:39 PM.



GunSmokingMan



#21
nmX.Memnoch

nmX.Memnoch

    MSFN Master

  • Patrons
  • 2,086 posts
  • Joined 15-September 04
  • OS:Windows 7 x64
  • Country: Country Flag

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users