Removing a Service in Windows Using Command Prompt

Removing a service in Windows using the Command Prompt involves a few straightforward steps. Here's how to do it:

Step 1: Open Command Prompt as Administrator

1. Press the Windows key and type cmd in the search box.

2. Right-click on Command Prompt and select Run as administrator.

This is necessary to ensure you have the appropriate permissions to remove services.

Step 2: Find the Service Name

Before removing a service, you need to know its service name (not the display name). Here's how to find it:

1. In the Command Prompt, type the following command and press Enter:

sc queryex type= service

2. This will display a list of all services running on your system. Look for the Service Name (not the Display Name) of the service you want to remove.

Example:

SERVICE_NAME: MyService

DISPLAY_NAME: My Service

Step 3: Stop the Service

To remove a service, it must be stopped first. Use the following command to stop the service:

sc stop "ServiceName"

Replace "ServiceName" with the name of the service you want to stop.

For example:

sc stop "MyService"

Step 4: Delete the Service

Once the service is stopped, you can delete it using the following command:

sc delete "ServiceName"

For example:

sc delete "MyService"

Step 5: Verify the Service is Removed

You can verify that the service has been removed by running the following command:

sc query "ServiceName"

If the service is deleted successfully, you should see an error message indicating that the service does not exist.

Troubleshooting

· If the service does not stop or delete, ensure you have the appropriate administrative rights.

· If a service is critical to Windows operations, it may not be removable or may cause system instability if deleted.

Important Notes:

· Removing services can have unintended consequences. Before deleting the service, always ensure that it is not essential for system operations.

· Some services may be automatically reinstalled or restored by the operating system or third-party software, depending on your settings.

This should help you manage and remove unnecessary services from your Windows system using Command Prompt!

How to deploy a spring boot application to a Linux server and install it as a service

Here's how to deploy a spring boot application and install it as a service:

Preparation

  1. Package your application as a jar file, name it myapp.jar
  2. Install the JDK that suits your needs on the server


Installation

  1. Upload the jar file to your server, put it in /var/myapp directory
  2. Set it as executable by running this command: chmod +x myapp.jar
  3. Create a script named myapp.service and place it in /etc/systemd/system directory, the script contains something like this

    [Unit]
    Description=myapp
    After=syslog.target network.target

    [Service]
    ExecStart=/path/to/java/home/bin/java -jar /var/myapp/myapp.jar
    ExecStop=/bin/kill -15 $MAINPID
    SuccessExitStatus=143

    [Install]
    WantedBy=multi-user.target



  4. Flag the application to start automatically on system boot, run the following command: systemctl enable myapp.service
Once installed, you can start and stop the service in the usual way. For example, on a Debian-based system, you could start it with the following command: service myapp start

If your application fails to start, check the log file written to /var/log/<appname>.log for errors.

How to use object as parameter in Spring JPA query

 Let's assume you have a class called Customer like this:

public class Customer {

    private String name;

    private String phoneNumber;

    private Integer age;

    ...

}

now you want to use that class as a parameter in the JPA repository, here's how to do it:

@Query("select c from Customer c where c.name = :#{#customer.name} and c.phoneNumber = :#{#customer.phoneNumber}")
List<Customer> findByNameAndPhone(@Param("customer") Customer customer);