I'm making program similar to keylogger (in vb2008), that detects keys pressed and then save it...
How can i make, that program will name .txt file like "29.3.20010.txt"? im using this code to make a file:

Dim file As System.IO.FileStream
file = System.IO.File.Create("C:\Key\Keylogg.txt")

how can i insert Date:

Dim dtmDate As Date
        dtmDate = DateValue(Now)

into the name of .txt file?

all keys are written into medium sized rich text box - but how can i make, that saved text will be in same shape as it was...

RichTextBox:
Start: 29.3.2010 21:14:50

[Enter]     viissuaal bbaasic 
    [Enter]     .ttxtt  sasasvvingiim  mamaking pprrogrrraamm ssiimmimlaarr to keeyloggeerr, that  ddetectts  kekyys  prreressedd andnd  theen  sasaavve  it...lockkeerzz
    [Enter]     
    [Enter]     
    [Enter]     
    [Enter]     hhow  cacan i ..
    [Enter]     
    [Enter]     ii  how cacann  i  make,, tthatt pprrorgrraam will naammweee  .ttxt fiile likeke ...!..ttxt2   iiimm  usinngg  tthhiss  coddee  to mamakke a  fille.
    [Enter]     
    [Enter]     
    [Enter]     
    [Enter]     how cacan i  inseerrtt daatee
    [Enter]     .
    [Enter]     
    [Enter]     
    [Enter]     intto thhee naame  of  txt.txt  ffile
    [Enter]     
    [Enter]     
    [Enter]     aandnd  d   i  hahave  limmediium siizzeed  riichh  texxt boxaall  keys aarer  writteen iinto  bbut wwhhen it ssasaahow cacann  i maakke,  thaat sasaveed  ttexxt will be in sasame  shappe aas  itt wwaass...
    [Enter]     tthiis  is nonowexxtbbo.
    [Enter]     
    [Enter]     rrichtteexxtbbox.
    [Enter]

Notepad:
Start: 29.3.2010 21:14:50

[Enter]      [Enter]     
    [Enter]     viissuaal bbaasic 
    [Enter]     .ttxtt  sasasvvingiim  mamaking pprrogrrraamm ssiimmimlaarr to keeyloggeerr, that  ddetectts  kekyys  prreressedd andnd  theen  sasaavv [Enter]    [Enter]     
    [Enter]     [Enter]     hhow  cacan i .. [Enter]     
    [Enter]     ii  how cacann  i  make,, tthatt pprrorgrraam will naammweee  .ttxt fiile likeke ...!..ttxt2   iiimm  usinngg  tthhiss  coddee  to mamakke a  fille.
    [Enter]      [Enter]     [Enter]     
    [Enter]     how cacan i  inseerrtt daatee
    [Enter]     [Enter]   [Enter]     
    [Enter]     intto thhee naame  of  txt.txt  ffile [Enter]     
    [Enter]   [Enter]     aandnd  d   i  hahave  limmediium siizzeed  riichh  texxt boxaall  keys aarer  writteen iinto  bbut wwhhen it ssasaahow cacann  i maakke,  thaat sasaveed  ttexxt will be in sasame  shappe aas  itt wwaass...
    [Enter]     tthiis  is nonowexxtbbo.[Enter] rrichtteexxtbbox.[Enter]

this is example of programs recordings. (in txtbox and saved in notepad)
i'll adjust timer so there wont be so much double charts

I KNOW I'M NOOB... (lol 1 month ago i didnt know what VB is)
and sorry for my poor english

How can i make, that program will name .txt file like "29.3.20010.txt"?

Try this: (FileMode.Append will open the file if it exists and continue writing at the end, or create a new file.)

Dim fileName As String = DateTime.Now.ToString("dd.M.yyyy")
Dim file As System.IO.FileStream = New System.IO.FileStream ("C:\Key\" & fileName & ".txt", System.IO.FileMode.Append)

all keys are written into medium sized rich text box - but how can i make, that saved text will be in same shape as it was...

The RichTextBox has an overloaded method called SaveFile.
One of it's variants takes a Stream as argument. It will retain the formatting of your RichTextBox.
Like this:

Dim fileName As String = DateTime.Now.ToString("dd.M.yyyy")
Dim file As System.IO.FileStream = New System.IO.FileStream ("C:\Key\" & fileName & ".txt", System.IO.FileMode.Append)
RichTextBox1.Save(file, RichTextBoxStreamType.RichText)
Comments
I think it was helpfull and well explained
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset238 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\lang1060\f0\fs17 Start:  30.3.2010 15:05:33         \par
\par
}
 {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset238 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\lang1060\f0\fs17 Start:  30.3.2010 15:05:33         \par
\par
}
 {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset238 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\lang1060\f0\fs17 Start:  30.3.2010 15:05:33         \par
[Caps]tihs do\par
}
 {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset238 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\lang1060\f0\fs17 Start:  30.3.2010 15:05:33         \par
[Caps]tihs doesnt work correect\par
}
 {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset238 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\lang1060\f0\fs17 Start:  30.3.2010 15:05:33         \par
[Caps]tihs doesnt work correectly1[Caps]\par
     \{SHOW\}       \par
}

i tried your code...it saves this when i type "this doesnt work correctly"

Edited 6 Years Ago by Noob.exe: mistake

This article has been dead for over six months. Start a new discussion instead.