现在需要将MSSQL2000的服务在PB里重启动一下,大家有什么办法?

sybasebbs 2011-08-25 11:38:23
RT。希望有经过测试的代码可以用。

————————————————————————
http://www.sybasebbs.com
...全文
138 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sybasebbs 2011-08-29
  • 打赏
  • 举报
回复
谢谢,搞定!!虽然有些不是偶想的办法,不过还是解决了。结
yyoinge 2011-08-29
  • 打赏
  • 举报
回复
上面的链接有问题,试试这个
http://download.csdn.net/source/3557823
yyoinge 2011-08-27
  • 打赏
  • 举报
回复
sybasebbs 2011-08-26
  • 打赏
  • 举报
回复
谢谢,整体上可以用。目前还有二个问题:
一、如果说SQLSERVERAGENT服务也启动的话,它就停止不成功了,好像是这样,我测试多次都不能停止;
二、偶想要停止后再启动相应的服务,自动的,如果停止后马上启动就失败了。
再增加判断停止SQL前的SQLSERVERAGENT的服务的启动情况,如果已经启动,就先停止,但启动MSSQLSERVER后再启动。请问一下这样应该如何处理?谢谢。
yyoinge 2011-08-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ehxz 的回复:]
谢谢,整体上可以用。目前还有二个问题:
一、如果说SQLSERVERAGENT服务也启动的话,它就停止不成功了,好像是这样,我测试多次都不能停止;
二、偶想要停止后再启动相应的服务,自动的,如果停止后马上启动就失败了。
再增加判断停止SQL前的SQLSERVERAGENT的服务的启动情况,如果已经启动,就先停止,但启动MSSQLSERVER后再启动。请问一下这样应该如何处理?谢谢。
[/Quote]

以上问题已经处理,源码已经重新上传,你自己去下载吧
gui41021 2011-08-26
  • 打赏
  • 举报
回复
强 顶

RUN("NET STOP MSSQLSERVER /Y",minimized!)最小化运行 用户就不太在意了 效果好一些

试过把启动服务内容写在BAT里 然后用BAT潜行者转成EXE运行 就不弹大黑框了 不过被360 金山判定为病毒 直接kill了。。哎
yyoinge 2011-08-25
  • 打赏
  • 举报
回复
简单点的用
sc stop mssqlserver
这是关闭sqlserver服务的命令
sc start mssqlserver启动命令、

复杂点调用api
yyoinge 2011-08-25
  • 打赏
  • 举报
回复
yyoinge 2011-08-25
  • 打赏
  • 举报
回复
$PBExportHeader$nvo_systemserver.sru
forward
global type nvo_systemserver from nonvisualobject
end type
type service_status from structure within nvo_systemserver
end type
type query_service_config from structure within nvo_systemserver
end type
end forward

type SERVICE_STATUS from structure
Long dwServiceType
Long dwCurrentState
Long dwControlsAccepted
Long dwWin32ExitCode
Long dwServiceSpecificExitCode
Long dwCheckPoint
Long dwWaitHint
end type

type QUERY_SERVICE_CONFIG from structure
Long dwServiceType
Long dwStartType
Long dwErrorControl
Long lpBinaryPathName
Long lpLoadOrderGroup
Long dwTagId
Long lpDependencies
Long lpServiceStartName
Long lpDisplayName
end type

global type nvo_systemserver from nonvisualobject autoinstantiate
end type

type prototypes
FUNCTION ulong OpenSCManager(ref string lpMachineName,ref string lpDatabaseName,ulong dwDesiredAccess) LIBRARY "advapi32.dll" ALIAS FOR "OpenSCManagerA"

FUNCTION ulong CreateService(ulong hSCManager,ref string lpServiceName,ref string lpDisplayName,ulong dwDesiredAccess,ulong dwServiceType,ulong dwStartType,ulong dwErrorControl,ref string lpBinaryPathName,ref string lpLoadOrderGroup,ref ulong lpdwTagId,ref string lpDependencies,ref string lp,ref string lpPassword) LIBRARY "advapi32.dll" ALIAS FOR "CreateServiceA"

FUNCTION ulong DeleteService(ulong hService) LIBRARY "advapi32.dll"

FUNCTION ulong CloseServiceHandle(ulong hSCObject) LIBRARY "advapi32.dll"

FUNCTION ulong OpenService(ulong hSCManager,ref string lpServiceName,ulong dwDesiredAccess) LIBRARY "advapi32.dll" ALIAS FOR "OpenServiceA"

FUNCTION ulong QueryServiceConfig(ulong hService,ref QUERY_SERVICE_CONFIG lpServiceConfig,ulong cbBufSize,ref ulong pcbBytesNeeded) LIBRARY "advapi32.dll" ALIAS FOR "QueryServiceConfigA"

