当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·求助11    »显示摘要«
    摘要: 各位大哥大姐,兄弟姐妹们,说来惭愧,本人会做些页子,本来只是一些课余爱好,怎奈这个月的饭钱交了别的费用,没有钱解决温饱问题了,希望大家能给我介绍一些东西做做,我和我的同学是一个工作室,我的信箱1leiting@163.comqq:38078612我的网址 http://lzw216.nease.net哦,忘记说了,我在长沙读书!最后谢谢大家来的都有分,不够咱们再加2222222222222......
    摘要: 2000sever 如何配置局域网共享上网!!!! 或者那里有现成的教程,急用!!!!!!!!!!!!!!! ......


如何得到win2000的服务列表高手帮忙啊

如何得到win2000的服务列表?高手帮忙啊~~~~~

NO.1   作者: 3661512

Public   Const   ERROR_MORE_DATA   =   234  
  Public   Const   SERVICE_ACTIVE   =   &H1  
  Public   Const   SERVICE_INACTIVE   =   &H2  
  Public   Const   SC_MANAGER_ENUMERATE_SERVICE   =   &H4  
  Public   Const   SERVICE_WIN32_OWN_PROCESS   As   Long   =   &H10  
  Public   Const   SERVICE_WIN32_SHARE_PROCESS   As   Long   =   &H20  
  Public   Const   SERVICE_WIN32   As   Long   =   SERVICE_WIN32_OWN_PROCESS   +   SERVICE_WIN32_SHARE_PROCESS  
  Public   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  
  Public   Type   ENUM_SERVICE_STATUS  
          lpServiceName   As   Long  
          lpDisplayName   As   Long  
          ServiceStatus   As   SERVICE_STATUS  
  End   Type  
  Public   Declare   Function   OpenSCManager   Lib   "advapi32.dll"   Alias   "OpenSCManagerA"   (ByVal   lpMachineName   As   String,   ByVal   lpDatabaseName   As   String,   ByVal   dwDesiredAccess   As   Long)   As   Long  
  Public   Declare   Function   EnumServicesStatus   Lib   "advapi32.dll"   Alias   "EnumServicesStatusA"   (ByVal   hSCManager   As   Long,   ByVal   dwServiceType   As   Long,   ByVal   dwServiceState   As   Long,   lpServices   As   Any,   ByVal   cbBufSize   As   Long,   pcbBytesNeeded   As   Long,   lpServicesReturned   As   Long,   lpResumeHandle   As   Long)   As   Long  
  Public   Declare   Function   CloseServiceHandle   Lib   "advapi32.dll"   (ByVal   hSCObject   As   Long)   As   Long  
  Public   Declare   Function   lstrcpy   Lib   "kernel32.dll"   Alias   "lstrcpyA"   (szDest   As   String,   szcSource   As   Long)   As   Long  
   
   
  Public   Function   StripTerminator(sInput   As   String)   As   String  
          Dim   ZeroPos   As   Integer  
          ZeroPos   =   InStr(1,   sInput,   Chr$(0))  
          If   ZeroPos   >   0   Then  
                  StripTerminator   =   Left$(sInput,   ZeroPos   -   1)  
          Else  
                  StripTerminator   =   sInput  
          End   If  
  End   Function  
   
   
   
  在窗体里代码(窗体内置一list1控件):  
  Private   Sub   Form_Load()  
          Dim   hSCM   As   Long,   lpEnumServiceStatus()   As   ENUM_SERVICE_STATUS,   lngServiceStatusInfoBuffer   As   Long  
          Dim   strServiceName   As   String   *   250,   lngBytesNeeded   As   Long,   lngServicesReturned   As   Long  
          Dim   hNextUnreadEntry   As   Long,   lngStructsNeeded   As   Long,   lngResult   As   Long,   i   As   Long  
          Open   connection   to   Service   Control   Manager.  
          hSCM   =   OpenSCManager(vbNullString,   vbNullString,   SC_MANAGER_ENUMERATE_SERVICE)  
          If   hSCM   =   0   Then  
                  MsgBox   "OpenSCManager   failed.   LastDllError   =   "   &   CStr(Err.LastDllError)  
                  Exit   Sub  
          End   If  
          Get   buffer   size   (bytes)   without   passing   a   buffer  
          and   make   sure   starts   at   0th   entry.  
          hNextUnreadEntry   =   0  
          lngResult   =   EnumServicesStatus(hSCM,   SERVICE_WIN32,   SERVICE_ACTIVE   Or   SERVICE_INACTIVE,   ByVal   &H0,   &H0,   lngBytesNeeded,   lngServicesReturned,   hNextUnreadEntry)  
          We   should   receive   MORE_DATA   error.  
          If   Not   Err.LastDllError   =   ERROR_MORE_DATA   Then  
                  MsgBox   "LastDLLError   =   "   &   CStr(Err.LastDllError)  
                  Exit   Sub  
          End   If  
          Calculate   the   number   of   structures   needed.  
          lngStructsNeeded   =   lngBytesNeeded   /   Len(lpEnumServiceStatus(0))   +   1  
          Redimension   the   array   according   to   our   calculation.  
          ReDim   lpEnumServiceStatus(lngStructsNeeded   -   1)  
          Get   buffer   size   in   bytes.  
          lngServiceStatusInfoBuffer   =   lngStructsNeeded   *   Len(lpEnumServiceStatus(0))  
          Get   services   information   starting   entry   0.  
          hNextUnreadEntry   =   0  
          lngResult   =   EnumServicesStatus(hSCM,   SERVICE_WIN32,   SERVICE_ACTIVE   Or   SERVICE_INACTIVE,   lpEnumServiceStatus(0),   lngServiceStatusInfoBuffer,   lngBytesNeeded,   lngServicesReturned,   hNextUnreadEntry)  
          If   lngResult   =   0   Then  
                  MsgBox   "EnumServicesStatus   failed.   LastDllError   =   "   &   CStr(Err.LastDllError)  
                  Exit   Sub  
          End   If  
          Get   the   strings   and   display   them.  
          Me.AutoRedraw   =   True  
          Me.Print   "All   registered   services:"   +   vbCrLf  
        Dim   name1   As   String  
           
          For   i   =   0   To   lngServicesReturned   -   1  
                  lngResult   =   lstrcpy(ByVal   strServiceName,   ByVal   lpEnumServiceStatus(i).lpServiceName)  
                  name1   =   StripTerminator(strServiceName)  
                   
                  lngResult   =   lstrcpy(ByVal   strServiceName,   ByVal   lpEnumServiceStatus(i).lpDisplayName)  
                  List1.AddItem   "服务名:"   +   name1   +   "     显示名:   "   +   StripTerminator(strServiceName)  
                   
                   
          Next   i  
          Clean   up.  
          CloseServiceHandle   (hSCM)  
  End   Sub  
   
   
   
  自已判断状态(currentstate)后,用下面的api来启动服务:  
  Public   Declare   Function   OpenService   Lib   "advapi32.dll"   Alias   "OpenServiceA"   (ByVal   hSCManager   As   Long,   ByVal   lpServiceName   As   String,   ByVal   dwDesiredAccess   As   Long)   As   Long  
   
   
 


 ·小弟想学vb,各位大哥帮帮忙    »显示摘要«
    摘要: 小弟想学vb,各位大哥帮帮忙!介绍几本好书给小弟吧,初级的,有电子版的也行,发到我邮箱行么?绝对给分!xin_highdam@hzu.edu.cn ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE