Re: Creating directories on Vista machines using .NET



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.




.



Relevant Pages

  • Re: Mapped Drives and VB6 on Vista
    ... administrator where possible. ... I have shared a local folder and mapped it as my Y:\ drive; ... Is the problem with Vista? ... I've encountered this problem with installation ...
    (microsoft.public.vb.general.discussion)
  • Re: User Account Suddenly Unaccessable
    ... me that only the Administrator has access to the CWLee profile folder. ... The Sharing tab has "Do not share this folder" checked, ...
    (microsoft.public.win2000.general)
  • Re: User Account Suddenly Unaccessable
    ... As I started to type the second command, ... I get two error messages. ... Contact your network administrator. ... It tells me that only the Administrator has access to the CWLee profile folder. ...
    (microsoft.public.win2000.general)
  • Re: User Account Suddenly Unaccessable
    ... Modify the registry so that it points at the correct folder. ... - Log on as administrator ... The Sharing tab has "Do not share this folder" checked, ... In the middle section none of the "permissions" categories have any ...
    (microsoft.public.win2000.general)
  • Re: Can not create a new file with File.Create -- throws exception: Access Denied
    ... difficult to do this right now (and I'm really suspecting Vista). ... It will be a general logging location. ... Keep in mind that "administrator" is just ... The sFileStoreLocation is pointing to a new folder that I created, ...
    (microsoft.public.dotnet.languages.csharp)