Multiple checkboxes with an apply type button

thebouncer

New member
Joined
Aug 31, 2009
Messages
3
Programming Experience
Beginner
I am working on a program that has about 20 checkboxes on it.
What I want to be able to do is to check the checkboxes and then hit an apply button then at that point whatever is checked/ or if something is unchecked the code for that item is run and those changes are applied. If the box is checked it disables the service if it is unchecked it enables the service.

the code I have so far is this for each service I want turned off i have placed under a button name Apply. Each service is a different registry entry and service name, some are just registry key changes...
the code seemed to work at first but that is when I only had one checkbox under the button.

I know I have done something wrong with the program logic here Im just not sure how to fix it as I've only been using VB.net for 2 weeks now... I can't find any reference on the internet to having multiple checkboxes with an apply type button. Just like in a normal windows application where the apply button is used to apply the changes on the form.


Please Help

Thanks In Advance

VB.NET:
 Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click

 '**********************************************************
        ' Disable Smart Card Service 
        ' Actual Service Name:SCardSvr
        '**********************************************************

        If chkSmartCard.Checked = True Then
            Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\SCardSvr", True)
            Dim dword As Int32
            'Set the Smart Card Sevice as DISABLED
            dword = 4
            key.SetValue("Start", dword)
            Dim controller As New ServiceController
            controller.MachineName = "."
            controller.ServiceName = "SCardSvr"
            Dim status As String = controller.Status.ToString
            If controller.Status.Equals(ServiceControllerStatus.Stopped) Or controller.Status.Equals(ServiceControllerStatus.StopPending) Then
                'Service already stopped or stopping
            Else
                controller.Stop()
            End If
        Else
            Dim keyrem As RegistryKey = Registry.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\wscscv", True)
            Dim dwordrem As Int32
            ' Set Service Back to MANUAL
            dwordrem = 3
            keyrem.SetValue("Start", dwordrem)
            Dim controller As New ServiceController
            controller.MachineName = "."
            controller.ServiceName = "SCardSvr"
            Dim status As String = controller.Status.ToString
            ' using the following statement to catch the exception if the service
            ' is already running
            If ServiceControllerStatus.Running Then Return
            'If the service is stopped it will be started
            ' Start the service
            controller.Start()
        End If
        '*************************************************
        ' Disable Telephony Service 
        ' Actual Service Name:TapiSrv
        '*************************************************
        If chkTelephony.Checked = True Then
            Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\TapiSrv", True)
            Dim dword As Int32
            'Set the Telephony Service as DISABLED
            dword = 4
            key.SetValue("Start", dword)
            Dim controller As New ServiceController
            controller.MachineName = "."
            controller.ServiceName = "TapiSrv"
            Dim status As String = controller.Status.ToString
            If controller.Status.Equals(ServiceControllerStatus.Stopped) Or controller.Status.Equals(ServiceControllerStatus.StopPending) Then
                'Service already stopped or stopping
            Else
                controller.Stop()
            End If
        Else
            Dim keyrem As RegistryKey = Registry.LocalMachine.OpenSubKey("System\CurrentControlSet\Services\TapiSrv", True)
            Dim dwordrem As Int32
            ' Set Service Back to MANUAL
            dwordrem = 3
            keyrem.SetValue("Start", dwordrem)
            Dim controller As New ServiceController
            controller.MachineName = "."
            controller.ServiceName = "TapiSrv"
            Dim status As String = controller.Status.ToString
            ' using the following statement to catch the exception if the service
            ' is already running
            If ServiceControllerStatus.Running Then Return
            ' Start the service
            controller.Start()
        End If
 

henryminute

Well-known member
Joined
Jul 24, 2009
Messages
57
Location
UK
Programming Experience
10+
In the code that you have posted the RegistryKey name in the Else block is different to the one in the If block (for the first checkbox).

Is that what you wanted?, or is it just a typo.

Don't know if it is the cause of your problems, it is odd though. :)
 

thebouncer

New member
Joined
Aug 31, 2009
Messages
3
Programming Experience
Beginner
I forgot about this posting since there was no replies the issue was resolved. there was some logic issues along with some issues in the way I was trying to make the changes. It has all been resolved

thank you .
 
Top Bottom