var processStartInfo = new ProcessStartInfo();
processStartInfo.WorkingDirectory = @"c:\temp";
processStartInfo.FileName = "cmd.exe";
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardInput = true;
// set additional properties
Process proc = Process.Start(processStartInfo);
//process.StandardInput.WriteLine("c:");
proc.StandardInput.WriteLine("powershell -ExecutionPolicy Bypass c:\\temp\\autologin.ps1");
proc.StandardInput.Close();
レジストリに必要な変更を行うPowerShellのPowerShellスクリプトではなく
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty $RegPath "AutoAdminLogon" -Value "0" -type String
Set-ItemProperty $RegPath "DefaultUsername" -Value " " -type String
Set-ItemProperty $RegPath "DefaultPassword" -Value " " -type String
私は私のプログラムの書き込みPowerShellスクリプトを実行しようとしてきました。私はコンピュータを再起動して、そのpowershellプログラムに再びアクセスするので、プログラムでpowershellコマンドを実行するだけではいけません。
アイデア?現在はコマンドを実行しますが、レジストリに変更は加えませんが、コマンドを自分でCMDに入力すると完全に動作します。だから私はちょっと立ち往生して、必要なのはC#が私のためにそのPowerShellスクリプトを実行することだけです。参照用
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
REGキー
NEW EDIT:プログラムはWOW6432NODE
変更するレジストリキーは何ですか?それらにアクセスするには管理者権限が必要ですか? – mageos
proc.StandardInput.WriteLine( "reg add" + c "HKLM \\ソフトウェア\\ Microsoft \\ Windows NT \\ CurrentVersion \\ Winlogon" + c + "/ v AutoAdminLogon/t REG_SZ/d 0/f") ; Windows NT \ CurrentVersion \\ Winlogon "+ c +"/v DefaultUserName/t REG_SZ/d "+ username +"これは、/f "); Windows NT \ CurrentVersion \ Winlogon "+ c +"/v DefaultPassword/t REG_SZ/d "+"はい " + "/ f"); proc.StandardInput.WriteLine( "タイムアウト10"); –
それは、バッチバージョンのPowerShellのバージョンが異なっていますが、私はスクリプトを実行していない代わりにコマンドをseperatly実行し、レジストリに変更はありません。 –