我在访问注册表和创建文件夹时遇到问题. [英] I face a problem in accessing the registry, and creating folder.

查看:145
本文介绍了我在访问注册表和创建文件夹时遇到问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我在访问注册表时遇到问题,
并在"c:\ windows"中创建文件夹.

例外:
System.Security.SecurityException:不允许请求的注册表访问.

System.UnauthorizedAccessException:拒绝访问路径"c:\ windows \ MH \".

代码:

Hi friends,

I face a problem in accessing the registry,
and creating folder in "c:\windows".

Exception:
System.Security.SecurityException: Requested registry acess is not allowed.

System.UnauthorizedAccessException: Access to the path ''c:\windows\MH\'' is denied.

Code:

RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp", true);
string portNumber = key.GetValue("PortNumber").ToString();string pathWin = Environment.GetFolderPath(System.Environment.SpecialFolder.Windows);
Directory.CreateDirectory(@pathWin + @"\MHTest");


该程序在Windows 2008上可以运行,但是在Windows 7中不起作用.
我以管理员用户身份运行该程序.

感谢


The program worka on Windows 2008, but it didn''t work in windows 7.
I run the program with Administrator user.

Thanks

推荐答案

听起来像Win7额外的安全层.即使您通过管理员帐户运行,如果系统安全性处于较高级别,它也会提示您提供权限,以避免通过编程/自动方式访问文件/文件夹.

由于您已经确定所使用帐户的管理员权限,因此只需松开Win7的安全性.我记得它有4个等级.允许安全性在没有提示的情况下传递并查看.那就应该可以了.现在,它绝对是特权问题,与代码无关.
Sounds like the Win7 extra security layer. Even if you run through the administrator account, if the system security is at high level, it prompts for permission to avoid access to files/folders programmatically/automatically.

As you are already sure of the admin priviledges to the account used, just loosen the security of Win7. It has 4 levels as much I remeber. Allow the security to pass on wihtout prompts and see. It should work then. For now, its definitly the priviledge issue and nothing related to code.


我在Windows 7上运行了同一段代码,但没有收到任何错误.它执行得很好,还创建了文件夹.我同意Sandeep的观点,因为我的用户帐户控制设置为UAC,所以从不通知
I ran the same piece of code on Windows 7 and did not get any error. It executed fine and also created the folder. I agree with Sandeep, since my User Account Control is set to UAC never notify


这篇关于我在访问注册表和创建文件夹时遇到问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