简体   繁体   中英

Ini File opengin

I have a applicaiton which reads from ini at startup

What i want is a vb code that will block the user from opeing the ini file manually

program could be runnung as service

eg: C:\\config.ini

program should block the user from opeing the file

To lock a file you can use something like this. Keep in mind this is not tested. Also remember to import System.IO

Private Sub LockFile(ByVal file As String)

    Dim FileSt As FileStream = New FileStream("test.dat", FileMode.Create, FileAccess.Write, FileShare.Write)
    Try
        FileSt.Lock(0, FileSt.Length)
        Debug.WriteLine("Locked")
    Catch Ex As Exception
        Debug.WriteLine(Ex.Message)
    End Try

End Sub

Private Sub UnlockFile(ByVal file As String)

    Dim FileSt As FileStream = New FileStream("test.dat", FileMode.Create, FileAccess.Write, FileShare.Write)
    Try
        FileSt.Unlock(0, FileSt.Length)
        Debug.WriteLine("Unlocked")
    Catch Ex As Exception
        Debug.WriteLine(Ex.Message)
    End Try

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM