joker77 Posted February 7, 2007 Posted February 7, 2007 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 Quote What if the Hokey-Pokey IS what it's all about?
Administrators PlausiblyDamp Posted February 7, 2007 Administrators Posted February 7, 2007 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joker77 Posted February 7, 2007 Author Posted February 7, 2007 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 I'm 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 it's running from O/S load as a shell Quote What if the Hokey-Pokey IS what it's all about?
Administrators PlausiblyDamp Posted February 7, 2007 Administrators Posted February 7, 2007 If you use the application as a shell it will be launched with the security credentials of the user logging in. As far as I'm 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 can't think of many things that would expose security concerns more than a shell always having admin rights regardless of who logs in. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joker77 Posted February 7, 2007 Author Posted February 7, 2007 If you use the application as a shell it will be launched with the security credentials of the user logging in. As far as I'm 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 can't 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 it's a kiosk type application - it'll be touchscreen with no keyboard, and the only thing I want running is my application, so I'll be locking down the security that way. Quote What if the Hokey-Pokey IS what it's all about?
Administrators PlausiblyDamp Posted February 8, 2007 Administrators Posted February 8, 2007 What does your application do? If it is only accessing it's 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.