home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Server_Gua2061034182007.psc / FrmServices.frm < prev    next >
Text File  |  2005-03-31  |  9KB  |  269 lines

  1. VERSION 5.00
  2. Begin VB.Form FrmServices 
  3.    BorderStyle     =   4  'Fixed ToolWindow
  4.    Caption         =   "Kay²tl² Hizmetler"
  5.    ClientHeight    =   4680
  6.    ClientLeft      =   45
  7.    ClientTop       =   285
  8.    ClientWidth     =   6105
  9.    LinkTopic       =   "Form1"
  10.    LockControls    =   -1  'True
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4680
  14.    ScaleWidth      =   6105
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.CommandButton BtnCancel 
  18.       Caption         =   "Vazgeτ"
  19.       Height          =   375
  20.       Left            =   1320
  21.       TabIndex        =   2
  22.       Top             =   4200
  23.       Width           =   1095
  24.    End
  25.    Begin VB.CommandButton BtnOK 
  26.       Caption         =   "Tamam"
  27.       Height          =   375
  28.       Left            =   120
  29.       TabIndex        =   1
  30.       Top             =   4200
  31.       Width           =   1095
  32.    End
  33.    Begin VB.ListBox List1 
  34.       Height          =   3960
  35.       Left            =   120
  36.       MultiSelect     =   1  'Simple
  37.       TabIndex        =   0
  38.       Top             =   120
  39.       Width           =   5895
  40.    End
  41.    Begin VB.Label Label1 
  42.       BackStyle       =   0  'Transparent
  43.       Caption         =   "╟ift t²klayarak istedi≡iniz hizmetin ■u anki durumu hakk²nda bilgi alabilirsiniz."
  44.       BeginProperty Font 
  45.          Name            =   "Small Fonts"
  46.          Size            =   6.75
  47.          Charset         =   162
  48.          Weight          =   400
  49.          Underline       =   0   'False
  50.          Italic          =   0   'False
  51.          Strikethrough   =   0   'False
  52.       EndProperty
  53.       Height          =   375
  54.       Left            =   2640
  55.       TabIndex        =   3
  56.       Top             =   4200
  57.       Visible         =   0   'False
  58.       Width           =   3375
  59.    End
  60.    Begin VB.Menu MnuService 
  61.       Caption         =   "Hizmet"
  62.       Visible         =   0   'False
  63.       Begin VB.Menu MnuQuery 
  64.          Caption         =   "Sorgula"
  65.       End
  66.       Begin VB.Menu MnuSep1 
  67.          Caption         =   "-"
  68.       End
  69.       Begin VB.Menu MnuStart 
  70.          Caption         =   "Ba■lat"
  71.       End
  72.       Begin VB.Menu MnuStop 
  73.          Caption         =   "Durdur"
  74.       End
  75.       Begin VB.Menu MnuPause 
  76.          Caption         =   "Duraklat"
  77.       End
  78.       Begin VB.Menu MnuResume 
  79.          Caption         =   "Sⁿrdⁿr"
  80.       End
  81.    End
  82. End
  83. Attribute VB_Name = "FrmServices"
  84. Attribute VB_GlobalNameSpace = False
  85. Attribute VB_Creatable = False
  86. Attribute VB_PredeclaredId = True
  87. Attribute VB_Exposed = False
  88. Const ERROR_MORE_DATA = 234
  89. Const SERVICE_ACTIVE = &H1
  90. Const SERVICE_INACTIVE = &H2
  91. Const SC_MANAGER_ENUMERATE_SERVICE = &H4
  92. Const SERVICE_WIN32_OWN_PROCESS As Long = &H10
  93. Const SERVICE_WIN32_SHARE_PROCESS As Long = &H20
  94. Const SERVICE_WIN32 As Long = SERVICE_WIN32_OWN_PROCESS + SERVICE_WIN32_SHARE_PROCESS
  95. Private Type SERVICE_STATUS
  96.     dwServiceType               As Long
  97.     dwCurrentState              As Long
  98.     dwControlsAccepted          As Long
  99.     dwWin32ExitCode             As Long
  100.     dwServiceSpecificExitCode   As Long
  101.     dwCheckPoint                As Long
  102.     dwWaitHint                  As Long
  103. End Type
  104. Private Type ENUM_SERVICE_STATUS
  105.     lpServiceName               As Long
  106.     lpDisplayName               As Long
  107.     ServiceStatus               As SERVICE_STATUS
  108. End Type
  109. Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
  110. Private 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
  111. Private Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject As Long) As Long
  112. Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (szDest As String, szcSource As Long) As Long
  113.  
  114. Dim ArrRegSvc()                 As String
  115. Dim MousePressed                As Boolean
  116. Dim ObjService                  As ClsService
  117. Private Sub BtnCancel_Click()
  118.  
  119.     Unload Me
  120.     
  121. End Sub
  122.  
  123. Private Sub BtnOK_Click()
  124.  
  125.     Dim FlgExist    As Boolean
  126.     Dim AddSvcCnt   As Integer
  127.     
  128.     For AddSvcCnt = 0 To List1.ListCount - 1
  129.         If List1.Selected(AddSvcCnt) Then
  130.             If FrmSetup.LstServices.ListCount > 0 Then
  131.                 For X = 0 To UBound(ArrServices, 2) - 1
  132.                     If StrComp(ArrRegSvc(List1.ListIndex), ArrServices(0, X)) = 0 Then
  133.                         FlgExist = True
  134.                         Exit For
  135.                     End If
  136.                 Next X
  137.             End If
  138.             If Not FlgExist Then
  139.                 ReDim Preserve ArrServices(1, FrmSetup.LstServices.ListCount)
  140.                 ArrServices(0, FrmSetup.LstServices.ListCount) = ArrRegSvc(AddSvcCnt)
  141.                 ArrServices(1, FrmSetup.LstServices.ListCount) = List1.List(AddSvcCnt)
  142.                 FrmSetup.LstServices.AddItem List1.List(AddSvcCnt)
  143.             End If
  144.         End If
  145.         FlgExist = False
  146.     Next AddSvcCnt
  147.     Unload Me
  148.     
  149. End Sub
  150.  
  151. Private Sub Form_Load()
  152.  
  153.     Dim hSCM As Long, lpEnumServiceStatus() As ENUM_SERVICE_STATUS, lngServiceStatusInfoBuffer As Long
  154.     Dim strServiceName As String * 250, lngBytesNeeded As Long, lngServicesReturned As Long
  155.     Dim hNextUnreadEntry As Long, lngStructsNeeded As Long, lngResult As Long, i As Long
  156.     
  157.     Set ObjService = New ClsService
  158.     
  159.     hSCM = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_ENUMERATE_SERVICE)
  160.     If hSCM = 0 Then
  161.         MsgBox "OpenSCManager failed. LastDllError = " & CStr(Err.LastDllError)
  162.         Exit Sub
  163.     End If
  164.  
  165.     hNextUnreadEntry = 0
  166.     lngResult = EnumServicesStatus(hSCM, SERVICE_WIN32, SERVICE_ACTIVE Or SERVICE_INACTIVE, ByVal &H0, &H0, lngBytesNeeded, lngServicesReturned, hNextUnreadEntry)
  167.  
  168.     If Not Err.LastDllError = ERROR_MORE_DATA Then
  169.         MsgBox "LastDLLError = " & CStr(Err.LastDllError)
  170.         Exit Sub
  171.     End If
  172.  
  173.     lngStructsNeeded = lngBytesNeeded / Len(lpEnumServiceStatus(0)) + 1
  174.  
  175.     ReDim lpEnumServiceStatus(lngStructsNeeded - 1)
  176.     lngServiceStatusInfoBuffer = lngStructsNeeded * Len(lpEnumServiceStatus(0))
  177.     hNextUnreadEntry = 0
  178.     lngResult = EnumServicesStatus(hSCM, SERVICE_WIN32, SERVICE_ACTIVE Or SERVICE_INACTIVE, lpEnumServiceStatus(0), lngServiceStatusInfoBuffer, lngBytesNeeded, lngServicesReturned, hNextUnreadEntry)
  179.     If lngResult = 0 Then
  180.         MsgBox "EnumServicesStatus failed. LastDllError = " & CStr(Err.LastDllError)
  181.         Exit Sub
  182.     End If
  183.  
  184.     ReDim ArrRegSvc(lngServicesReturned - 1)
  185.     For i = 0 To lngServicesReturned - 1
  186.         lngResult = lstrcpy(ByVal strServiceName, ByVal lpEnumServiceStatus(i).lpDisplayName)
  187.         List1.AddItem StripTerminator(strServiceName)
  188.         lngResult = lstrcpy(ByVal strServiceName, ByVal lpEnumServiceStatus(i).lpServiceName)
  189.         ArrRegSvc(i) = StripTerminator(strServiceName)
  190.     Next i
  191.     CloseServiceHandle (hSCM)
  192. End Sub
  193. Function StripTerminator(sInput As String) As String
  194.     
  195.     Dim ZeroPos As Integer
  196.     ZeroPos = InStr(1, sInput, Chr$(0))
  197.     If ZeroPos > 0 Then
  198.         StripTerminator = Left$(sInput, ZeroPos - 1)
  199.     Else
  200.         StripTerminator = sInput
  201.     End If
  202.     
  203. End Function
  204.  
  205.  
  206. Private Sub List1_DblClick()
  207.  
  208.     ObjService.ServiceName = ArrRegSvc(List1.ListIndex)
  209.     MsgBox ObjService.QueryService
  210.     
  211. End Sub
  212.  
  213.  
  214. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  215.  
  216.     MousePressed = True
  217.     
  218. End Sub
  219.  
  220.  
  221. Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  222.  
  223.     If MousePressed Then
  224.         MousePressed = False
  225.         If Button = 2 Then Me.PopupMenu MnuService, , , , MnuQuery
  226.     End If
  227.     
  228. End Sub
  229.  
  230.  
  231. Private Sub MnuPause_Click()
  232.     
  233.     ObjService.ServiceName = ArrRegSvc(List1.ListIndex)
  234.     ObjService.PauseService
  235.     
  236. End Sub
  237.  
  238. Private Sub MnuQuery_Click()
  239.  
  240.     ObjService.ServiceName = ArrRegSvc(List1.ListIndex)
  241.     MsgBox ObjService.QueryService
  242.     
  243. End Sub
  244.  
  245.  
  246. Private Sub MnuResume_Click()
  247.     
  248.     ObjService.ServiceName = ArrRegSvc(List1.ListIndex)
  249.     ObjService.ResumeService
  250.     
  251. End Sub
  252.  
  253. Private Sub MnuStart_Click()
  254.     
  255.     ObjService.ServiceName = ArrRegSvc(List1.ListIndex)
  256.     ObjService.StartService
  257.     
  258. End Sub
  259.  
  260.  
  261. Private Sub MnuStop_Click()
  262.     
  263.     ObjService.ServiceName = ArrRegSvc(List1.ListIndex)
  264.     ObjService.StopService
  265.     
  266. End Sub
  267.  
  268.  
  269.