Skip to main content

Create Service on Remote Machine

Private Sub CrateService(ByVal strComputer As String)

        Dim objWMIService, colServiceList, objService, errReturn, objSWbemLocator
        Const OWN_PROCESS = 16
        Const NOT_INTERACTIVE = False
        Const NORMAL_ERROR_CONTROL = 2
        Dim strName, strDisplay, strPath As String

        strName = txtName.Text
        strDisplay = txtDisplay.Text
        strPath = txtPath.Text

        Try

            objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

            If (strComputer = Environment.MachineName.ToString) Then

                objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2")
            Else
                objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", strTargetUser, strTargetPwd)
            End If

            objWMIService.Security_.ImpersonationLevel = 3

            objService = objWMIService.Get("Win32_BaseService")
            errReturn = objService.Create(strName, strDisplay, strPath, OWN_PROCESS, NORMAL_ERROR_CONTROL, strMode, NOT_INTERACTIVE, "NT AUTHORITY\LocalService", "")

            If (errReturn = 0) Then
                MessageBox.Show("Service Successfully Created.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf (errReturn = 1) Then
                MessageBox.Show("Not Supported.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf (errReturn = 2) Then
                MessageBox.Show("Access Denied.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf (errReturn = 9) Then
                MessageBox.Show("Path Not Found.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf (errReturn = 10) Then
                MessageBox.Show("Service Already Running.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ElseIf (errReturn = 14) Then
                MessageBox.Show("Service Disabled.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Service Creation Failed.", "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message.ToString, "Create Service", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End Try

        

End Sub

Popular posts from this blog

Ping Network Computer in VB.Net

"Ping" is very basic utility for every network programmer. Here we will discuss ping a computer in Network using VB.Net. We have two methods for pinging a computer. Method 1: Here we will use VB.Net NetworkInformation NameSpace. Public Sub PingStatus(ByVal strComputer As String) Dim pingSender As Ping = New Ping() Dim options As PingOptions = New PingOptions() options.DontFragment = True 'Create a buffer of 32 bytes of data to be transmitted Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Dim buffer As Byte() = Encoding.ASCII.GetBytes(data) Dim timeout As Integer = 120 Dim reply As PingReply = pingSender.Send(strComputer, timeout, buffer, options) If (reply.Status = IPStatus.Success) Then MessageBox.Show("Ping Successed.") Else MessageBox.Show("Ping Faild.") End If End Sub Method 2: Here we are using .Net inbuil

GridView Paging and Sorting

Introduction Paging and Sorting are most commonly used features of ASP.Net GridView. And it is very easy to implement in GridView with small lines of code. Here I am going to demonstrate how to use Paging and Sorting in GridView for better use of data display.