急!!如何启动局域网内其它机子的“server”这个服务!在线等待 ( 积分: 50 )

  • 主题发起人 主题发起人 lsxysuper
  • 开始时间 开始时间
L

lsxysuper

Unregistered / Unconfirmed
GUEST, unregistred user!
我想利用“server”这个服务来使用net time 和at 这两个命令,使的局域网内其它机子可以被指定时间运行一个exe。<br>我们例子:<br>net time //10.20.40.136<br>//result=18:56<br>at //10.20.40.136 19:00 &quot;f:/super/project2server.exe&quot;<br><br>但是这样必需使的局域网内的其它机子的&quot;server&quot;这个服务是要在启动的状态?<br>请问各们大虾,有什么办法启动局域网内的其它机子的&quot;server&quot;这个服务啊
 
我想利用“server”这个服务来使用net time 和at 这两个命令,使的局域网内其它机子可以被指定时间运行一个exe。<br>我们例子:<br>net time //10.20.40.136<br>//result=18:56<br>at //10.20.40.136 19:00 &quot;f:/super/project2server.exe&quot;<br><br>但是这样必需使的局域网内的其它机子的&quot;server&quot;这个服务是要在启动的状态?<br>请问各们大虾,有什么办法启动局域网内的其它机子的&quot;server&quot;这个服务啊
 
http://borland.mblogger.cn/aiirii/posts/2893.aspx<br>設定NtService的運行狀態 <br><br>你必须先用<br>SC_HANDLE OpenSCManager(<br> &nbsp;LPCTSTR lpMachineName,<br> &nbsp;LPCTSTR lpDatabaseName,<br> &nbsp;DWORD dwDesiredAccess<br>);<br><br>打开对应机器的 Service 管理器,才能操作
 
uses<br> &nbsp;WinSvc;<br>//启动一个服务.......//机器名,服务名.<br>function ServiceStart(const sMachine, sService: string) : Boolean;<br>var<br> &nbsp;schm,schs: SC_Handle;<br> &nbsp;ss: TServiceStatus;<br> &nbsp;psTemp: PChar;<br> &nbsp;dwChkP: DWord;<br>begin<br> &nbsp;ss.dwCurrentState := 0;<br> &nbsp;schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);<br> &nbsp;if (schm&gt;0) then<br> &nbsp;begin<br> &nbsp; schs := OpenService(schm, PChar(sService), SERVICE_START or SERVICE_QUERY_STATUS);<br> &nbsp; &nbsp;if (schs&gt;0) then<br> &nbsp; begin<br> &nbsp; &nbsp; psTemp := nil;<br> &nbsp; &nbsp; &nbsp;if (StartService(schs, 0, psTemp)) then<br> &nbsp; &nbsp; &nbsp; &nbsp;if (QueryServiceStatus(schs, ss)) then<br> &nbsp; &nbsp; &nbsp; &nbsp; while (SERVICE_RUNNING&lt;&gt;ss.dwCurrentState) do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwChkP := ss.dwCheckPoint;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Sleep(ss.dwWaitHint);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not QueryServiceStatus(schs, ss)) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ss.dwCheckPoint &lt;&gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;CloseServiceHandle(schs);<br> &nbsp; &nbsp;end;<br> &nbsp; CloseServiceHandle(schm);<br> &nbsp;end;<br> Result := SERVICE_RUNNING=ss.dwCurrentState;<br>end;
 
to dedema<br>谢谢 dedema 给我提示<br>我怎么不能成功啊,程序没错误,但是不能启动‘server’这个服务,是什么原因啊???
 
对自己的机子是能启动的,但对局域网内的其它机子就不行?是什么原因啊??
 
应该是权限的问题,你把SC_MANAGER_CONNECT 改SC_MANAGER_ALL_ACCESS.
 
to dedema<br>我改过了 ,可是还是不行!是什么原因?<br>请问你自己试过有用的吗?
 
