2016-09-02 24 views
0

再起動時に別のPowershellスクリプトを実行するスクリプトを実行しようとしています。私はHKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Runキーを使用しています。管理スクリプトは再起動時に管理者として再起動しません

私の問題は、スクリプトは再起動時に起動されますが、管理外のPSウィンドウから実行されることです。これは私に "アクセス拒否"を与えます。私はシステム上でUACを無効にしましたが、同じエラーが発生します。 リブート時にAdmin Powershellウィンドウから起動するにはどうしたらいいですか?

は、現在持っている:

REG ADD HKLM \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Runを/ VのRunThis /トンREG_SZ/F/D「C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell.exe - ExecutionPolicy無制限 - ファイルC:\ script.ps1 -Verb RunAsの

+0

固定文の構造。文言を締め固めた。 – Prune

答えて

0

がこの問題を解決する必要があり、あなたはそれを手動で実行するときに、アクセスが拒否されませんと仮定すると、PowerShellの管理・プロンプトを開き、キーこの中 -

set-executionpolicy remotesigned 

今すぐ実行キーにこれを追加 -

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -file C:\script.ps1 
0

これは本当に要因のカップルに依存:UACの設定。結合されたマシンドメインです。 ...

このスクリプトはほとんどのシナリオで機能します。注:スクリプトの実行が完了すると、admin powershellホストは終了します。

$currentUserID = [System.Security.Principal.WindowsIdentity]::GetCurrent() 
$currentUserPrincipal = New-Object System.Security.Principal.WindowsPrincipal($currentUserID) 

$adminPrincipal = [System.Security.Principal.WindowsBuiltInRole]::Administrator 

# If not already admin start a new process and pass the current session definition to the admin powershell instance. 
if(-not ($currentUserPrincipal.IsInRole($adminPrincipal))) { 
    $adminProc = New-Object System.Diagnostics.ProcessStartInfo "powershell" 
    $adminProc.Arguments = $MyInvocation.MyCommand.Definition 
    $adminProc.Verb = "runas" 

    [System.Diagnostics.Process]::Start($adminProc) 

    #If you don't need to keep the current session open uncomment this line. 
    #exit 
} 

# Any code executed at this point will execute in an admin PS session. 
ping google.com 
関連する問題