Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

UnauthorizedAccessException writing to Windows (Vista) directory and     writing to Registry

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
wesley.hs76@hotmail.com - 23 Mar 2008 22:36 GMT
Hello,

I've the following two problems. I want to write an inifile to the
Windows directory. And I wanna write variables to the Registry. For
both things I get an UnauthorizedAccessException. This problem started
when I'm using Windows Vista. (Windows XP this problem never happens.)
Can somebody give a solution, how to solve this? This a part of my
source:

      static string FBestandnaam;
      ...
      public string Naam
      {
         ...
      }
      ...
      public void Reset()
       {
           if (FFullBestandnaam != null)
               Close();
           //    UnauthorizedAccessException => Here the exception
starts
           FFullBestandnaam = File.Open(Naam, FileMode.OpenOrCreate,
FileAccess.ReadWrite);
           FFullBestandnaam.Position = 0;
       }

       private static RegistryKey _Key_LocalMachine =
Registry.LocalMachine;
       private static RegistryKey _Key_Software;
       private static RegistryKey _Key_Company;
       private static RegistryKey _Key;
       private static RegistryKey _Subkey;
       ...
       static void InitRegistry()
       {
           _Key_Software =
_Key_LocalMachine.OpenSubKey(sKEY_SOFTWARE, true);
           using (RegistryKey
               //  UnauthorizedAccessException => Here the exception
starts
               tempKey =
_Key_LocalMachine.CreateSubKey(sKEY_SOFTWARE))
           {
               _Key_Software =
_Key_LocalMachine.OpenSubKey(sKEY_SOFTWARE, true);
           }

           _Key_Company = _Key_Software.OpenSubKey(sKEY_COMPANY,
true);
           using (RegistryKey
               tempKey = _Key_Software.CreateSubKey(sKEY_COMPANY))
           {
               _Key_Company = _Key_Software.OpenSubKey(sKEY_COMPANY,
true);
           }
       }

Yours sincerly, Wesley
Peter Bromberg [C# MVP] - 23 Mar 2008 23:16 GMT
Wesley,
This is happening because the Windows Identity your code is running under
does not have the required permissions. Since you haven't provided
information about what kind of application this is or how the credentials
have been determined, the best advice would be to search on "how to run an
application as Administrator".
In particular, Willy DeNoyette has a post earilier in this group about how
to embed the correct manifest for same into your application.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short Urls & more: http://ittyurl.net

> Hello,
>
[quoted text clipped - 55 lines]
>
> Yours sincerly, Wesley

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.