FUNCTION ulong QueryServiceStatus(ulong hService,ref SERVICE_STATUS lpServiceStatus) LIBRARY "advapi32.dll"

FUNCTION ulong ControlService(ulong hService,ulong dwControl,ref SERVICE_STATUS lpServiceStatus) LIBRARY "advapi32.dll"

FUNCTION ulong StartService(ulong hService,ulong dwNumServiceArgs,ulong lpServiceArgVectors) LIBRARY "advapi32.dll" ALIAS FOR "StartServiceA"

FUNCTION ulong ChangeServiceConfig(ulong hService,ulong dwServiceType,ulong dwStartType,ulong dwErrorControl,ref string lpBinaryPathName,ref string lpLoadOrderGroup,ref ulong lpdwTagId,ref string lpDependencies,ref string lpServiceStartName,ref string lpPassword,ref string lpDisplayName) LIBRARY "advapi32.dll" ALIAS FOR "ChangeServiceConfigA"

//再有类似的需求,要不定义到具体的对象上去,要不就名称取得更贴切些,否则很难被再次用到
SUBROUTINE CopyMemory(ref ulong pDesc, ulong pSource,ulong size) LIBRARY "kernel32.dll" ALIAS FOR "RtlMoveMemory"

FUNCTION ulong lstrcpy(ref string lpString1,ref long lpString2) LIBRARY "kernel32.dll" ALIAS FOR "lstrcpyA"

FUNCTION ulong lstrlen(ref long lpString) LIBRARY "kernel32.dll" ALIAS FOR "lstrlenA"

FUNCTION ulong NetWkstaUserGetInfo(ref string reserved,ref string lLevel,ref string pbBuffer) LIBRARY "Netapi32.DLL"

FUNCTION Long NetApiBufferFree ( Long Buffer) LIBRARY "NETAPI32.DLL"

function ulong GetLastError() library "kernel32.dll"

end prototypes

type variables
String Service_Name
String Service_Display_Name
String Service_File_Path
String Service_Description
String Service_Account
String Service_Password
Long Service_Type
Long Service_Interact





private:
constant ulong SERVICE_WIN32_OWN_PROCESS = 16
constant ulong SERVICE_INTERACTIVE_PROCESS = 256
constant ulong SERVICE_CONFIG_DESCRIPTION = 1
constant ulong ERROR_SERVICE_DOES_NOT_EXIST = 1060
constant ulong SC_MANAGER_CONNECT = 1
constant ulong SC_MANAGER_CREATE_SERVICE = 2
constant ulong STANDARD_RIGHTS_REQUIRED = 983040
constant ulong SERVICE_QUERY_CONFIG = 1
constant ulong SERVICE_CHANGE_CONFIG = 2
constant ulong SERVICE_QUERY_STATUS = 4
constant ulong SERVICE_ENUMERATE_DEPENDENTS = 8
constant ulong SERVICE_START = 16
constant ulong SERVICE_STOP = 32
constant ulong SERVICE_PAUSE_CONTINUE = 64
constant ulong SERVICE_INTERROGATE = 128
constant ulong SERVICE_USER_DEFINED_CONTROL = 256
constant ulong SERVICE_ALL_ACCESS = 983551

//Public Enum SERVICE_START_TYPE
constant ulong SERVICE_AUTO_START = 2
constant ulong SERVICE_DEMAND_START = 3
constant ulong SERVICE_DISABLED = 4

//Public Enum SERVICE_INTERACT_TYPE
constant ulong SERVICE_INTERACT_WITHNOT_DESKTOP = 16
constant ulong SERVICE_INTERACT_WITH_DESKTOP = 272

constant ulong SERVICE_ERROR_NORMAL = 1
constant ulong ERROR_INSUFFICIENT_BUFFER = 122
//Private Enum SERVICE_CONTROL
constant ulong SERVICE_CONTROL_STOP = 1
constant ulong SERVICE_CONTROL_PAUSE = 2
constant ulong SERVICE_CONTROL_CONTINUE = 3
constant ulong SERVICE_CONTROL_INTERROGATE = 4
constant ulong SERVICE_CONTROL_SHUTDOWN = 5

//Public Enum SERVICE_STATE
constant ulong SERVICE_STOPPED = 1
constant ulong SERVICE_START_PENDING = 2
constant ulong SERVICE_STOP_PENDING = 3
constant ulong SERVICE_RUNNING = 4
constant ulong SERVICE_CONTINUE_PENDING = 5
constant ulong SERVICE_PAUSE_PENDING = 6
constant ulong SERVICE_PAUSED = 7

end variables

forward prototypes
public function long of_getservicestatus (string as_server_name)
public function boolean of_getserviceconfig (string as_server_name)
public function long of_start (string as_server_name)
public function long of_statuschange (string as_server_name, integer ai)
public function long of_stop (string as_server_name)
end prototypes

