Re: Creating directories on Vista machines using .NET
- From: Steve Barker <stevebarker@xxxxxxxxxxxxx>
- Date: Fri, 11 May 2007 09:02:00 -0700
Hi Patrice,
Thanks for your reply!
I didn't realise that you don't intrinsically get create permissions on
Program File folders if you're not an administrator. Just goes to show that
almost all users run Windows under an administrator account all the time. No
wonder viruses are so prevalent!
Under Vista, when you try to create folders under the Program Files, you
don’t get an error. The application continues as though everything is fine,
except the folder is not created. This is the case even when you’re logged in
as an administrator. However, you can get round this by "running the program
as an administrator". To do this, you must find the executable you are trying
to run (because the option isn’t available from the shortcut), and right
click. The option is something like “Run as administrator…” In that case, the
application is able to create the folder. If you're already logged on as an
administrator, the thing just works. Otherwise, a dialog appears for you to
enter administrator login information.
XP is a different matter. When you log in as an administrator, the folder is
created with no problems. However, when you log in as a standard user, you
get a nasty .NET unhandled exception when you try to create the folder.
Has anyone got any suggestions as to how I can make my application more
elegant? I am aware of Permission classes in .NET; in this case, the one I
need is FileIOPermission. However, I’m not exactly sure what this can do or
what the best way to use them would be. Surely, the Assert() method won’t
actually give the application the permissions it needs?!
Thanks in advance,
Steve.
"Patrice" wrote:
Even in XP, AFAIK you can't create a directory in "program files" (is this.
where your executable is ?) under a non administrative account. Depending on
what you are trying to store, I would rather try another location...
Else what is the error you get ?
"Steve Barker" <stevebarker@xxxxxxxxxxxxx> a écrit dans le message de news:
FC7E57C4-0FED-400F-A0D4-784E66E596C3@xxxxxxxxxxxxxxxx
Hi guys,
I've noticed that simple .NET code to create directories does not seem to
work on Vista.
Take the following simple example (implemented in a Windows forms
application):
==========================
FileInfo executableFile = new FileInfo(Application.ExecutablePath);
DirectoryInfo directory =
executableFile.Directory.CreateSubdirectory("Test");
if (!directory.Exists)
{
directory.Create();
}
==========================
This works fine on XP, but not on Vista, despite the "belt and braces"
approach!
I guess this is to do with the improved security model in Vista. Clearly
there will be no way to override this in code (else it is useless in
preventing hackers from playing), but it would be good to find some kind
of
solution to this problem, even if that was popping up a box for the user
to
confirm that they're happy for Vista to perform the action.
Does anyone have any ideas as to how I can proceed?
Thanks in advance,
Steve.
- Follow-Ups:
- Re: Creating directories on Vista machines using .NET
- From: "Jeffrey Tan[MSFT]"
- Re: Creating directories on Vista machines using .NET
- From: Patrice
- Re: Creating directories on Vista machines using .NET
- From: Alun Harford
- Re: Creating directories on Vista machines using .NET
- From: Peter Duniho
- Re: Creating directories on Vista machines using .NET
- References:
- Re: Creating directories on Vista machines using .NET
- From: Patrice
- Re: Creating directories on Vista machines using .NET
- Prev by Date: Re: textbox query
- Next by Date: Re: Memory never released in SMO (when create database)
- Previous by thread: Re: Creating directories on Vista machines using .NET
- Next by thread: Re: Creating directories on Vista machines using .NET
- Index(es):
Relevant Pages
|