hi Marcos,
[quoted text, click to view] Marcos Lommez wrote:
> I need this because after installing the MSDE through InstallShield,
> im changing the listening port in the windows registry. So i need to
> restart it.
>
> Im not an advanced of MS SQL Server. What would be SQL-DMO?
> Is possible to implement that object in Delphi language for example?
>
SQL-DMO is a COM component and you can use it in Delphi.., but it must be
registered at install time (actually you are the installer) and I really do
not know if it works in this condition...
but you can have a look at the scm, SQL Service Control Manager API,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/coprompt/cp_scm_9f95.asp
c:\..\>scm.exe -Action 1 -Silent 1 -Service MSSQL$InstanceName
or even something like (VB6)
Option Explicit
Private Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type
Private Const SERVICE_STOP = &H20
Private Const SERVICE_CONTROL_STOP = &H1
Private Const SC_MANAGER_CONNECT = &H1
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias
"OpenSCManagerA" _
(ByVal lpMachineName As String, _
ByVal lpDatabaseName As String, _
ByVal dwDesiredAccess As Long) As Long
Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA"
_
(ByVal hSCManager As Long, _
ByVal lpServiceName As String, _
ByVal dwDesiredAccess As Long) As Long
Private Declare Function ControlService Lib "advapi32.dll" _
(ByVal hService As Long, _
ByVal dwControl As Long, _
lpServiceStatus As SERVICE_STATUS) As Long
Private Declare Function CloseServiceHandle Lib "advapi32.dll" _
(ByVal hSCObject As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA"
_
(ByVal dwFlags As Long, _
lpSource As Any, _
ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, _
ByVal lpBuffer As String, _
ByVal nSize As Long, _
Arguments As Long) As Long
Private Sub ErrorMessage()
Dim ErrCode As Long
Dim NumCar As Long
Dim Text As String
ErrCode = GetLastError
Text = Space$(1000)
NumCar = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ErrCode, 0, Text,
Len(Text), 0)
MsgBox Text, vbCritical
End Sub
Public Sub StopService(ByVal ServiceName As String)
Dim hSCManager As Long
Dim hService As Long
Dim hControl As Long
Dim hClose As Long
Dim ServStatus As SERVICE_STATUS
'open services database
hSCManager = OpenSCManager(vbNullString, vbNullString,
SC_MANAGER_CONNECT)
If hSCManager <> 0 Then
'access the service
hService = OpenService(hSCManager, ServiceName, SERVICE_STOP)
If hService <> 0 Then
'post "Stop" command to it
hControl = ControlService(hService, SERVICE_CONTROL_STOP,
ServStatus)
If hControl <> 0 Then
'clean-up and close handlers
hClose = CloseServiceHandle(hService)
Else
ErrorMessage
End If
Else
ErrorMessage
End If
hClose = CloseServiceHandle(hSCManager)
Else
ErrorMessage
End If
End Sub
Sub Main()
StopService "MSSQLServer"
End Sub
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org DbaMgr2k ver 0.18.0 - DbaMgr ver 0.62.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply