October 13, 2008 at 5:07 pm
According to my project plan we need to stop certain services for our refresh. Currently I do it manually like going to the services and manually stopping it and putting it into manual mode. Is there any script I can use to stop the services and keeping it into the manual mode.
Thanks
October 13, 2008 at 5:44 pm
you could try using xp_cmdshell (if it is enabled)
eg
xp_cmdshell 'net stop servicename'
and
xp_cmdshell 'net start servicename'
there is probably also some sample code utilising OLE around as well.
October 14, 2008 at 5:01 am
magennis.weate (10/13/2008)
you could try using xp_cmdshell (if it is enabled)
That certainly works for me. xp_cmdshell is useful for passing commands to the OS but a word of warning, it is better to put all required OS commans e.g stop, start, waits etc into a batch file and then call the batch file with xp_cmdshell.
If you are wanting to comunicate and pass service start and stop commands to a remote server my suggestion would to use psservice.exe (http://technet.microsoft.com/en-us/sysinternals/bb897542.aspx). The way i use it is to call the psservice and batch from the SQL server.
Let me know it goes.
Adam Zacks-------------------------------------------Be Nice, Or Leave
December 14, 2009 at 8:36 am
Hi
I'm trying to get this working on our servers, so that we can stop services as part of a scheduled job, but it appears that it won't run unless we have first manually opened a command prompt by using the Run As.... option.
We thought it may have something to do with the initial sysinternal usage agreement.
Could you let me know how you got it working
- Thanks!
_____________________________________________________________________________MCITP: Business Intelligence Developer (2005)
December 14, 2009 at 8:49 am
I'm guessing that maybe your issue is access rights. In my case the service account for sql (or at least the account that the impersination is using) has to have relevant permissions to run the command.
As a test, try it using a local admin account.
I've just looked at one of my old solutions (using a siss package) and in the same case as you, to stop a service on a remote server i have used 'psservice' (its only a tiny file). In my case, psservice was on the c: of sql and i accessed it that way.
BUT, you do need rights on the remote server.
Adam Zacks-------------------------------------------Be Nice, Or Leave
December 14, 2009 at 9:27 am
Thanks adam. We pretty much found the permissions were the issue.
My colleague and I have just found that we need to specificy the SQL Service Account as part of the administrators group on the remote machine because SQL Service Account is logged on as part of running the SQL Agent service.
We could you it without adding the the Service Account to the admin group on the remote server, but this meant having to define a username and password for the remote server in the psservice command, which we wanted to avoid.
(it looks like the account you want to use to run the psservice command will work, so long as it is running something).
Previously we were trying to use a Proxy Account with Domain Admin rights (which should have all the necessary permissions), but this didn't work, unless we had opened a command prompt using Run As... and specifying the proxy account. Very confusing, but we got there.
Thanks again though for your assistance and quick reply. It's appreciated. 😀
_____________________________________________________________________________MCITP: Business Intelligence Developer (2005)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply