views:

145

answers:

2

Hi there:

I am developing an application (Delphi 7, windows XP) that uses a connection to a remote SQL Server. Sometimes, that server is down, and I want to do something to start it. I was trying to start SQL Server in a local context, and it was fine, it worked... But the point is that I have to start it up from a remote machine.

I can see SQL Server status from a remote server, but I can't start it up... Maybe it gets problems because of user and password, but where to specify the login to the remote machine?

Do you have any idea to do this???

I am sorry about my English.

Thanks.

+1  A: 

1) Use sc.exe from a batch file 2) Use the Service Control Manager API via code. You may need to change the process security context (i.e. calling ImpersonateLoggedOnUser) to be able to perform the desired operation, using the right user credentials.

ldsandon
A: 

Use OpenSCManager to obtain a handle to the (remote machine's) Service Control Manager, then use OpenService to get a handle to the SQL Server Service, finally use StartService to Start it.

If you want to do this under another account you can use the WNetAddConnection(2) function to connect with credentials (eg to \\machine\ipc$ or \\machine\admin$).

Remko