Geo*_*ge2 6 windows powershell service visual-studio-2008
我使用VSTS 2008 Windows服务类型项目创建了一个Windows服务项目,现在我想编写脚本来使用PowerShell安装/卸载它.
任何参考样品或文件?
Ric*_*erg 18
这是我写的安装脚本的清理版本.应该展示你需要做的一切:
## delete existing service
# have to use WMI for much of this, native cmdlets are incomplete
$service = Get-WmiObject -Class Win32_Service -Filter "Name = 'My Service'"
if ($service -ne $null)
{
$service | stop-service
$service.Delete() | out-null
}
## run installutil
# 'frameworkdir' env var apparently isn't present on Win2003...
$installUtil = join-path $env:SystemRoot Microsoft.NET\Framework\v2.0.50727\installutil.exe
$serviceExe = join-path $messageServerPath MyService.exe
$installUtilLog = join-path $messageServerPath InstallUtil.log
& $installUtil $serviceExe /logfile="$installUtilLog" | write-verbose
$service = Get-WmiObject -Class Win32_Service -Filter "Name = 'My Service'"
# change credentials if necessary
if ($user -ne "" -and $password -ne "")
{ $service.change($null, $null, $null, $null, $null, $null, $user, $password, $null, $null, $null) | out-null }
# activate
$service | set-service -startuptype Automatic -passthru | start-service
write-verbose "Successfully started service $($service.name)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6229 次 |
| 最近记录: |