我已经编写了为 git bash 创建服务的 power shell 脚本。打开 git bash 后,脚本必须添加所有 c 驱动器文件并提交。但每隔一小时,无论 c 驱动器中发生什么变化(例如,如果我们安装软件),都会创建一些文件,必须在脚本中进行更新。
$serviceName = "MyService"
if (Get-Service $serviceName -ErrorAction SilentlyContinue)
{
$serviceToRemove = Get-WmiObject -Class Win32_Service -Filter "name='$serviceName'"
$serviceToRemove.delete()
"service removed"
}
else
{
"service does not exists"
}
"Installing service"
$binaryPath = "C:\Program Files\Git\git-bash.exe"
New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds
"Installation completed"