怎样用delphi打开启动任务栏右侧的SQL Server服务?(20分)

  • 主题发起人 主题发起人 caohaodelphi
  • 开始时间 开始时间
C

caohaodelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样用delphi打开启动任务栏右侧的SQL Server服务?
 
1.获得安装sqlserver服务器名称:
var
SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
sRetValue:String;
begin
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
nServers:=ServerList.Count;
for i := 1 to nservers do
ListBox1.Items.Add(ServerList.Item(i));
SQLServer:=NULL;
serverList:=NULL;
end;
2.启动sqlserver服务
uses Registry, ShellAPI, FileCtrl, Unit2;
{$R *.DFM}

function IsNT: Boolean;
begin
Result := (Win32MajorVersion >= 4) and (Win32Platform = VER_PLATFORM_WIN32_NT);
end;

var
IsExists: Boolean = False;
function IsExistsMSSQL: Boolean;
const
MSSQLSERVER = 'SOFTWARE/Microsoft/MSSQLServer';
var
Reg: TRegistry;
begin
Result := IsExists;
if Result then Exit;
if not IsNT then
Reg := TRegistry.Create else
Reg := TRegistry.Create(KEY_READ);
with Reg do
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Result := KeyExists(MSSQLSERVER);
IsExists := Result;
finally
Free;
end;
end;

const
MSSQL_98StartCommand = 'scm -action 1 -pwd "%s"';
MSSQL_NTStartCommand = 'net start mssqlserver';
MSSQL_98StopCommand = 'scm -action 6';
MSSQL_NTStopCommand = 'net stop mssqlserver';

function StartMSSQL(Pass: string): Boolean;
var
S: string;
begin
Screen.Cursor := crHourGlass;
try
if not IsNT then
S := Format(MSSQL_98StartCommand, [Pass]) else
S := MSSQL_NTStartCommand;
try
WinExec(PChar(S), SW_HIDE);
Result := True;
except
Result := False;
end;
finally
Screen.Cursor := crDefault;
end;
end;

function StopMSSQL: Boolean;
begin
Screen.Cursor := crHourGlass;
try
try
if not IsNT then
WinExec(MSSQL_98StopCommand, SW_HIDE) else
WinExec(MSSQL_NTStopCommand, SW_HIDE);
Result := True;
except
Result := False;
end;
finally
Screen.Cursor := crDefault;
end;
end;
 
接受答案了.
 
后退
顶部