ورود

View Full Version : سوال: Start کردن sqlMangr بوسیله کد نویسی



z_bluestar
دوشنبه 24 فروردین 1388, 10:41 صبح
سلام
من میخوام تو کد نویسی Stop یا Start بودن SqlMangr تشخیص بدم و اگر Stop بود آن را Start کنم.
اگه کمک کنید مشکر می شم :لبخندساده:

z_bluestar
دوشنبه 24 فروردین 1388, 16:22 عصر
کسی نیست بتونه کمک کنه ؟؟؟

vcldeveloper
دوشنبه 24 فروردین 1388, 16:52 عصر
برید درباره Start و Stop کردن یک Windows Service جستجو کنید. SQL Server هم یکی سرویسی هست مثل سایر سرویس های ویندوز، و میشه مثل آنها آن را Start یا Stop کرد.

Ahmad Chehreghani
سه شنبه 25 فروردین 1388, 13:15 عصر
سلام
با اين برنامه اي که قرار دادم شما مي تونيد ليست سرويس هاي ويندوز رو نمايش بديد و سرويس ها را Start يا Stop کنيد
سرويس Sqlserver اسمش MSSQLServer هست
موفق باشيد

z_bluestar
سه شنبه 25 فروردین 1388, 16:33 عصر
برنامه رو اجرا کردم ولی MSSQLSERVER رو نه start کرد نه Stop :ناراحت:

Ahmad Chehreghani
سه شنبه 25 فروردین 1388, 17:58 عصر
من تست کردم جواب داد...
وقتي روي کليد Start ميزنيد يک بار روي يک سرويس ديگه کليک کنيد و بعد دوباره روي همون سرويسي که استارتش کرديد کليک کنيد ببينيد در قسمت Current Status چي مينويسيه.
اصلا ببينيد خودتون مي تونيد سرويس را Start کنيد!

z_bluestar
پنج شنبه 27 فروردین 1388, 10:06 صبح
تو اینترنت هم در مورد Windows Service ها جستجو کردم ولی نتونستم کد Delphi پیدا کنم :ناراحت:

as13851365
پنج شنبه 27 فروردین 1388, 11:15 صبح
من خودم تا حالا امتحانش نکردم ولی یه کد دارم نمی دونم به کارت می آد یا نه.

Start كردن سرويسهاي ويندوز



uses WinSvc;

//
// start service
//
// return TRUE if successful
//
// sMachine:
// machine name, ie: \\SERVER
// empty = local machine
//
// sService
// service name, ie: Alerter
//
function ServiceStart(
sMachine,
sService : string ) : boolean;
var
//
// service control
// manager handle
schm,
//
// service handle
schs : SC_Handle;
//
// service status
ss : TServiceStatus;
//
// temp char pointer
psTemp : PChar;
//
// check point
dwChkP : DWord;
begin
ss.dwCurrentState := -1;

// connect to the service
// control manager
schm := OpenSCManager(
PChar(sMachine),
Nil,
SC_MANAGER_CONNECT);

// if successful...
if(schm > 0)then
begin
// open a handle to
// the specified service
schs := OpenService(
schm,
PChar(sService),
// we want to
// start the service and
SERVICE_START or
// query service status
SERVICE_QUERY_STATUS);

// if successful...
if(schs > 0)then
begin
psTemp := Nil;
if(StartService(
schs,
0,
psTemp))then
begin
// check status
if(QueryServiceStatus(
schs,
ss))then
begin
while(SERVICE_RUNNING
<> ss.dwCurrentState)do
begin
//
// dwCheckPoint contains a
// value that the service
// increments periodically
// to report its progress
// during a lengthy
// operation.
//
// save current value
//
dwChkP := ss.dwCheckPoint;

//
// wait a bit before
// checking status again
//
// dwWaitHint is the
// estimated amount of time
// the calling program
// should wait before calling
// QueryServiceStatus() again
//
// idle events should be
// handled here...
//
Sleep(ss.dwWaitHint);

if(not QueryServiceStatus(
schs,
ss))then
begin
// couldn't check status
// break from the loop
break;
end;

if(ss.dwCheckPoint <
dwChkP)then
begin
// QueryServiceStatus
// didn't increment
// dwCheckPoint as it
// should have.
// avoid an infinite
// loop by breaking
break;
end;
end;
end;
end;

// close service handle
CloseServiceHandle(schs);
end;

// close service control
// manager handle
CloseServiceHandle(schm);
end;

// return TRUE if
// the service status is running
Result :=
SERVICE_RUNNING =
ss.dwCurrentState;
end;

// *************** مثال ***********
if( ServiceStart('\\ComputerName','alerter' ) )then
begin
// "alerter" service on \




Stop كردن سرويسهاي ويندوز


//
// stop service
//
// return TRUE if successful
//
// sMachine:
// machine name, ie: \\SERVER
// empty = local machine
//
// sService
// service name, ie: Alerter
//
function ServiceStop(
sMachine,
sService : string ) : boolean;
var
//
// service control
// manager handle
schm,
//
// service handle
schs : SC_Handle;
//
// service status
ss : TServiceStatus;
//
// check point
dwChkP : DWord;
begin
// connect to the service
// control manager
schm := OpenSCManager(
PChar(sMachine),
Nil,
SC_MANAGER_CONNECT);

// if successful...
if(schm > 0)then
begin
// open a handle to
// the specified service
schs := OpenService(
schm,
PChar(sService),
// we want to
// stop the service and
SERVICE_STOP or
// query service status
SERVICE_QUERY_STATUS);

// if successful...
if(schs > 0)then
begin
if(ControlService(
schs,
SERVICE_CONTROL_STOP,
ss))then
begin
// check status
if(QueryServiceStatus(
schs,
ss))then
begin
while(SERVICE_STOPPED
<> ss.dwCurrentState)do
begin
//
// dwCheckPoint contains a
// value that the service
// increments periodically
// to report its progress
// during a lengthy
// operation.
//
// save current value
//
dwChkP := ss.dwCheckPoint;

//
// wait a bit before
// checking status again
//
// dwWaitHint is the
// estimated amount of time
// the calling program
// should wait before calling
// QueryServiceStatus() again
//
// idle events should be
// handled here...
//
Sleep(ss.dwWaitHint);

if(not QueryServiceStatus(
schs,
ss))then
begin
// couldn't check status
// break from the loop
break;
end;

if(ss.dwCheckPoint <
dwChkP)then
begin
// QueryServiceStatus
// didn't increment
// dwCheckPoint as it
// should have.
// avoid an infinite
// loop by breaking
break;
end;
end;
end;
end;

// close service handle
CloseServiceHandle(schs);
end;

// close service control
// manager handle
CloseServiceHandle(schm);
end;

// return TRUE if
// the service status is stopped
Result :=
SERVICE_STOPPED =
ss.dwCurrentState;
end;

z_bluestar
پنج شنبه 27 فروردین 1388, 14:08 عصر
بالاخره موفق شدم :چشمک:مشکل برنامه اونجا بود
که سرویس SQLMangr رو سیستم به صورت ( SQLSERVER (MSSQLSERVER برمی گردوند و وقتی من به Function ورودی رو به صورت دستی MSSQLSERVER دادم برنامه درست عمل کرد