Help with Permissions in Vista? RRS feed

  • Question

  • Hi,

    I'm relatively new to .NET and am developing an Application for Windows Vista. I'm running into a couple of issues with the Application when it's trying to do 2 things - Copy a file, or Set a Registry Key Value. When I'm running VS2005 both these 2 functions work no problem, but I would assume that this is because I run VS2005 as an Administrator. My Application won't be able to run as an Administrator I don't think, because I will be running the Application from boot up as a shell.

    For the file copy, I'm using a straightforward File.Copy, e.g.:

    Dim strPathFrom As String = "C:\FolderName\Filename.txt"
    Dim strPathTo As String = "C:\Filename.txt"
    File.Copy(strPathFrom, strPathTo, True)

    This raises the following error:
    Access to path "C:\Filename.txt" is denied


    When I try to Set a Registry value, I was trying to look for the permission to do it with code, but it's not working:

    Imports System.Security.Permissions

    <Assembly: RegistryPermissionAttribute( _
        SecurityAction.RequestMinimum, ViewAndModify:="HKEY_LOCAL_MACHINE")>

    Public Class Reset
        Private Sub SetRegistry
            My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "Shell", "C:\MyProgram.exe")
        End Sub
    End Class

    When I run this I get:
    Attempted to perform an unauthorized operation

    Wednesday, February 7, 2007 10:04 AM

All replies

  • Standard users aren't allowed to create files at the root of the OS drive (only admins and SYSTEM can). They can create folders there though, and files within these folders.
    You'll find the same is true from the default Shell.

    With regards to the key, it's a per-machine location.
    Like most per-machine locations, they affect all users and as such typically aren't modifiable by standard users.

    Changing this may belong to this installation phase, or you could modify the same key in HKCU...


    Thursday, February 8, 2007 9:43 PM