这是一个打开远程机器Telnet服务的例子程序。<br>需要远程主机有启动服务权限的用户名、密码,且远程主机的远程注册表服务要已打开(若远程主机Telnet服务被禁用,强制改为允许用)。<br>n久前的东西了,应该还能有帮助吧。<br>//========unit1.pas===========<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, WinSvc, Clipbrd;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;Edit2: TEdit;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;Label3: TLabel;<br> &nbsp; &nbsp;Edit3: TEdit;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;scHandle:SC_HANDLE;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure ConnIPC(RemoteName,User,Pass:string);<br>var<br> &nbsp;nr:NETRESOURCE;<br> &nbsp;RN:string;<br>begin<br> &nbsp;RN:='//';<br> &nbsp;RN:=rn+RemoteName+'/ipc$';<br> &nbsp;nr.dwType:=RESOURCETYPE_ANY;<br> &nbsp;nr.lpLocalName:=NiL;<br> &nbsp;nr.lpRemoteName:=pchar(RN);<br> &nbsp;nr.lpProvider:=NiL;<br>// &nbsp;showmessage(rn+'::'+user+'::'+pass);<br> &nbsp;if not WNetAddConnection2(nr,pchar(Pass),pchar(User),0)=NO_ERROR then<br> &nbsp; &nbsp;showmessage('establish ipc$ connection error!!!');<br>end;<br><br>procedure CancelIPC(RemoteName,User,Pass:string);<br>var<br> &nbsp;nr:NETRESOURCE;<br> &nbsp;RN:string;<br>begin<br> &nbsp;RN:='//';<br> &nbsp;RN:=rn+RemoteName+'/ipc$';<br> &nbsp;nr.dwType:=RESOURCETYPE_ANY;<br> &nbsp;nr.lpLocalName:=NiL;<br> &nbsp;nr.lpRemoteName:=pchar(RN);<br> &nbsp;nr.lpProvider:=NiL;<br>// &nbsp;showmessage(rn+'::'+user+'::'+pass);<br> &nbsp;if not WNetCancelConnection2(pchar(rn),CONNECT_UPDATE_PROFILE,true)=NO_ERROR then<br> &nbsp; &nbsp;showmessage('stop ipc$ connection error!!!');<br>end;<br><br>function EnableServices(const pServiceName:PChar):bool;<br>var<br> &nbsp;osHandle:SC_HANDLE;<br> &nbsp;Qresult:BOOL;<br> &nbsp;Qsc:QUERY_SERVICE_CONFIG;<br> &nbsp;i:dword;<br>begin<br> &nbsp;Result:=false;<br>// &nbsp;showmessage(pServiceName);<br> &nbsp;osHandle:=OpenService(scHandle,pServiceName,SERVICE_ALL_ACCESS);<br> &nbsp;if osHandle&lt;&gt;0 then<br> &nbsp;begin<br> &nbsp; &nbsp;Qresult:=QueryServiceConfig(osHandle,@Qsc,Sizeof(Qsc),i);<br> &nbsp; &nbsp;if not Qresult then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if (Qsc.lpDependencies&lt;&gt;'') and (Qsc.lpDependencies[0]&lt;&gt;SC_GROUP_IDENTIFIER) then<br> &nbsp; &nbsp; &nbsp; &nbsp;EnableServices(Qsc.lpDependencies);<br>// &nbsp; &nbsp; &nbsp;showmessage('lpDependencies::'+Qsc.lpDependencies);<br> &nbsp; &nbsp; &nbsp;if Qsc.dwStartType=SERVICE_DISABLED then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Qsc.dwStartType:=SERVICE_DEMAND_START;<br> &nbsp; &nbsp; &nbsp; &nbsp;Qresult:=ChangeServiceConfig(osHandle,Qsc.dwServiceType,Qsc.dwStartType,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SERVICE_ERROR_IGNORE,nil,nil,nil,nil,nil,nil,Qsc.lpDisplayName);<br> &nbsp; &nbsp; &nbsp; &nbsp;if not Qresult then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;showmessage('ChangeServiceConfig::'+syserrormessage(getlasterror));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;CloseServiceHandle(osHandle);<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;showmessage('QueryServiceConfig::'+syserrormessage(getlasterror));<br> &nbsp; &nbsp; &nbsp;CloseServiceHandle(osHandle);<br> &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; &nbsp;end; &nbsp; //enable service<br> &nbsp;end<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('OpenService Error::'+syserrormessage(getlasterror));<br> &nbsp;end;<br> &nbsp;CloseServiceHandle(osHandle);<br> &nbsp;Result:=true;<br>end;<br><br>procedure StartTelnet(n:string);<br>var<br> &nbsp;lpServiceName:PChar;<br> &nbsp;b:bool;<br> &nbsp;osHandle:SC_HANDLE;<br> &nbsp;rkey,key1,key2:HKEY;<br> &nbsp;x:dword;<br>begin<br> &nbsp;ConnIPC(form1.Edit1.Text,form1.Edit2.Text,form1.Edit3.Text);<br> &nbsp;if RegConnectRegistry(PChar('//'+form1.Edit1.Text),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HKEY_LOCAL_MACHINE,rKey)=ERROR_SUCCESS then<br> &nbsp;begin<br> &nbsp; &nbsp;x:=3;<br> &nbsp; &nbsp;if RegOpenKey(rkey,PChar('SYSTEM/CurrentControlSet/Services/TlntSvr'),key1)=ERROR_SUCCESS then<br> &nbsp; &nbsp; &nbsp;RegSetValueEx(key1,'Start',0,reg_dword,@x,4);<br> &nbsp; &nbsp;RegCloseKey(Key1);<br> &nbsp; &nbsp;x:=0;<br> &nbsp; &nbsp;if RegOpenKey(rkey,PChar('SOFTWARE/Microsoft/TelnetServer/1.0'),key2)=ERROR_SUCCESS then<br> &nbsp; &nbsp; &nbsp;RegSetValueEx(key2,'NTLM',0,reg_dword,@x,4);<br> &nbsp; &nbsp;RegCloseKey(Key2); &nbsp;<br> &nbsp; &nbsp;RegCloseKey(rKey);<br> &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;showmessage('reg connect error');<br> &nbsp;lpServiceName:='TlntSvr'; &nbsp;//PChar(n)<br> &nbsp;scHandle:=OpenSCManager(PChar('//'+form1.Edit1.Text),NIL,SC_MANAGER_ALL_ACCESS);<br> &nbsp;if scHandle=0 then<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('OpenSCManager //'+form1.Edit1.Text +'Error::'+syserrormessage(getlasterror));<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;//////////<br> &nbsp;EnableServices(lpServiceName);<br> &nbsp;/////////<br> &nbsp;osHandle:=OpenService(scHandle,lpServiceName,SERVICE_ALL_ACCESS);<br> &nbsp;b:=StartService(osHandle,1,lpServiceName);<br> &nbsp;if b then<br> &nbsp; &nbsp;showmessage('success to start the service '+lpServiceName+'!!')<br> &nbsp;else<br> &nbsp; &nbsp;showmessage('StartService Error::'+syserrormessage(getlasterror));<br> &nbsp;CloseServiceHandle(osHandle);<br> &nbsp;CloseServiceHandle(scHandle);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;c:TClipboard;<br>begin<br> &nbsp;if edit1.Text&lt;&gt;'' then<br> &nbsp;begin<br> &nbsp; &nbsp;StartTelnet(edit1.Text);<br> &nbsp;end;<br> &nbsp;c:=TClipboard.Create;<br> &nbsp;c.SetTextBuf(pchar(edit2.Text));<br> &nbsp;c.Free;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> &nbsp;lpServiceName:PChar;<br> &nbsp;b:bool;<br> &nbsp;osHandle:SC_HANDLE;<br> &nbsp;ss:TServiceStatus;<br> &nbsp;rkey,key1,key2:HKEY;<br> &nbsp;x:dword;<br>begin<br> &nbsp;if RegConnectRegistry(PChar('//'+form1.Edit1.Text),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HKEY_LOCAL_MACHINE,rKey)=ERROR_SUCCESS then<br> &nbsp;begin<br> &nbsp; &nbsp;x:=4;<br> &nbsp; &nbsp;if RegOpenKey(rkey,PChar('SYSTEM/CurrentControlSet/Services/TlntSvr'),key1)=ERROR_SUCCESS then<br> &nbsp; &nbsp; &nbsp;RegSetValueEx(key1,'Start',0,reg_dword,@x,4);<br> &nbsp; &nbsp;RegCloseKey(Key1);<br> &nbsp; &nbsp;x:=2;<br> &nbsp; &nbsp;if RegOpenKey(rkey,PChar('SOFTWARE/Microsoft/TelnetServer/1.0'),key2)=ERROR_SUCCESS then<br> &nbsp; &nbsp; &nbsp;RegSetValueEx(key2,'NTLM',0,reg_dword,@x,4);<br> &nbsp; &nbsp;RegCloseKey(Key2);<br> &nbsp; &nbsp;RegCloseKey(rKey);<br> &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;showmessage('reg connect error');<br> &nbsp;lpServiceName:='TlntSvr'; &nbsp;//PChar(n)<br> &nbsp;scHandle:=OpenSCManager(PChar('//'+form1.Edit1.Text),NIL,SC_MANAGER_ALL_ACCESS);<br> &nbsp;if scHandle=0 then<br> &nbsp;begin<br> &nbsp; &nbsp;showmessage('OpenSCManager //'+form1.Edit1.Text +'Error::'+syserrormessage(getlasterror));<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;//////////<br> &nbsp;EnableServices(lpServiceName);<br> &nbsp;/////////<br> &nbsp;osHandle:=OpenService(scHandle,lpServiceName,SERVICE_ALL_ACCESS);<br> &nbsp;b:=ControlService(osHandle, SERVICE_CONTROL_STOP, ss);<br> &nbsp;if b then<br> &nbsp; &nbsp;showmessage('success to stop the service '+lpServiceName+'!!')<br> &nbsp;else<br> &nbsp; &nbsp;showmessage('StopService Error::'+syserrormessage(getlasterror));<br> &nbsp;CloseServiceHandle(osHandle);<br> &nbsp;CloseServiceHandle(scHandle);<br> &nbsp;CancelIPC(form1.Edit1.Text,form1.Edit2.Text,form1.Edit3.Text);<br>end;<br><br>end.<br>//========Form1.dfm===========<br>object Form1: TForm1<br> &nbsp;Left = 192<br> &nbsp;Top = 107<br> &nbsp;Width = 295<br> &nbsp;Height = 154<br> &nbsp;Caption = 'Form1'<br> &nbsp;Color = clBtnFace<br> &nbsp;Font.Charset = DEFAULT_CHARSET<br> &nbsp;Font.Color = clWindowText<br> &nbsp;Font.Height = -11<br> &nbsp;Font.Name = 'MS Sans Serif'<br> &nbsp;Font.Style = []<br> &nbsp;OldCreateOrder = False<br> &nbsp;PixelsPerInch = 96<br> &nbsp;TextHeight = 13<br> &nbsp;object Label1: TLabel<br> &nbsp; &nbsp;Left = 16<br> &nbsp; &nbsp;Top = 8<br> &nbsp; &nbsp;Width = 23<br> &nbsp; &nbsp;Height = 13<br> &nbsp; &nbsp;Caption = 'user:'<br> &nbsp;end<br> &nbsp;object Label2: TLabel<br> &nbsp; &nbsp;Left = 16<br> &nbsp; &nbsp;Top = 32<br> &nbsp; &nbsp;Width = 48<br> &nbsp; &nbsp;Height = 13<br> &nbsp; &nbsp;Caption = 'password:'<br> &nbsp;end<br> &nbsp;object Label3: TLabel<br> &nbsp; &nbsp;Left = 16<br> &nbsp; &nbsp;Top = 64<br> &nbsp; &nbsp;Width = 35<br> &nbsp; &nbsp;Height = 13<br> &nbsp; &nbsp;Caption = 'ip addr:'<br> &nbsp;end<br> &nbsp;object Button1: TButton<br> &nbsp; &nbsp;Left = 16<br> &nbsp; &nbsp;Top = 96<br> &nbsp; &nbsp;Width = 75<br> &nbsp; &nbsp;Height = 25<br> &nbsp; &nbsp;Caption = 'start service'<br> &nbsp; &nbsp;TabOrder = 1<br> &nbsp; &nbsp;OnClick = Button1Click<br> &nbsp;end<br> &nbsp;object Button2: TButton<br> &nbsp; &nbsp;Left = 192<br> &nbsp; &nbsp;Top = 96<br> &nbsp; &nbsp;Width = 75<br> &nbsp; &nbsp;Height = 25<br> &nbsp; &nbsp;Caption = 'stop service'<br> &nbsp; &nbsp;TabOrder = 2<br> &nbsp; &nbsp;OnClick = Button2Click<br> &nbsp;end<br> &nbsp;object Edit1: TEdit<br> &nbsp; &nbsp;Left = 80<br> &nbsp; &nbsp;Top = 64<br> &nbsp; &nbsp;Width = 193<br> &nbsp; &nbsp;Height = 21<br> &nbsp; &nbsp;TabOrder = 0<br> &nbsp; &nbsp;Text = '10.1.'<br> &nbsp;end<br> &nbsp;object Edit2: TEdit<br> &nbsp; &nbsp;Left = 80<br> &nbsp; &nbsp;Top = 0<br> &nbsp; &nbsp;Width = 193<br> &nbsp; &nbsp;Height = 21<br> &nbsp; &nbsp;TabOrder = 3<br> &nbsp; &nbsp;Text = 'administrator'<br> &nbsp;end<br> &nbsp;object Edit3: TEdit<br> &nbsp; &nbsp;Left = 80<br> &nbsp; &nbsp;Top = 32<br> &nbsp; &nbsp;Width = 193<br> &nbsp; &nbsp;Height = 21<br> &nbsp; &nbsp;TabOrder = 4<br> &nbsp;end<br>end
 
后退
顶部