1

In the below Code i get a Path/File Access Error In Vb 6 .

Open App.Path & "\testing.Bat" For Output as #1

This error happens in windows 7 PC's only & not at all times & Only in sometimes any virus issue involved here?

Any one give me a solution . Please ?

C-Pound Guru
  • 15,967
  • 6
  • 46
  • 67
sangilirajan
  • 11
  • 1
  • 2
  • 1
    You aren't supposed to write to `App.Path`. See [this question](http://stackoverflow.com/questions/4273424/where-should-i-store-application-specific-settings) for more information – MarkJ Sep 06 '12 at 15:27
  • 3
    Using a fixed file number isn't too classy either, as well as being error-prone leading to crashes. A `Close` is a "lazy close" so you can leave file number 1 tied up and then try to reuse it - kaboom. Get out of this habit fast! – Bob77 Sep 06 '12 at 21:54
  • What is `App.Path` at the time? – Deanna Sep 14 '12 at 13:47

2 Answers2

1

If App.Path is c:\Program Files, it's most likely a rights issue. On Windows 7, even if you are an Administrator, you don't always have full rights to Program Files.

C-Pound Guru
  • 15,967
  • 6
  • 46
  • 67
-1

When you launch you Visual Studio 6.0 IDE, make sure you right click the icon and select "Run As Administrator" instead of just running it normally, you can also right click the shortcut icon, select properties, and in the Compatability tab, you should be able to check "Run As Administrator" so that every time you click the shortcut for Visual Basic 6.0, it will run in admin mode (and may ask/prompt you every time, in which case, you must select Yes). In this case, the File/Path access error will go away :).

Let me know how you get along and if you need more help.

Erx_VB.NExT.Coder
  • 4,838
  • 10
  • 56
  • 92
  • There shouldn't be any need to run the VB6 IDE in admin mode except when compiling or registering COM components or testign something that truely needs elevation. It certainly won't help them fix it for other machines. – Deanna Sep 07 '12 at 12:30
  • @Deanna Since the debugger is running under the devenv process, elevated VS IDE will mean the code the OP is running will be elevated and he will not be getting the file/path access error. Of course, if he is compiling and running the exe seperately, there is no need to elevate the VS IDE, & he can just do the exact same thing for the EXE file that he is running. im trying to help him understand his problem, youre trying to say its bad practice, right? Even though i wasn't even advocating a practice, but just trying to help him understand the problem & how to fix it without making assumptings. – Erx_VB.NExT.Coder Sep 08 '12 at 22:12
  • You were suggested a work around for the problem which isn't normally relelvant to the recomended fix. If it was just a "this will explain what's happening" then it should be a comment, not an answer. I was just making this clear to the OP and explaining my downvote. – Deanna Sep 10 '12 at 08:00
  • @Deanna I also wasn't assuming that he'd be running this code on other machines, the solution was for his scenario & his machine since thats where it was happening & thats the location & scenario that he had requested help for. I just told him why its happening & how to prevent it from happening, without assuming he is distributing it without assuming he wants to get rid of the same problem on other peoples machines. Of course, once he understands the problem, he can figure out what needs to be done if distributing. It directly answered OP's question for stated scenario and nothing more! – Erx_VB.NExT.Coder Sep 13 '12 at 13:42