|
-
Aug 21st, 2000, 05:02 PM
#1
Thread Starter
New Member
I am writing to an ini file using the win API function WritePrivateProfileString. If I try to delete the file or overwrite it after using the WritePrivateProfileString, nothing happens. Can anyone help me with this?? Here's the code I've written:
WritePrivateProfileString "Testing FSO", "Worked", "No", _
"C:\windows\desktop\joey.ini"
WritePrivateProfileString "Testing FSO", "Worked2", "No", _
"C:\windows\desktop\joey.ini"
Kill "C:\windows\desktop\joey.ini"
If the file joey.ini doesn't exist then WritePrivateProfileString creates it, but then the kill statement won't delete it. Even if the file exists already it won't delete it. The only instance where it was deleted was when those settings written by WritePrivateProfileString already existed. HELP!!!!???
-
Aug 21st, 2000, 05:24 PM
#2
WritePrivateProfileString should automatically write over it.
Try this:
Code:
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Call WritePrivateProfileString("Testing FSO", "Worked", "No", "C:\windows\desktop\joey.ini")
Call WritePrivateProfileString("Testing FSO", "Worked2", "No", "C:\windows\desktop\joey.ini")
'And deleting...
Kill ("C:\Windows\Desktop\joey.ini")
-
Aug 21st, 2000, 05:31 PM
#3
Thread Starter
New Member
I just tried that and the file still won't delete. it remains on the desktop.
-
Aug 21st, 2000, 05:52 PM
#4
Does any error come up? Are you specifying the correct file? When you try to delete the file, is it open? Because if a file is open, the Kill function will not work.
You could also try this code:
Code:
Sub DestroyFile(sFileName As String)
Dim Block1 As String, Block2 As String, Blocks As Long
Dim hFileHandle As Integer, iLoop As Long, offset As Long
'Create two buffers with a specified 'wipe-out' characters
Const BLOCKSIZE = 4096
Block1 = String(BLOCKSIZE, "X")
Block2 = String(BLOCKSIZE, " ")
'Overwrite the file contents with the wipe-out characters
hFileHandle = FreeFile
Open sFileName For Binary As hFileHandle
Blocks = (LOF(hFileHandle) \ BLOCKSIZE) + 1
For iLoop = 1 To Blocks
offset = Seek(hFileHandle)
Put hFileHandle, , Block1
Put hFileHandle, offset, Block2
Next iLoop
Close hFileHandle
'Now you can delete the file, which contains no sensitive data
Kill sFileName
End Sub
Call DestroyFile("C:\Windows\Desktop\joey.ini")
-
Aug 21st, 2000, 07:08 PM
#5
Thread Starter
New Member
-
Aug 22nd, 2000, 01:12 PM
#6
Thread Starter
New Member
Can somebody help me with this??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|