Location: List Archives

List Archives

This forum is an archive of all posts to our mailing list over the past few years.  The forum is set read only therefore to contribute you will need to join our list community.  See more info about this here.

 

When subscribed to the list you should use your standard email client to send your posts to ActiveDir@mail.activedir.org.

List Archives

Subject: [ActiveDir] OT: Script Request - Restart Remote Service
Prev Next
You are not authorized to post a reply.

AuthorMessages
mark.parris@xxxx.yyy

01/20/2006 4:10 AM  
Does anyone have a nice applet to enable the remote manual restart of a service on a server? The service permissions have been delegated as the app that uses it is not very good and needs to be restarted numerous times a day - it never hangs so the inbuilt stuff is no good.

I have had a look but can find no examples to achieve my end goal.

Regards,

Mark
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
hcolemanUser is Offline

Posts:31

01/20/2006 4:32 AM  
Here is part of a script that I poached from somewhere. It's only set to
stop a list of services, but you could include a second step in the
For...Next loop that calls the oInstance.ExecMethod_("StartService")
after you've stopped the service.

Watch for line wraps and such...
sComputer = '
' In 'services_list', add your sevices in the order you want them to
stop.
' If some of the services have comma in their names,
' you must choose another delimiter
services_list =
"IMAP4Svc,POP3Svc,MSExchangeES,MSExchangeIS,MSExchangeMTA,MSExchangeSA,M
SExchangeMGMT,MSExchangeSRS,RESvc"
services_array = Split(services_list,",")
For i = 0 to UBound(services_array)
sService = Trim(services_array(i))
'fileTxt.WriteLine("ServiceName = " & sService)
Set oInstance =
GetObject("winmgmts:{impersonationLevel=impersonate}//" & sComputer & _
"/root/cimv2:Win32_Service=" & Chr(34) & sService & Chr(34))
'fileTxt.WriteLine("ServiceState = " &
oInstance.Properties_("State").Value)
fileTxt.WriteLine(oInstance.Name & ": " &
oInstance.Properties_("State").Value)
If (oInstance.Properties_("State").Value = "Running") Then
Set oOutParam = oInstance.ExecMethod_("StopService")

