none
Buffer file RRS feed

  • Question

  • Hi All,

    What trying to do is;

    1.Save all file in c:\windows\system32 to the buffer c:\my Documents\Backup_32

    2.When computer detect one of the file in c:\windows\system32 has changed then restore back from Buffer.

    Thank.

    Imports System.IO
    Imports System.Text
    Imports System.Diagnostics
    
    Public Class Form1
        Dim watchfolder As New FileSystemWatcher
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            watchfolder.Path = "c:\windows\system32"
    
            AddHandler watchfolder.Deleted, Sub()
                                                MsgBox("File Delete")
                                            End Sub
            AddHandler watchfolder.Renamed, Sub()
                                                MsgBox("File Rename")
                                            End Sub
            AddHandler watchfolder.Changed, Sub()
                                                MsgBox("File Changed")
                                            End Sub
            AddHandler watchfolder.Created, Sub()
                                                MsgBox("File Created")
                                            End Sub
    
    
            watchfolder.EnableRaisingEvents = True
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
            Dim sFolder As String = "c:\windows\system32"
            Dim sFolder_Copy As String = "C:\Users\Uset\Documents\Backup_Sys32"
    
            For Each foundFile As String In My.Computer.FileSystem.GetFiles(sFolder)
                TextBox1.AppendText(foundFile & vbCrLf)
    
                ' convert string to stream
                Dim buffer As Byte() = Encoding.ASCII.GetBytes(foundFile)
                Dim ms As New MemoryStream(buffer)
                'write to file
                Dim file As New FileStream(sFolder_Copy, FileMode.Create, FileAccess.Write)
                ms.WriteTo(file)
    
                file.Close()
                ms.Close()
    
            Next
    
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    
            Dim sFolder_Copy As String = "C:\Users\Uset\Documents\Backup_Sys32"
            Dim Text As String = ""
    
            Dim f As System.IO.FileStream
            Dim i As Integer
            Dim mybuffer(100) As Byte
            f = New System.IO.FileStream(sFolder_Copy, IO.FileMode.Open, IO.FileAccess.Read)
            f.Read(mybuffer, 0, 100)
            For i = 0 To 100
                Text &= Chr(mybuffer(i))
                'Need to see in progress
                'TextBox2.AppendText(? & vbCrLf)
            Next
            f.Close()
    
    
    
        End Sub
    
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    
        End Sub
    End Class
    

    Saturday, June 15, 2019 4:09 AM

All replies

  • Hi

    Bad idea messing with system files. What OS are you using, it must not be Windows 10?

    I have no intenrion of trying your code as I value my system as it is, but even if I did try it, I wouldn't get very far as Windows 10 has security that aims to prevent such things.

    Would you be comfortable if some other persons application could manipulate your system files like that? Just as some viruses do!


    Regards Les, Livingston, Scotland


    • Edited by leshay Saturday, June 15, 2019 10:23 PM
    Saturday, June 15, 2019 1:19 PM
  • thank leshay for your exlanation.

    I 'm using windows 10

    i need some knowledge in line

    For i as integer= 0 to 100

    next

    why 100?

    Saturday, June 15, 2019 2:42 PM
  • Hi

    That would be the Buffer size as assigned by

    Dim mybuffer(100) As Byte


    Regards Les, Livingston, Scotland

    Saturday, June 15, 2019 6:22 PM

  • i need some knowledge in line

    For i as integer= 0 to 100

    next

    why 100?

    If you have to ask that question then it's evident that you didn't write this
    code yourself. So you appear to be taking code you got from somewhere which
    messes with system files and presumably are going to try using it on your
    own computer. Even though you don't fully understand the code. That's doubly
    perilous.

    As Les said: "Bad idea messing with system files." It's a bad idea compounded
    when you don't fully understand what the code is doing.

    Do you understand the implications of reverting some of the operating system 
    files to older versions after Windows 10 may have done an update?

    - Wayne


    Saturday, June 15, 2019 9:43 PM
  • thank you WayneAKing and leshay.

    Maybe I asked the wrong way,Touch system files.This ways can be protect the own program created.

    sorry.

    Saturday, June 15, 2019 11:44 PM
  • thank you WayneAKing and leshay.

    Maybe I asked the wrong way,Touch system files.This ways can be protect the own program created.

    sorry.

    Hi

    Are you aware that Windows 10 has extensive system file management including protection and auto repair?


    Regards Les, Livingston, Scotland

    Saturday, June 15, 2019 11:57 PM
  • u very clever, leshay.

    Not all files in system are turn on.

     
    Sunday, June 16, 2019 1:33 AM
  • u very clever, leshay.

    Not all files in system are turn on.

     

    Hi,

    If the issue still exist,please feel free to contact us.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 19, 2019 8:41 AM
    Moderator
  • I agreed with WayneAking said, I'm not fully understand what I write.

    But I thinking that way can protect my program if all files hold by memory.It can check if files changed.

    Or you can advice How can I do to protect all files in my program.

    Thank you very much Alex for always helping me.

    Saturday, June 22, 2019 3:06 PM
  • Hi

    So, now we get the actual question. Have you tried any research, if so, you would have found hundreds of relevant posts on this topic. Just type 'protection' into the search box at the top of the forum.

    Here are my thoughts: if your application is any good at all, 99% of people wouldn't be bothered in trying to 'cheat'.

    If you are selling your application, then the best protection is for the application to be very very good.

    You can try a variety of methods that will serve to prevent the curious from getting very far, but no amount of protection would rreally stop any determined knowledgable coder from breaking it.

    Even commercial protection is not completely safe.


    Regards Les, Livingston, Scotland


    • Edited by leshay Saturday, June 22, 2019 3:30 PM
    Saturday, June 22, 2019 3:29 PM
  • thank you,Leshay
    Sunday, June 23, 2019 9:01 AM
  • thank leshay for your exlanation.

    I 'm using windows 10

    i need some knowledge in line

    For i as integer= 0 to 100

    next

    why 100?

    Good question in 2019. To answer it right, because managers could not decide in 2000.

    In 2000 they decided that an array of (100) would mean 101 items. 

    Therefore 0 to 100 means 101 items. 

    VB before 2000 used 1 for the first indexer and not zero as in assembler languages. 


    Success
    Cor

    Sunday, June 23, 2019 7:51 PM
  • thank Cor ligthert.

    Monday, June 24, 2019 12:01 PM