::Stop Windows service
sc query MyWinService | find "STOPPED" & if errorlevel 1 net stop MyWinService
::delete the dll
del /q E:\MyWinService\\*
for /d %%x in (E:\MyWinService\\*) do @rd /s /q "%%x"
但是如果我在执行5分钟后重新运行相同的命令,则某些dll不会被删除,输出将显示为----"ACCESS DENIED"----
。我知道因为dll仍然与Windows服务相关联,所以错误即将发生,但我想删除dll而不会在5分钟后再次重新运行命令。 :(
答案 0 :(得分:2)
批处理文件方式
:Repeat
del "del /q E:\MyWinService\*"
if exist "E:\MyWinService\sampledll.dll" goto Repeat
答案 1 :(得分:1)
Powershell方式:
do
{
$a = stop-service MyWinService -PassThru
}while ($a.status -ne "Stopped")
do
{
remove-item e:\MyWinService\* -recurse -force -ea silentlycontinue
} untill ( (dir e:\mywinservice).count -gt 0 )