回答編集履歴
2
追記
test
CHANGED
@@ -11,3 +11,47 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
あと、用語が間違っていたら話が通じません。必要なのは本当にカレントディレクトリなのか確認してください。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
#追記
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
次のスクリプトを試してください。
|
22
|
+
|
23
|
+
else ブロックの中が管理者権限で行われる処理です。
|
24
|
+
|
25
|
+
コマンドライン引数も一応対応させました。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```ps1
|
30
|
+
|
31
|
+
using namespace System.Security.Principal
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
$isSu = ([WindowsPrincipal][WindowsIdentity]::GetCurrent()).IsInRole([WindowsBuiltInRole]"Administrator")
|
36
|
+
|
37
|
+
if (-not $isSu) {
|
38
|
+
|
39
|
+
$powershell = [Environment]::GetCommandLineArgs()[0]
|
40
|
+
|
41
|
+
$startInfo = New-Object System.Diagnostics.ProcessStartInfo $powershell, ([string]::Join(' ', (@($PSCommandPath) + $args)))
|
42
|
+
|
43
|
+
$startInfo.WorkingDirectory = Get-Location
|
44
|
+
|
45
|
+
$startInfo.Verb = "runas"
|
46
|
+
|
47
|
+
[void][Diagnostics.Process]::Start($startInfo)
|
48
|
+
|
49
|
+
} else {
|
50
|
+
|
51
|
+
$PSScriptRoot
|
52
|
+
|
53
|
+
Read-Host
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
```
|
1
修正
test
CHANGED
@@ -7,3 +7,7 @@
|
|
7
7
|
(pwd)
|
8
8
|
|
9
9
|
```
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
あと、用語が間違っていたら話が通じません。必要なのは本当にカレントディレクトリなのか確認してください。
|