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的
$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中
答案 0 :(得分:1)
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /reg:64 /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d USERNAME /reg:64 /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d PASSWORD /reg:64 /f
调试后,使用批处理解决方案发现我可以编辑我编写文件的方式。现在,它完全得益于你的帮助!
答案 1 :(得分:0)
听起来问题是您的应用程序需要管理员权限才能访问这些密钥。在启用Windows 7及更高版本和UAC的情况下,即使登录用户具有管理员权限,除非他们请求,否则这些进程将没有管理员权限。
这篇文章:How to force my C# Winforms program run as administrator on any computer?
应该帮助您设置项目,使其以管理员权限运行。