VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Install Windows NT Service

by Matthew Ruffell (3 Submissions)
Category: Windows System Services
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (9 Votes)

Install a Windows NT service on a local or remote server. Configure how the service is installed. Requires Windows NT and administrator rights.

Inputs
ServiceFileName [string] = binary service file path and name, ServiceName [string] = name of service, DisplayName [string] = unofficial name of service, Interactive [boolean] = communicates with desktop, AutoStart [boolean] = run when system starts, MachineName [optional string] = target server name
Assumes
Requires Windows NT and administrator rights.
Code Returns
Returns True if serive was successfully installed.
API Declarations
Private 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
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CreateService Lib "advapi32.dll" Alias "CreateServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal lpDisplayName As String, ByVal dwDesiredAccess As Long, ByVal dwServiceType As Long, ByVal dwStartType As Long, ByVal dwErrorControl As Long, ByVal lpBinaryPathName As String, ByVal lpLoadOrderGroup As String, lpdwTagId As Long, ByVal lpDependencies As String, ByVal lpServiceStartName As String, ByVal lpPassword As String) As Long
Private Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject As Long) As Long

Rate Install Windows NT Service

Public Function Install_SVC(strServiceFileName As String, strServiceName As String, strDisplayName As String, bolInteractive As Boolean, bolAutoStart As Boolean, Optional strMachineName As Variant, Optional strAccount As Variant, Optional strAccountPassword As Variant) As Boolean
 Dim hSCM As Long
 Dim hSVC As Long
 Dim lngInteractive As Long
 Dim lngAutoStart As Long
 Dim pSTATUS As SERVICE_STATUS
 If bolInteractive = True Then lngInteractive = (&H100 Or &H10) Else lngInteractive = &H10
 If bolAutoStart = True Then lngAutoStart = &H2 Else lngAutoStart = &H3
 If IsMissing(strMachineName) = True Then strMachineName = vbNullString Else strMachineName = CStr(strMachineName)
 If IsMissing(strAccount) = True Then strAccount = vbNullString Else strAccount = CStr(strAccount)
 If IsMissing(strAccountPassword) = True Then strAccountPassword = vbNullString Else strAccountPassword = CStr(strAccountPassword)
 
 '// Open the service manager
 hSCM = OpenSCManager(strMachineName, vbNullString, &H2)
 If hSCM = 0 Then Exit Function '// error opening
 '// Install the service
 hSVC = CreateService(hSCM, _
 strServiceName, _
 strDisplayName, _
 983551, _
 lngInteractive, _
 lngAutoStart, _
 0, _
 strServiceFileName, _
 vbNull, _
 vbNull, _
 vbNullString, _
 strAccount, _
 strAccountPassword)
 
 If hSVC <> 0 Then Install_SVC = True
 
 Call CloseServiceHandle(hSVC)
 Call CloseServiceHandle(hSCM)
End Function

Download this snippet    Add to My Saved Code

Install Windows NT Service Comments

No comments have been posted about Install Windows NT Service. Why not be the first to post a comment about Install Windows NT Service.

Post your comment

Subject:
Message:
0/1000 characters