public function long of_getservicestatus (string as_server_name);//判断服务状态
Long hSCManager
Long hService, ll_status
SERVICE_STATUS Status
string ls
setnull(ls)
hSCManager = OpenSCManager(ls, ls, SC_MANAGER_CONNECT)
If hSCManager > 0 Then
hService = OpenService(hSCManager,as_server_name, SERVICE_QUERY_STATUS)
If hService > 0 Then
If QueryServiceStatus(hService, Status) > 0 Then
ll_status = Status.dwCurrentState
End If
CloseServiceHandle(hService)
End If
CloseServiceHandle(hSCManager)
End If

return ll_status

end function

public function boolean of_getserviceconfig (string as_server_name);//检查服务是否按照

uLong hSCManager, hService, r, r1, ll_rtn
string s, ls_null
QUERY_SERVICE_CONFIG scfg, scfg1
setnull(ls_null)
hSCManager = OpenSCManager(ls_null, ls_null, SC_MANAGER_CONNECT)
If hSCManager > 0 Then
hService = OpenService(hSCManager,as_server_name, SERVICE_QUERY_CONFIG)
If hService > 0 Then
scfg = scfg1
If QueryServiceConfig(hService, SCfg, 36, r) = 0 Then
If getlasterror() = ERROR_INSUFFICIENT_BUFFER Then
r1 = r / 36 + 1
scfg = scfg1
If QueryServiceConfig(hService, SCfg, r1 * 36, r) > 0 Then
s = Space(lstrlen(SCfg.lpservicestartname))//
lstrcpy(s, SCfg.lpServiceStartName)
Service_Account = s
Else
ll_rtn = getlasterror()
End If
Else
ll_rtn = getlasterror()
End If
End If
CloseServiceHandle(hService)
Else
ll_rtn = getlasterror()
End If
CloseServiceHandle(hSCManager)
Else
ll_rtn = getlasterror()
End If

return ERROR_SERVICE_DOES_NOT_EXIST <> ll_rtn
end function

public function long of_start (string as_server_name);//启动服务,返回0为成功
Long hSCManager, hService, ll_rtn
string ls_null
setnull(ls_null)
hSCManager = OpenSCManager(ls_null, ls_null, SC_MANAGER_CONNECT)
If hSCManager > 0 Then
hService = OpenService(hSCManager, as_server_name, SERVICE_START)
If hService > 0 Then
If StartService(hService, 0, 0) = 0 Then
ll_rtn = getlasterror()
End If
CloseServiceHandle(hService)
Else
ll_rtn = getlasterror()
End If
CloseServiceHandle(hSCManager)
Else
ll_rtn =getlasterror()
End If


return ll_rtn
end function

public function long of_statuschange (string as_server_name, integer ai);/*
SERVICE_CONTROL_STOP = 1
SERVICE_CONTROL_PAUSE = 2
SERVICE_CONTROL_CONTINUE = 3
SERVICE_CONTROL_INTERROGATE = 4
SERVICE_CONTROL_SHUTDOWN = 5
*/
choose case ai
case SERVICE_CONTROL_STOP
case SERVICE_CONTROL_PAUSE
case SERVICE_CONTROL_CONTINUE
return of_start( as_server_name)
case SERVICE_CONTROL_INTERROGATE
case SERVICE_CONTROL_SHUTDOWN
case else
end choose

return 1
end function

public function long of_stop (string as_server_name);//停止服务,返回0为成功
Long hSCManager, hService, ll_rtn
string ls_null
SERVICE_STATUS Status
setnull(ls_null)
hSCManager = OpenSCManager(ls_null, ls_null, SC_MANAGER_CONNECT)
If hSCManager > 0 Then
hService = OpenService(hSCManager, as_server_name, SERVICE_STOP)
If hService > 0 Then
If ControlService(hService, SERVICE_CONTROL_STOP, Status) = 0 Then
ll_rtn = getlasterror()
End If
CloseServiceHandle(hService)
Else
ll_rtn = getlasterror()
End If
CloseServiceHandle(hSCManager)
Else
ll_rtn =getlasterror()
End If


return ll_rtn

end function

on nvo_systemserver.create
call super::create
TriggerEvent( this, "constructor" )
end on

on nvo_systemserver.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

yyoinge 2011-08-25
  • 打赏
  • 举报
回复


源码已经上传到我的资源,不过现在还看不到
sybasebbs 2011-08-25
  • 打赏
  • 举报
回复
我现在用RUN("NET STOP MSSQLSERVER /Y")
但是会弹出一个黑框,不好看,关键还要等待完成。再运行启动命令。
sybasebbs 2011-08-25
  • 打赏
  • 举报
回复
SC是啥?PB找不到这个命令啊

740

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