If oOutParam.ReturnValue = 0 Then
fileTxt.WriteLine(oInstance.Name & " stopped successfully")
Else
fileTxt.WriteLine(oInstance.Name & " failed to stop")
Select Case oOutParam.ReturnValue
Case 1 fileTxt.WriteLine("The request is not
supported.")
Case 2 fileTxt.WriteLine("The user did not have the
necessary access.")
Case 3 fileTxt.WriteLine("The service cannot be stopped
because other " & _
"services that are running are
dependent on it.")
Case 4 fileTxt.WriteLine("The requested control code is
not valid, or " & _
"it is unacceptable to the
service.")
Case 5 fileTxt.WriteLine("The requested control code
cannot be sent to " & _
"the service because the state
of the service.")
Case 6 fileTxt.WriteLine("The service has not been
started.")
Case 7 fileTxt.WriteLine("The service did not respond
to the stop request " & _
"in a timely fashion.")
Case 8 fileTxt.WriteLine("Unknown failure when stopping
the service.")
Case 9 fileTxt.WriteLine("The directory path to the
service executable was not found.")
Case 10 fileTxt.WriteLine("The service is already
stopped")
Case 11 fileTxt.WriteLine("The service database is
locked.")
Case 12 fileTxt.WriteLine("A dependency which this
service relies on " & _
"has been removed from the
system.")
Case 13 fileTxt.WriteLine("The service failed to find
the service needed " & _
"from a dependent service.")
Case 14 fileTxt.WriteLine("The service has been disabled
from the system.")
Case 15 fileTxt.WriteLine("The service does not have the
correct authentication " & _
"to run on the system.")
Case 16 fileTxt.WriteLine("This service is being removed
from the system.")
Case 17 fileTxt.WriteLine("There is no execution thread
for the service.")
Case 18 fileTxt.WriteLine("There are circular
dependencies when stopping the service.")
Case 19 fileTxt.WriteLine("There is a service running
under the same name.")
Case 20 fileTxt.WriteLine("There are invalid characters
in the name of the service.")
Case 21 fileTxt.WriteLine("Invalid parameters have been
passed to the service.")
Case 22 fileTxt.WriteLine("The account, which this
service is to run under is " & _
"either invalid or lacks the
permissions to run the service.")
Case 23 fileTxt.WriteLine("The service exists in the
database of services " & _
"available from the system.")
Case 24 fileTxt.WriteLine("The service is currently
paused in the system.")
End Select
End If
Do
' state will be "Stop Pending" until "Stopped".
' Adjust sleep as necessary, but do *not* remove it!
WScript.Sleep 1000
Set oInstance =
GetObject("winmgmts:{impersonationLevel=impersonate}//" & sComputer & _
"/root/cimv2:Win32_Service=" & Chr(34) & sService & Chr(34))
'fileTxt.WriteLine( "ServiceState = " &
oInstance.Properties_("State").Value
Stopped = False
if oInstance.Properties_("State") = "Stopped" Then
'fileTxt.WriteLine( sService & ": " &
oInstance.Properties_("State").Value
Stopped = True
end if
Loop until Stopped

End If
Next

-----Original Message-----
From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Mark Parris
Sent: Friday, January 20, 2006 9:06 AM
To: ActiveDir.org
Subject: [ActiveDir] OT: Script Request - Restart Remote Service

Does anyone have a nice applet to enable the remote manual restart of a
service on a server? The service permissions have been delegated as the
app that uses it is not very good and needs to be restarted numerous
times a day - it never hangs so the inbuilt stuff is no good.

I have had a look but can find no examples to achieve my end goal.

Regards,

Mark
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
AD000001290User is Offline

Posts:0

01/20/2006 4:44 AM  
www.protect-me.com/rtm/

There are several 'remote task manager' like apps out there.

neil
-----Original Message-----
From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Mark Parris
Sent: 20 January 2006 16:06
To: ActiveDir.org
Subject: [ActiveDir] OT: Script Request - Restart Remote Service

Does anyone have a nice applet to enable the remote manual restart of a
service on a server? The service permissions have been delegated as the
app that uses it is not very good and needs to be restarted numerous
times a day - it never hangs so the inbuilt stuff is no good.

I have had a look but can find no examples to achieve my end goal.

Regards,

Mark
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/

PLEASE READ: The information contained in this email is confidential and
intended for the named recipient(s) only. If you are not an intended
recipient of this email please notify the sender immediately and delete your
copy from your system. You must not copy, distribute or take any further
action in reliance on it. Email is not a secure method of communication and
Nomura International plc ('NIplc') will not, to the extent permitted by law,
accept responsibility or liability for (a) the accuracy or completeness of,
or (b) the presence of any virus, worm or similar malicious or disabling
code in, this message or any attachment(s) to it. If verification of this
email is sought then please request a hard copy. Unless otherwise stated
this email: (1) is not, and should not be treated or relied upon as,
investment research; (2) contains views or opinions that are solely those of
the author and do not necessarily represent those of NIplc; (3) is intended
for informational purposes only and is not a recommendation, solicitation or
offer to buy or sell securities or related financial instruments. NIplc
does not provide investment services to private customers. Authorised and
regulated by the Financial Services Authority. Registered in England
no. 1550505 VAT No. 447 2492 35. Registered Office: 1 St Martin's-le-Grand,
London, EC1A 4NP. A member of the Nomura group of companies.

List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
darren.marelia@xxxx.yyy

01/20/2006 6:26 AM  
Sc.exe is an easy command-line utility for managing local and remote
services. Comes with the OS.

-----Original Message-----
From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Mark Parris
Sent: Friday, January 20, 2006 8:06 AM
To: ActiveDir.org
Subject: [ActiveDir] OT: Script Request - Restart Remote Service

Does anyone have a nice applet to enable the remote manual restart of a
service on a server? The service permissions have been delegated as the
app that uses it is not very good and needs to be restarted numerous
times a day - it never hangs so the inbuilt stuff is no good.

I have had a look but can find no examples to achieve my end goal.

Regards,

Mark
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
dharrisUser is Offline

Posts:0

01/20/2006 7:12 AM  
Here's a script I use - prompts to stop or start the service; watch line
wrap & modify to suit your needs.

>>>>>>>
On Error Resume Next
Const TIMEOUT = 5
Set objShell = WScript.CreateObject("WScript.Shell")

ComputerName = "Server"
ServiceName = "SurfControl Scout Service"
Err.Clear
for each Service in _
GetObject("winmgmts:{impersonationLevel=impersonate}!//"&
ComputerName &"").ExecQuery _
("select * from Win32_Service where Name = '" & ServiceName &
"'")
If Err.Number 0 Then
MyErr = Err.Number & " - " & Err.Description
MsgBox MyErr
End If
Status = Service.State
If Err.Number 0 Then
MyErr = Err.Number & " - " & Err.Description
MsgBox MyErr
End If
If Status = "Running" Then
Action = InputBox("The SurfControl service is running; do you
want to stop it?" & vbCrLf & "Y or N","Web Filter","Y")
If UCase(Action) = "Y" Then
Service.StopService()
objShell.Popup "Stop request sent.", TIMEOUT
End If
ElseIf Status = "Stopped" Then
Action = InputBox("The SurfControl service is stopped; do you
want to start it?" & vbCrLf & "Y or N","Web Filter","Y")
If UCase(Action) = "Y" Then
Service.StartService()
objShell.Popup "Start request sent.", TIMEOUT
End If
Else
objShell.Popup "Service state cannot be determined.", TIMEOUT
End If
Next
>>>>>>>

-----Original Message-----
From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Mark Parris
Sent: 20 January 2006 16:06
To: ActiveDir.org
Subject: [ActiveDir] OT: Script Request - Restart Remote Service

Does anyone have a nice applet to enable the remote manual restart of a
service on a server? The service permissions have been delegated as the
app that uses it is not very good and needs to be restarted numerous
times a day - it never hangs so the inbuilt stuff is no good.

I have had a look but can find no examples to achieve my end goal.

Regards,

Mark
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/

PLEASE READ: The information contained in this email is confidential and
intended for the named recipient(s) only. If you are not an intended
recipient of this email please notify the sender immediately and delete
your copy from your system. You must not copy, distribute or take any
further action in reliance on it. Email is not a secure method of
communication and Nomura International plc ('NIplc') will not, to the
extent permitted by law, accept responsibility or liability for (a) the
accuracy or completeness of, or (b) the presence of any virus, worm or
similar malicious or disabling code in, this message or any
attachment(s) to it. If verification of this email is sought then please
request a hard copy. Unless otherwise stated this email: (1) is not, and
should not be treated or relied upon as, investment research; (2)
contains views or opinions that are solely those of the author and do
not necessarily represent those of NIplc; (3) is intended for
informational purposes only and is not a recommendation, solicitation or
offer to buy or sell securities or related financial instruments. NIplc
does not provide investment services to private customers. Authorised
and regulated by the Financial Services Authority. Registered in
England no. 1550505 VAT No. 447 2492 35. Registered Office: 1 St
Martin's-le-Grand, London, EC1A 4NP. A member of the Nomura group of
companies.

List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive:
http://www.mail-archive.com/activedir%40mail.activedir.org/
List info : http://www.activedir.org/List.aspx
List FAQ : http://www.activedir.org/ListFAQ.aspx
List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
kamleshapUser is Offline

Posts:27

01/21/2006 7:53 AM  
Message body was not found.
listmailUser is Offline

Posts:497

01/23/2006 3:56 AM  
Note that you want the SC that comes with Windows Server
2003 SP1 if you have Windows Server 2003 SP1 Servers since there was a change in
the SCuM ACL.

Also my svcutl knows how to handle that ACL as well and
allow you to stop/start with delegated perms.

To delegate the perms use subinacl
/service

From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx
[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx] On Behalf Of Kamlesh
ParmarSent: Saturday, January 21, 2006 2:52 AMTo:
ActiveDir@xxxxxxxxxxxxxxxxxxSubject: Re: [ActiveDir] OT: Script
Request - Restart Remote Service

Yup,

SC \\remoteserver stop myservice
SC \\remoteserver start myservice
* Assumes user or app running SC has enought rights to manage service
remotely.
Note: It doesn't handle auto management for dependent services,
same as other posted scripts

I have _vbscript_ to handle dependent services as well (put somewhere, need
to find)
 if you need it let me know

--
Kamlesh

On 1/20/06, Darren
Mar-Elia darren.marelia@xxxxxxxxx>
wrote:
Sc.exe
is an easy command-line utility for managing local and remoteservices.
Comes with the OS.-----Original Message-----From: ActiveDir-owner@xxxxxxxxxxxxxxxxxx[mailto:ActiveDir-owner@xxxxxxxxxxxxxxxxxx
] On Behalf Of Mark ParrisSent: Friday, January 20, 2006 8:06
AMTo: ActiveDir.orgSubject: [ActiveDir] OT: Script Request - Restart
Remote ServiceDoes anyone have a nice applet to enable the remote
manual restart of a service on a server? The service permissions have been
delegated as theapp that uses it is not very good and needs to be
restarted numeroustimes a day - it never hangs so the inbuilt stuff is no
good.I have had a look but can find no examples to achieve my end
goal. Regards,MarkList info   : http://www.activedir.org/List.aspxList
FAQ    : http://www.activedir.org/ListFAQ.aspx
List archive:http://www.mail-archive.com/activedir%40mail.activedir.org/List
info   : http://www.activedir.org/List.aspxList
FAQ    : http://www.activedir.org/ListFAQ.aspxList
archive: http://www.mail-archive.com/activedir%40mail.activedir.org/-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"Be the change you
want to see in the World"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You are not authorized to post a reply.
Forums >ActiveDir Mail List Archive >List Archives > [ActiveDir] OT: Script Request - Restart Remote Service



ActiveForums 3.7
AdventNet Banner
Friends

Friends

Namescape
Members

Members

MembershipMembership:
Latest New UserLatest:kosciesza69
New TodayNew Today:3
New YesterdayNew Yesterday:1
User CountOverall:4319

People OnlinePeople Online:
VisitorsVisitors:88
MembersMembers:0
TotalTotal:88

Online NowOnline Now:

Ads

Copyright 2008 ActiveDir.org
Terms Of Use