英文:
Editing registry on non-admin user (c#, windows 11)
问题
I'm using the following code to disable task manager:
RegistryKey regKey;
string subKey = @"Software\Microsoft\Windows\CurrentVersion\Policies\System";
regKey = Registry.CurrentUser.CreateSubKey(subKey);
regKey.SetValue("DisableTaskMgr", 1);
regKey.Close();
My program is running with admin rights.
When I run it on a non-admin user (I enter the password of an admin user to run it), it doesn't work (the registry key is created successfully, but task manager isn't disabled).
When I run it on an admin user, it does work.
Does anyone have a solution for this?
英文:
I'm using the following code to disable task manager :
RegistryKey regKey;
string subKey = @"Software\Microsoft\Windows\CurrentVersion\Policies\System";
regKey = Registry.CurrentUser.CreateSubKey(subKey);
regKey.SetValue("DisableTaskMgr", 1);
regKey.Close();
My program is running with admin rights.
When I run it on non-admin user (I enter the password of an admin user to run it), it doesn't work (the registry key is created successfully, but task manager isn't disabled).
When I run it on admin user, it does work.
Does anyone have a solution for this?
答案1
得分: 1
我已解决问题,感谢@RaymondChen的评论。
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
string username = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];
NTAccount account = new NTAccount(username);
SecurityIdentifier securityIdentifier = (SecurityIdentifier)account.Translate(typeof(SecurityIdentifier));
string sid = securityIdentifier.ToString();
string subKey = $@"{sid}\Software\Microsoft\Windows\CurrentVersion\Policies\System";
RegistryKey regKey = Registry.Users.CreateSubKey(subKey);
regKey.SetValue("DisableTaskMgr", 1);
regKey.Close();
英文:
I have solved the issue thanks to @RaymondChen comment.
ManagementObjectSearcher searcher = new ManagementObjectSearcher(
"SELECT UserName FROM Win32_ComputerSystem");
ManagementObjectCollection collection = searcher.Get();
string username = (string)collection.Cast<ManagementBaseObject>().First()["UserName"];
NTAccount account = new NTAccount(username);
SecurityIdentifier securityIdentifier = (SecurityIdentifier)account.Translate(typeof(SecurityIdentifier));
string sid = securityIdentifier.ToString();
string subKey = $@"{sid}\Software\Microsoft\Windows\CurrentVersion\Policies\System";
RegistryKey regKey = Registry.Users.CreateSubKey(subKey);
regKey.SetValue("DisableTaskMgr", 1);
regKey.Close();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论