How to start the elastic search service Automatically if it stops in windows?

sometimes in while restarting system,or server restarts the ES service will also stops working . so we are planning to do an application to start the service again without human intervention . But some time when ever any folders are there inside the plugin folder service is not running displaying message like
" failed to start elasticsearch-service-x86 " , if i remove the folders the service is starting .how to solve this issue ? is there any solution for this ?