Help with Permissions in Vista?

joker77

Active member
Joined
Sep 16, 2005
Messages
38
Location
Dublin
Hi,

Im relatively new to .NET and am developing an Application for Windows Vista. Im running into a couple of issues with the Application when its trying to do 2 things - Copy a file, or Set a Registry Key Value. When Im 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 wont be able to run as an Administrator I dont think, because I will be running the Application from boot up as a shell.

For the file copy, Im using a straightforward File.Copy, e.g.:
Code:
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 its not working:
Code:
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
 
You would either need to relax the security on the folders / keys you need access to or run the application as a user with permissions to those resources.

Alternatively if you are only dealing with your own files etc. you could store them in locations the user does have access to.
 
You would either need to relax the security on the folders / keys you need access to or run the application as a user with permissions to those resources.

Alternatively if you are only dealing with your own files etc. you could store them in locations the user does have access to.
Well Im logged onto the machine as an Administrator, and as I said - if I run the program in debug through VS2005 (which I run as an Administrator), the functions work correctly.

I suppose I need a way of running the program as an Administrator, even though its running from O/S load as a shell
 
If you use the application as a shell it will be launched with the security credentials of the user logging in. As far as Im aware there is no way to get your shell launched with an alternative set of credentials. As a work around you could make the shell a stub application that launches your shell via something like the runas command to elevate the permissions.

Personally I cant think of many things that would expose security concerns more than a shell always having admin rights regardless of who logs in.
 
If you use the application as a shell it will be launched with the security credentials of the user logging in. As far as Im aware there is no way to get your shell launched with an alternative set of credentials. As a work around you could make the shell a stub application that launches your shell via something like the runas command to elevate the permissions.

Personally I cant think of many things that would expose security concerns more than a shell always having admin rights regardless of who logs in.
Thanks for that - could you provide some more info on how the stub application would call my app to runas admin?

Regarding the security - yea I hear ya, but its a kiosk type application - itll be touchscreen with no keyboard, and the only thing I want running is my application, so Ill be locking down the security that way.
 
What does your application do? If it is only accessing its own files etc. then there is no need to putthose files in a location hat requires admin access.

One easy way to launch an application as another user is the runas command - type runas /? at a command prompt to see the help for it.
 
Back
Top