Categories

CODE
Visual C++ Programming
C++ (Non Visual C++ Issues)
Modern Windows Apps (Metro)
C++ and WinAPI
Managed C++ and C++/CLI
Visual C++ Bugs & Fixes
Graphics Programming
Multithreading
Network Programming
Driver Development
Visual Basic 6.0 Programming
Visual Basic .NET
Crystal Reports
C-Sharp Programming
Managed C++
Visual Basic .NET
ASP.NET
.NET Framework
ADO.NET
Windows Presentation Foundation (WPF) & XAML forum
Silverlight
.NET Installation and Configuration Issues
Java Programming
AJAX
Scripting - Client Side
Database
XML
Wireless/Mobile Development
Assembly
Scripting - Server Side (PHP, Perl, etc.)
Python
General Developer Topics
Project Planning, Design, and Management
Testers and Testing
Algorithms & Data Structures
General Discussion / Chit Chat
Announcements, Press Releases, & News
Feedback
Articles Suggestions
Testing Area
Programming Projects
C# Game(s) Project
Game Engine Project
C++ Coding Project
Project: Code War
Slow Chat: Talk with Microsoft Developer Teams
Slow Chat: Developing Multithreaded Applications
Slow Chat: C++0x
Slow Chat: Visual C++: Yesterday, Today, and Tomorrow
Directory Services
General Windows and DNA Programming
Windows OS Issues
Open Positions (Jobs)
Looking for Work
Visual Basic .NET FAQs
Visual Basic FAQs
CodeGuru Individual FAQs
CodeGuru Individual Visual Basic FAQs

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Visual Basic 6.0 Programming

Ask questions about VB 6.0 (or earlier versions) or help others by answering their question.

Permission Denied When Trying To Delete A File


I'm using the following code to copy some lines from file into a new file. After all the correct lines are copied, I delete the old file. This was working just fine last week. But suddenly it's not working on several computers and I don't know why it's not working.      	Code:  	Public Function DeleteLines(ByVal from_name As String, ByVal to_name As String, ByVal target As String) As Long      Dim strlen As Integer      Dim from_file As Integer      Dim to_file As Integer      Dim one_line As String      Dim deleted As Integer        ' Open the input file.      from_file = FreeFile      Open from_name For Input As from_file        ' Open the output file.      to_file = FreeFile      Open to_name For Output As to_file        ' Copy the file skipping lines containing the      ' target.      deleted = 0            Do While Not EOF(from_file)          Line Input #from_file, one_line          If InStr(one_line, target) > 0 Then              Print #to_file, one_line          Else              deleted = deleted + 1          End If      Loop        ' Close the files.      Close from_file      Close to_file            MsgBox ("before kill")      Kill (from_name)        MsgBox ("after kill")      Name to_name As from_name            DeleteLines = deleted  End Function   It fails on the Kill (from_name) line. It says that it doesn't have permission. I'l closing the file before killing, so I don't know what the issue is.    Anyone have any ideas?  				  			

  				  					Try running the EXE as Administrator.  (You didn't say which OS you're targeting)  				  			

  				  					Is the computer on a Domain ??? if the domain admin decided to change some of the access policy's this could cause the sudden failure..  Is the user using the same account as before ??  				  			

  				  					  	  		  			  			  				  					 Originally Posted by dglienna  					  				  				Try running the EXE as Administrator.  (You didn't say which OS you're targeting)  			  		  	   UAC is turned off.    	  		  			  			  				  					 Originally Posted by GremlinSA  					  				  				Is the computer on a Domain ??? if the domain admin decided to change some of the access policy's this could cause the sudden failure..  Is the user using the same account as before ??  			  		  	   Security settings are valid.  I can delete the file on form_load, but I can't delete it inside of the method. Even If I put it as the first line in the method, it still won't delete.  				  			

  				  					  	  		  			  			  				UAC is turned off.  			  		  	   Narrows it down to the last 4. Or not counting XP?  Brilliant.  				  			

  				  					  	  		  			  			  				  					 Originally Posted by weirddemon  					  				  				Security settings are valid.  I can delete the file on form_load, but I can't delete it inside of the method. Even If I put it as the first line in the method, it still won't delete.  			  		  	   Then somewhere in the code the file is still held open (or the file is open in another proggy)  				  			

  				  					I'm going to get shot for saying this, have you considered using DoEvents just after you closed your file, then, after DoEvents use kill?  				  			

  				  					I was posting in this thread on the other forum, turns out he had some other code that is not shown here which opened the file but had not yet closed it when the code here was called. We missed that because the problem code was never shown so all we could do is guess at drive permissions and such.


Related Links

How to append it the data is getting scattered in the file???
Change datagrid Column Value ???
Sending Email to Multiple Receiptents in VB6 using MAPI
Running Batch File With O/P Redirection From VB
use of NOT IN clause in sql query in vb6
[RESOLVED] Syntax Error
AutoVerb Menu in Sheridan SSDBGrid
[RESOLVED] Repeated Ctrl-C and Ctrl-V messages
Error with using VB to access cell in Excel
[RESOLVED] Run time error 13, type mismatch
Mousehooks and Cursor speed
listview problem
Text Box Beeping
[MySQL][ODBC 3.51 Driver]Can't connect to MySQL server 10060
Finding strings in multiple files
Adding context menu to Farpoint Tab Pro control