Skip to content

Instantly share code, notes, and snippets.

@yyoda
Created April 5, 2017 04:03
Show Gist options
  • Save yyoda/ba55c050688bb8cef329e0eebb9c8caa to your computer and use it in GitHub Desktop.
Save yyoda/ba55c050688bb8cef329e0eebb9c8caa to your computer and use it in GitHub Desktop.
Visual Studio 2017 を管理者モードで起動させるためのスクリプト
<#
Visual Studio 2017 を管理者モードで起動させるためのスクリプト
#>
$path = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"
$key_devenv = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe"
$key_vslauncher = "C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe"
$value = "RUNASADMIN"
$type = "String"
### レジストリ追加/更新を行う関数を定義
### reference source http://www.vwnet.jp/Windows/PowerShell/Regedit.htm
function RegSet( $RegPath, $RegKey, $RegKeyType, $RegKeyValue ){
# レジストリそのものの有無確認
$Elements = $RegPath -split "\\"
$RegPath = ""
$FirstLoop = $True
foreach ($Element in $Elements ){
if($FirstLoop){
$FirstLoop = $False
}
else{
$RegPath += "\"
}
$RegPath += $Element
if( -not (test-path $RegPath) ){
echo "Add Registry : $RegPath"
md $RegPath
}
}
# Key有無確認
$Result = Get-ItemProperty $RegPath -name $RegKey -ErrorAction SilentlyContinue
# キーがあった時
if( $Result -ne $null ){
Set-ItemProperty $RegPath -name $RegKey -Value $RegKeyValue
}
# キーが無かった時
else{
# キーを追加する
New-ItemProperty $RegPath -name $RegKey -PropertyType $RegKeyType -Value $RegKeyValue
}
Get-ItemProperty $RegPath -name $RegKey
}
### 実行
RegSet $path $key_devenv $type $value
RegSet $path $key_vslauncher $type $value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment