c# - Powershell Topshelf Uninstall 继续锁定文件
问题描述
使用以下 topshelf 卸载命令:
& $path uninstall -servicename:"MyService" -displayname "MyService"
该命令似乎在它所包含的 powershell 脚本的生命周期内继续运行并锁定文件,因此我无法覆盖它们。有没有办法确保它所做的一切都被终止,以便我的脚本可以不受阻碍地继续进行?
解决方案
卸载 Windows 服务的另一种方法。可以用作脚本模块。
function Uninstall-WindowsService($serviceName)
{
$existingService = (Get-WmiObject Win32_Service -filter "name='$serviceName'")
if ($existingService)
{
Write-Host "Stopping the '$serviceName'."
Stop-Service $serviceName
Write-Host "Waiting 3 seconds to allow existing service to stop."
Start-Sleep -s 3
$existingService.Delete()
Write-Host "Waiting 15 seconds to allow service to be uninstalled."
Start-Sleep -s 15
}
}
推荐阅读
- bash - bash_profile 函数到 git grep 和替换
- sql - LINQ SQL 连接多个 n-to-n 关系和过滤器
- sql - SQL Server 错误:在预期条件的上下文中指定的非布尔类型的表达式,靠近 ')'
- python - 解决多组子集和问题的“智能”方法
- java - 锁定 JpaRepository Java Spring Boot
- ios - 向 Swift 中 Path 块中的 CGRect 添加标记
- python - Python:“IndentationError:unindent 不匹配任何外部缩进级别”尝试排除故障但不起作用
- pseudocode - 设计一种算法以保证以至少 1/4 的概率接受结果
- java - 如何对作为 Java 中映射值的内部列表进行排序?
- powerapps - 根据另一个表中的数据对过滤表进行排序