【发布时间】:2016-10-25 17:00:26
【问题描述】:
我的要求是使用windows服务的部分PathName形成一个文件夹路径。
例如,“Microsoft Deployment Agent”windows 服务的 PathName 为“C:\Program Files (x86)\Microsoft Visual Studio 14.0\Release Management\bin\DeploymentAgent.exe”
“C:\Program Files (x86)\Microsoft Visual Studio 14.0\Release Management\Client\bin\ReleaseManagementBuild.exe”中还有另一个exe。
所以我需要形成这个到 ReleaseManagementBuild.exe 的路径。所以我可以执行它来触发 Microsoft 发布管理中的发布。这是必需的,因为服务的 PathName 在所有服务器中都不相同。一个可能在 C 盘,另一个可能在另一个驱动器。
到目前为止,我已经探索了两种方法,使用 Join-Path 或 [IO.Path]::Combine。
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
$RMBuildExePath = Get-WmiObject win32_service | ?{$_.Name -like "*VSO*"} | select PathName
[string]$RMBuildExePathString = $RMBuildExePath.PathName
[string[]]$split = $RMBuildExePathString.Split("\")
$WorkFolder = [IO.Path]::Combine($split[0].Replace("`"","") + "\", $split[1], $split[2], '_work')
Test-Path $WorkFolder
$work = Join-Path $split[0].Replace("`"","") $split[1] | Join-Path -ChildPath $split[2] | Join-Path -ChildPath '_work'
Test-Path $work
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
有没有更好的方法来形成文件路径?可能是注册表项?还是环境变量?
【问题讨论】:
标签: string powershell release-management