03-08-13, 12:31 PM
الشاكي لله كتب :عندي بالدوس استطيع اغلاق الخدمة وتشغيلها
[ATTACH=CONFIG]3619[/ATTACH]
كيف مايصير عندك
هل عطلتها من الخدمات ؟ عطلها وشوف
الشاكي لله كتب :عندي بالدوس استطيع اغلاق الخدمة وتشغيلها
[ATTACH=CONFIG]3619[/ATTACH]
كيف مايصير عندك

Dim svc As New ServiceController("W3SVC")
ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Automatic)

الشاكي لله كتب :PHP كود :
Dim svc As New ServiceController("W3SVC")
ServiceHelper.ChangeStartMode(svc, ServiceStartMode.Automatic)
تمام ؟
Imports System.Runtime.InteropServicesImports System.ServiceProcess
Public Class ServiceHelper
Public NotInheritable Class ServiceHelper
Private Sub New()
End Sub
<DllImport("advapi32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _
Public Shared Function ChangeServiceConfig(ByVal hService As IntPtr, ByVal nServiceType As UInt32, ByVal nStartType As UInt32, ByVal nErrorControl As UInt32, ByVal lpBinaryPathName As [String], ByVal lpLoadOrderGroup As [String], _
ByVal lpdwTagId As IntPtr, <[In]()> ByVal lpDependencies As Char(), ByVal lpServiceStartName As [String], ByVal lpPassword As [String], ByVal lpDisplayName As [String]) As [Boolean]
End Function
<DllImport("advapi32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function OpenService(ByVal hSCManager As IntPtr, ByVal lpServiceName As String, ByVal dwDesiredAccess As UInteger) As IntPtr
End Function
Public Declare Unicode Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerW" (ByVal machineName As String, ByVal databaseName As String, ByVal dwAccess As UInteger) As IntPtr
<DllImport("advapi32.dll", EntryPoint:="CloseServiceHandle")> _
Public Shared Function CloseServiceHandle(ByVal hSCObject As IntPtr) As Integer
End Function
<DllImport("advapi32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> _
Public Shared Function QueryServiceConfig(ByVal hService As IntPtr, ByVal intPtrQueryConfig As IntPtr, ByVal cbBufSize As UInt32, ByRef pcbBytesNeeded As UInt32) As [Boolean]
End Function
<DllImport("advapi32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, EntryPoint:="QueryServiceConfig2W")> _
Public Shared Function QueryServiceConfig2(ByVal hService As IntPtr, ByVal dwInfoLevel As UInt32, ByVal buffer As IntPtr, ByVal cbBufSize As UInt32, ByRef pcbBytesNeeded As UInt32) As [Boolean]
End Function
Private Const SERVICE_NO_CHANGE As UInteger = &HFFFFFFFFUI
Private Const SERVICE_QUERY_CONFIG As UInteger = &H1
Private Const SERVICE_CHANGE_CONFIG As UInteger = &H2
Private Const SC_MANAGER_ALL_ACCESS As UInteger = &HF003F
<StructLayout(LayoutKind.Sequential)> _
Public Class QUERY_SERVICE_CONFIG
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)> _
Public dwServiceType As UInt32
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)> _
Public dwStartType As UInt32
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)> _
Public dwErrorControl As UInt32
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Public lpBinaryPathName As [String]
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Public lpLoadOrderGroup As [String]
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)> _
Public dwTagID As UInt32
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Public lpDependencies As [String]
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Public lpServiceStartName As [String]
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> _
Public lpDisplayName As [String]
End Class
Public Shared Sub ChangeStartMode(ByVal svc As ServiceController, ByVal mode As ServiceStartMode)
Dim scManagerHandle = OpenSCManager(Nothing, Nothing, SC_MANAGER_ALL_ACCESS)
If scManagerHandle = IntPtr.Zero Then
Throw New ExternalException("Open Service Manager Error")
End If
Dim serviceHandle = OpenService(scManagerHandle, svc.ServiceName, SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG)
If serviceHandle = IntPtr.Zero Then
Throw New ExternalException("Open Service Error")
End If
Dim result = ChangeServiceConfig(serviceHandle, SERVICE_NO_CHANGE, CUInt(mode), SERVICE_NO_CHANGE, Nothing, Nothing, _
IntPtr.Zero, Nothing, Nothing, Nothing, Nothing)
If result = False Then
Dim nError As Integer = Marshal.GetLastWin32Error()
Dim win32Exception = New System.ComponentModel.Win32Exception(nError)
Throw New ExternalException("Could not change service start type: " & Convert.ToString(win32Exception.Message))
End If
CloseServiceHandle(serviceHandle)
CloseServiceHandle(scManagerHandle)
End Sub
''' <summary>
''' Automatic = 2, Manual = 3, Disabled = 4
''' </summary>
''' <param name="svc"></param>
''' <returns></returns>
Public Shared Function GetStartMode(ByVal svc As ServiceController) As UInteger
Dim scManagerHandle = OpenSCManager(Nothing, Nothing, SC_MANAGER_ALL_ACCESS)
If scManagerHandle = IntPtr.Zero Then
Throw New ExternalException("Open Service Manager Error")
End If
Dim serviceHandle = OpenService(scManagerHandle, svc.ServiceName, SERVICE_QUERY_CONFIG)
If serviceHandle = IntPtr.Zero Then
Throw New ExternalException("Open Service Error")
End If
Dim dwBytesNeeded As UInt32 = 0
Dim ptr As IntPtr = Marshal.AllocHGlobal(4096)
' Allocate memory for struct.
Dim result As Boolean = QueryServiceConfig(serviceHandle, ptr, 4096, dwBytesNeeded)
Dim qUERY_SERVICE_CONFIG As New QUERY_SERVICE_CONFIG()
Marshal.PtrToStructure(ptr, qUERY_SERVICE_CONFIG)
' Copy;
Marshal.FreeHGlobal(ptr)
If result = False Then
Dim nError As Integer = Marshal.GetLastWin32Error()
Dim win32Exception = New System.ComponentModel.Win32Exception(nError)
Throw New ExternalException("Could not QueryServiceConfig : " & Convert.ToString(win32Exception.Message))
End If
CloseServiceHandle(serviceHandle)
CloseServiceHandle(scManagerHandle)
Return qUERY_SERVICE_CONFIG.dwStartType
End Function
End Class
End Class