teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

追記

2018/11/14 07:09

投稿

Zuishin
Zuishin

スコア28675

answer CHANGED
@@ -4,4 +4,26 @@
4
4
  (pwd)
5
5
  ```
6
6
 
7
- あと、用語が間違っていたら話が通じません。必要なのは本当にカレントディレクトリなのか確認してください。
7
+ あと、用語が間違っていたら話が通じません。必要なのは本当にカレントディレクトリなのか確認してください。
8
+
9
+ #追記
10
+
11
+ 次のスクリプトを試してください。
12
+ else ブロックの中が管理者権限で行われる処理です。
13
+ コマンドライン引数も一応対応させました。
14
+
15
+ ```ps1
16
+ using namespace System.Security.Principal
17
+
18
+ $isSu = ([WindowsPrincipal][WindowsIdentity]::GetCurrent()).IsInRole([WindowsBuiltInRole]"Administrator")
19
+ if (-not $isSu) {
20
+ $powershell = [Environment]::GetCommandLineArgs()[0]
21
+ $startInfo = New-Object System.Diagnostics.ProcessStartInfo $powershell, ([string]::Join(' ', (@($PSCommandPath) + $args)))
22
+ $startInfo.WorkingDirectory = Get-Location
23
+ $startInfo.Verb = "runas"
24
+ [void][Diagnostics.Process]::Start($startInfo)
25
+ } else {
26
+ $PSScriptRoot
27
+ Read-Host
28
+ }
29
+ ```

1

修正

2018/11/14 07:09

投稿

Zuishin
Zuishin

スコア28675

answer CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  ```ps1
4
4
  (pwd)
5
- ```
5
+ ```
6
+
7
+ あと、用語が間違っていたら話が通じません。必要なのは本当にカレントディレクトリなのか確認してください。