Results 1 to 6 of 6

Thread: writeprivateprofilestring and deleting files

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4

    Exclamation

    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!!!!???

  2. #2
    Guest
    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")

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4
    I just tried that and the file still won't delete. it remains on the desktop.

  4. #4
    Guest
    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")

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4
    still doesn't work.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4
    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
  •  



Click Here to Expand Forum to Full Width