14 Replies - 16844 Views - Last Post: 16 March 2011 - 09:15 AM Rate Topic: -----

#1 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

How to Create Directory In Windows 7

Posted 16 March 2011 - 12:12 AM

Hi,
I used this code in WIndows xp its work fine
System.IO.Directory.CreateDirectory(Application.StartupPath + "\\Errors\\");


but when i install my software to other machine(Windows 7) i got error access denied.
so i manually Create Directory (Errors) in StartupPath so its work fine
so how to resolve this problem i don't want to create directory manually.

Is This A Good Question/Topic? 0
  • +

Replies To: How to Create Directory In Windows 7

#2 Ändrew  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 25
  • View blog
  • Posts: 312
  • Joined: 21-April 08

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 01:04 AM

Try running it under administrator.

Example [From debug mode]

Project -> (Project Name) Properties -> Debug

Start Options
Command line arguments

Type in the textbox: runas


Example [Windows Vista/Seven]
Find the executable.
Right click on it and press Run as Administrator



Ändrew

This post has been edited by Ändrew: 16 March 2011 - 01:05 AM

Was This Post Helpful? 3
  • +
  • -

#3 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 02:42 AM

Actually I am maintaining errorlog if error occur in my application than Directory(Errors) create in my installation path and also crate a text file in Directory to write error details.

it's work fine in XP but when i installed setup of my software on WIndows 7 .
i aspected while error occur in my application at that time Directory and File should be Created in my installation path
but i got error " //Errors...access denied ".
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5578
  • View blog
  • Posts: 11,918
  • Joined: 02-June 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 04:05 AM

Repeating the problem description is unnecessary: We got it the first time.

Andrew already told you how to fix it: You need to run your application as Administrator.
Was This Post Helpful? 1
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 04:57 AM

Windows XP and Windows 7 handle security differently. Most applications, running under normal circumstances, will not have write access to the Program Files in Windows 7.

You need to either run the application as administrator(as Ändrew and tlhIn`toq stated), or create your directory in one of the user folders. Users will have write access to their "user" directory in Windows 7. This is where the Application Data and My Documents directories are located.
Was This Post Helpful? 2
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 05:18 AM

You can check if the version of the windows is Vista or Higher and if so write it in different directory then application.startuppath:
if (Environment.OSVersion.Version.Major < 6)
{
  //'Its XP or less'
}
else
{
  //'Its vista or higher version of OS'
}


Was This Post Helpful? 3
  • +
  • -

#7 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 05:38 AM

Thank You Guys!
Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 06:15 AM

One more thing if i may add. Here is interesting video on programing for standart user:
http://www.dreaminco...-standard-user/

In my opinion you have to make your program this way so that your program should not run as administrator. There are several restriction that you must follow when writing your program (the video covers most of them) but the least things are to not write/create files or folders in restricted folders. Dont write in the registry(you dont have the reason for doing this rly).
Was This Post Helpful? 1
  • +
  • -

#9 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 07:48 AM

There's folders designed specifically for this: the user app data folders. And guess what? There's a property that makes this path easily available to you:

Application.UserAppDataPath

You should already have permission there to write to a log.
Was This Post Helpful? 4
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5578
  • View blog
  • Posts: 11,918
  • Joined: 02-June 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 08:18 AM

View PostNoBrain, on 16 March 2011 - 07:15 AM, said:

Don't write in the registry(you dont have the reason for doing this really).


I don't know if I can agree with this. Maybe someday. But not this year. Its a nice theory, but the Registry was mean for holding persistent data and has been in use for years. Maintaining backward compatibility often necessitates its use. It's the one place guaranteed to be reachable where you expect it regardless of OS version, not affected by which user is logged in, easily organized in hierarchical node format and so on.

As much as MS says it's a bad practice, they themselves haven't gone away from it. They write to the registry in their latest OS and in all the Win7 applications they build. It's really hard to preach something when you can't follow it yourself.
Was This Post Helpful? 4
  • +
  • -

#11 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 08:35 AM

As long as you can clean up after yourself. Make sure that your installer's uninstall action kills any registry entries you've made, and then it's not that bad. Tens of thousands of orphaned keys are annoying though.
Was This Post Helpful? 0
  • +
  • -

#12 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 08:41 AM

You can also give a directory full permission for system users in Program Files ,which is a quick way just for "testing" application code , but writing directly under C:\Folderpath
directory does not produce any errors in Win 7.

This post has been edited by marinus: 16 March 2011 - 08:43 AM

Was This Post Helpful? 0
  • +
  • -

#13 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 08:49 AM

View PosttlhIn`toq, on 16 March 2011 - 05:18 PM, said:

View PostNoBrain, on 16 March 2011 - 07:15 AM, said:

Don't write in the registry(you dont have the reason for doing this really).


I don't know if I can agree with this. Maybe someday. But not this year. Its a nice theory, but the Registry was mean for holding persistent data and has been in use for years. Maintaining backward compatibility often necessitates its use. It's the one place guaranteed to be reachable where you expect it regardless of OS version, not affected by which user is logged in, easily organized in hierarchical node format and so on.

As much as MS says it's a bad practice, they themselves haven't gone away from it. They write to the registry in their latest OS and in all the Win7 applications they build. It's really hard to preach something when you can't follow it yourself.


i`m sorry i thought that there was restrictions writing to the registry.

This post has been edited by NoBrain: 16 March 2011 - 08:49 AM

Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6077
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 09:08 AM

View PostinsertAlias, on 16 March 2011 - 11:35 AM, said:

As long as you can clean up after yourself. Make sure that your installer's uninstall action kills any registry entries you've made, and then it's not that bad. Tens of thousands of orphaned keys are annoying though.


That would be fab, if Microsoft and its ClickOnce technology for VSTO allowed me to do so :P This VSTO crap makes me leave all sorts of stuff behind that was created in the process of operation.
Was This Post Helpful? 0
  • +
  • -

#15 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4531
  • View blog
  • Posts: 7,902
  • Joined: 08-June 10

Re: How to Create Directory In Windows 7

Posted 16 March 2011 - 09:15 AM

ClickOnce is just good for little bullshit deployment. If you're going to do real deployments, make a real setup package. If you don't have the version of VS to do that, I'd suggest a third party installer. Nullsoft Installer is open source, I believe.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1