I have not been coding for very long but am looking to create a work around with some issues that log me in rescue has, during reboots log me in rescue will frequently lose connection and cause the program to break for lack of better terms, currently the fix for the issues is to delete the service which looks something like LMIRescue_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
So what i would like to do is create a batch that can delete an service starting in LMIRescue_
or if that's not possible to have a workaround where I can find service and the grab the out put and use that to delete
can any one give me an example of how to use batch to find the service and delete it on its own or at least point me in the right direction?
I have tried
@echo off
set /p UserInputPath1= What is the First Service Name?
set /p UserInputPath2= What is the Second Service Name?
net stop %UserInputPath1%
net stop %UserInputPath2%
sc delete %UserInputPath1%
sc delete %UserInputPath2%
this works but it requires user input and takes extra time, and the whole point in making this is to avoid wasting time
if wildcards would work, I could just do this
net stop LMIRescue*
sc delete LMIRescue*
net stop LMIRescue*
sc delete LMIRescue*
is there a way to delete a service using wild cards?
is there any way to delete a service in batch other than sc Delete "ServiceName"
and/or how can i use batch to find and output the name of the service and then use that to delete it.
You could use the
sc query
command to retrieve the names of all the active services that are currently running on the local machine. Thefindstr
command can be used to filter anything that doesn't meet the given criteria (in this example, only lines starting withSERVICE_NAME: LMIRescue
remain). The remaining line can be tokenized with the use of thefor /f
command to temporarily store the retrieved service name in for-loop variable%%j
.