Create a subdirecory in "All Users/Application Data"

148 views
Skip to first unread message

Arnaud Mongrain

unread,
Jul 22, 2011, 10:03:55 AM7/22/11
to dotnetde...@googlegroups.com
Hello,
 
I've got a problem at work.  In a program, I'm trying to create an xml file so it would always log automatically using the first user credentials that connected.  To be sure every user of the terminal will be able to use it, I created the file in "All Users/(Application Name)/login.xml".
 
I'm using DirectoryInfo.CreateSubdirectory(string) to create my subfolder (Application Name) if it doesn't exist.  That part works on my work PC, but doesn't on the terminal.  And since du Application Name folder doesn't exist on the terminal, program won't run cause it can't create the file in the folder, since it doesn't exist...
 
I'm currently log as an administrator on that terminal, so I don't understand why it wouldn't work.
 
Any ideas?
 

if

(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + \\Application Name))

{

DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));

dir.CreateSubdirectory(

"Application Name");

}

Benj Nunez

unread,
Jul 26, 2011, 5:50:27 AM7/26/11
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Try the example(s) indicated here:

http://msdn.microsoft.com/en-us/library/system.io.file.setaccesscontrol.aspx
http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemaccessrule.aspx


Regards,


Benj



On Jul 22, 10:03 pm, Arnaud Mongrain <arnaudmongr...@gmail.com> wrote:
> Hello,
>
> I've got a problem at work.  In a program, I'm trying to create an xml file
> so it would always log automatically using the first user credentials that
> connected.  To be sure every user of the terminal will be able to use it, I
> created the file in "All Users/(Application Name)/login.xml".
>
> I'm using DirectoryInfo.CreateSubdirectory(string) to create my subfolder
> (Application Name) if it doesn't exist.  That part works on my work PC, but
> doesn't on the terminal.  And since du Application Name folder doesn't exist
> on the terminal, program won't run cause it can't create the file in the
> folder, since it doesn't exist...
>
> I'm currently log as an administrator on that terminal, so I don't
> understand why it wouldn't work.
>
> Any ideas?
>
> if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
> + \\Application Name <file://application%20name/>))
>
> {
>
> DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.
> SpecialFolder.CommonApplicationData));
>
> dir.CreateSubdirectory("Application Name");
>
>
>
>
>
>
>
> }

Kira Qian

unread,
Aug 1, 2011, 2:46:55 AM8/1/11
to dotnetde...@googlegroups.com

The scenario is unclear to me. Does the application run on the terminal server?  When a user login to your terminal server and run your application, you want to write the user information in login.xml? If you mean that, first you need to add users who can use your app to a group (Name Group_A). Then configure the NTFS permission of “All Users” folder let Group_A has enough permission. “All Users” folder is not a good implement, you might think of using ProgramData folder. 

Cerebrus

unread,
Aug 2, 2011, 3:38:38 AM8/2/11
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Are you able to gain access to the ApplicationData SpecialFolder? Is
the problem occurring when you try to create the folder ?

Check the exception that is thrown. That should provide you more
details about the problem. It does sound like a permissions problem.
You mention that you login as Admin on the terminal, but what
credential does your code use?


On Jul 22, 7:03 pm, Arnaud Mongrain <arnaudmongr...@gmail.com> wrote:
> Hello,
>
> I've got a problem at work.  In a program, I'm trying to create an xml file
> so it would always log automatically using the first user credentials that
> connected.  To be sure every user of the terminal will be able to use it, I
> created the file in "All Users/(Application Name)/login.xml".
>
> I'm using DirectoryInfo.CreateSubdirectory(string) to create my subfolder
> (Application Name) if it doesn't exist.  That part works on my work PC, but
> doesn't on the terminal.  And since du Application Name folder doesn't exist
> on the terminal, program won't run cause it can't create the file in the
> folder, since it doesn't exist...
>
> I'm currently log as an administrator on that terminal, so I don't
> understand why it wouldn't work.
>
> Any ideas?
>
> if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Comm­onApplicationData)
> + \\Application Name <file://application%20name/>))
>
> {
>
> DirectoryInfo dir = new DirectoryInfo(Environment.GetFolderPath(Environment.
> SpecialFolder.CommonApplicationData));
>
> dir.CreateSubdirectory("Application Name");
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -

Jay Dan

unread,
Aug 2, 2011, 1:21:45 PM8/2/11
to dotnetde...@googlegroups.com
Try to assign network service user on the top level folder under which
u want to create ur sub dir or file.

> --
> You received this message because you are subscribed to the Google
> Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
> Web Services,.NET Remoting" group.
> To post to this group, send email to dotnetde...@googlegroups.com
> To unsubscribe from this group, send email to
> dotnetdevelopm...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
> or visit the group website at http://megasolutions.net
>

--
Sent from my mobile device

Jay

Arnaud Mongrain

unread,
Aug 2, 2011, 7:58:39 AM8/2/11
to dotnetde...@googlegroups.com
I feel bad about all of it.  I made a mistake on that problem!  I thought I wasn't able to create the folder, but it was another mistake... seems I was trying to read it before it was created.  I trapped that error.  Should have noticed earlier, but I can't debug on that terminal.  It's now all good and my folder is created when it has to!
 
Thank everyone for your help, though.

2011/8/2 Cerebrus <zor...@sify.com>

Busted!

unread,
Aug 2, 2011, 4:20:50 AM8/2/11
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi.

The common application data folder (as opposed to the program files
folder) is a good place to put shared files. The default permission on
this folder however, is everyone read without write permission. This
can be changed/set using the installer.
Since the default Visual Studio installer project cannot do this
simply by setting a property, you must add a custom install action
( http://msdn.microsoft.com/en-us/library/d9k65z2d(v=vs.80).aspx )
which can set the permission on the directory.

Since you have multiple accounts that are to write to the file, the
permission might use "Users" or "Everyone". If at all possible, try to
avoid "Everyone" since its literally... everyone...

Cheers

Arnaud Mongrain

unread,
Aug 4, 2011, 7:56:09 AM8/4/11
to dotnetde...@googlegroups.com
Thanks for that information, but it will be use in the business I work for, and so will be "installed" by an administrator before the users can use it.  Those users won't have access to modify those config files, so in fact I'm really happy to learn they won't be able to do anything else than read it.  Once it is configurated, nothing should be change, but in case something must that access is limited to the local administrator.
 
Thanks for all of your answers guys, but please, remember that my problem is solved, like a wrote some days ago!
2011/8/2 Busted! <magnus...@gmail.com>

--
Reply all
Reply to author
Forward
0 new messages