Friday, 16 January 2009

Save Skype chat history


Tonight I want to present my first VBScript. Before having lunch, I had some free time, so I surfed the net, when bumped into the developer section at I remembered, my every OS-reinstall destroyed Skype chat history. But to be honest, the default format of the history filer is very messy, so it is difficult to read. I decided to delve into the SkypeAPI technology and it turned out that making simple scripts is so easy. You can use PHP, JavaSctipt, JScript, Java and VBScript. I choose the last one, because it seemed to be the most easy to run in Windows. You just put in a file with vbs extension, and run. So here is the code I wrote, I'll tell how it works soon:
' Define global variables
Dim oFSO, chat_file, folder_to_save
' Directory where You want to save history (you can modify it)
' Now it is relative, so it will be created where Your *.vbs script runs
folder_to_save = "SkypeChatHistory"
line_count = 0

' Create FSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Connect to Skype API via COM
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
' Open skype, if it is not running
If Not oSkype.Client.IsRunning Then
End If

WScript.Echo "Skype history will be saved. Found " & oSkype.Chats.Count & " chat group."

' Iterate chats
For Each oChat In oSkype.Chats
names = ""
' First name is You, so it is unnecessary to keep
no_1st_flag = TRUE
For Each oUser In oChat.Members
If no_1st_flag Then
no_1st_flag = FALSE
   names = names & "_" & oUser.FullName
End If
get_file("chat" & names & ".txt")
chat_file.WriteLine(vbNewLine & "==== CHAT HISTORY (" & Replace(names, "_", "") & ") ====" & vbNewLine)
line_count = line_count + oChat.Messages.Count
' Fix by an anonymous commenter
If oChat.Messages.Count > 0 Then
For Each oMsg In oChat.Messages
' Fix by Vadim Kravchenko
On Error Resume Next
chat_file.WriteLine(oMsg.FromDisplayName & " (" & oMsg.Timestamp & "): " & oMsg.Body)
End If

WScript.Echo "Backup was finished (" & line_count & " line saved). You can find your chats in: ./" & folder_to_save

' Garbage collection
SET chat_file = NOTHING
SET folder_to_save = NOTHING

' Access to a file given by name
Sub get_file(file_name)
' Parameter fix by: rommeech
Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True, -1)
End Sub

' Find an appropriate directory the logs to save, however, to avoid collision with former dirs
Sub set_next_free_dir()
If oFSO.FolderExists(folder_to_save) Then
ext = 1
While oFSO.FolderExists(folder_to_save & "_" & ext) And ext < 100
  ext = ext + 1
folder_to_save = folder_to_save & "_" & ext
End If
End Sub

Save it to your Desktop (*.vbs), and double click on it. At the first time, Skype will ask you, whether you are aware of the security issues, and really want to add permission to connect the SkypeAPI ... if you trust me, just click OK. It will creates a folder called SkypeChatHistory and some files in it. Every filename consists the other member of the chat sessions, so, if you talked 3 times with your friend, John Doe, there will be a 'chat_John Doe.txt' in SkypeChatHistory with 3 conversation in it. If you are keen-eyed, you will notice conversation lines are in reversed order. --homework-- :)
Now, I think, this code is quiet enough to save messages, and learn from it the way it works. If you can write a really small function to invert the collection (oChat.Messages), please comment it, and I will extend the code. Perhaps I make a gui for it with Visual Studio, I don't know. It must be dozen of good Skype backup applications already.

Update: eigenein did a fantastic job making a Windows application for the same purposes:

Sleep well!


  1. It doesn't work to me. Restores just 3 files and makes error
    line 37
    char 3
    error: Invalid procedure call or agrument
    code 800A0005

  2. Hi,

    Unfortunately I'm not a VB programmer, I don't know VB at all. The problem, I guess, the type conversion at line 39:

    chat_file.WriteLine(oMsg.FromDisplayName & " (" & oMsg.Timestamp & "): " & oMsg.Body)

    Target: oMsg.Body. oMsg is an IMessage object. It has a property, called Body contains the body of the chat message. However, it could be several types of messages, like status information, file sending, joins, quits... I tried to cast it (CStr()), but it didn't help at all, neither checking whether it is empty or null or anything. Maybe if it gets the type of the message could solve the problem but I didn't have much time for this. Although, if you solve it, I add your name and snippet to the post:) Some info:
    oMsg.Type contains the type of the message. The types:

    cmeUnknown Unknown message type.
    cmeCreatedChatWith Chat created.
    cmeSawMembers Saw chat members.
    cmeAddedMembers Added chat members.
    cmeSetTopic Chat topic changed.
    cmeSaid Sent message.
    cmeLeft Left the chat.
    cmeEmoted Sent emoted message.
    cmePostedContacts Posted contacts.
    cmeGapInChat Indicates gap in chat.
    cmeSetRole Member role changed.
    cmeKicked Member kicked from chat.
    cmeSetOptions Chat options changed.
    cmeKickBanned Member kicked and banned from chat.
    cmeJoinedAsApplicant Member joined as applicant.
    cmeSetPicture Chat picture changed.
    cmeSetGuidelines Chat guidelines changed.

    Anyway, thank you for reporting the bug! When I wrote the code, it worked, but now I get the same error message.


  3. Peter, you are AWESOME!

    I just downloaded Skype v4.1.0.141 and your VBS code WORKS FLAWLESSLY! A directory called "SkypeChatHistory" is created with a text file "chat_.txt". As you had mentioned, the chat order will be "in reverse" (which is fine for me).

    If there are problems, it could be that the code from this blogspot website does not format correctly when copied. I had to copy-paste this code into WORDpad and THEN copy-paste that code into a NOTEpad text file. Then, I renamed the TXT extension into VBS.

    Keep up the good work.. peace, my brother!

    Tariq Rana - USA

  4. Greet Job..

    Can u give me suggestion how to run your vb script file in button click event in html.I don't know vb script.


  5. When running I receive the following error message from Windows Script Host:
    Script: C:\...
    Line: 34
    Char: 2
    Error: Invalide procedure call argument
    Code: 800A0005
    Source: Microsoft VBScript runtime error

  6. Hi,

    Great thanks to Vadim Kravchenko for his fix. oMsg.Type unable to handle file transfer annotation, so as quick fix it's better to step through in that cases. Thanks again.
    (Unfortunately I can't test it on a Windows machine, so I hope I insert the snippet at the right place).


  7. Excellent work!

    Works just FINE!

  8. Copied the code into Notepad, copied and pasted the code into it and saved it as a vbs extension. Works excellent... Thanks!!

  9. Excellent work Peter!
    I re-installed my OS, and spent ages trying to put the chat history back.
    With your little bit of code, at least now I can reference my chat history again.
    Thanks heaps! Mark

  10. Thank you so much!!! I spent 3 hours on the net looking for a tool like yours.
    Just a thing: you need the extra stuff when you install skype on your computer (in order to use the Skype4COM dll in your code). I had to install a new version of skype to get it.

  11. works great!! Cheers mate!
    I just copy and pasted straight into notepad and saved as vbs file - and it worked :)

  12. I'm having a problem identifying which part of the code selects which chats to save, the one chat which I need to export on a regular basis to a text file is not exporting. Otherwise great piece of code!

  13. Hello, I'm using Win 7, and it doesnt worked for me, because, it found an error in 34. lime:

    chat_file.WriteLine(vbNewLine & "==== CHAT HYSTORY (" & Replace(names, "_", "") & ") ====" & vbNewLine)

    I dont know what is the problem :S please help !

  14. thanks. works great! this is what i need.

  15. Try to replace following subroutine as shown:

    Sub get_file(file_name)
    file_name = Replace(file_name, "/", "-")
    Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True)
    End Sub

  16. For fixing error in line 34 you can replace line 54 from

    Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True)


    Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True, -1)

    And your files will be saved in UTF-8

  17. The fix is in the code, thanks rommeech ;)

  18. I get an error saying:

    line: 13
    char: 1
    error: could not create object named "Skype4COM.Skype"
    source: WScript.CreateObject

    my computer runs windows 7, i don't know if that's important..

  19. Great stuff, thanks! Windows 7 Home Premium 64bit, saved as a .vbs file and it just worked, lovely :)

    Oh yeah, and it's Skype Beta

    Little typo correction:
    Line 34 Col 45: change the Y to an I to read "HISTORY", instead of "HYSTORY" ;)

  20. Typo fixed, thanks Luke ;)

  21. Hi, thanks v.much worked well - phil

  22. Thank you very much!
    Could you give me a hint on how to extract chats from backed up files of a previous OS (WinXP)? Thanks

  23. Do I just copy the code and save it as a vbs file with wordpad?

  24. Hello,
    thanks for your work but i also cant run the script (windows 7 64 bit)

    error says: Line 13
    couldnt create the object "Skype4COM.Skype"
    Source: WScript.CreateObject

    any help ?

  25. i have an error on line 55 char 1

    i dont know much about scripts, but i will try to solve this. i just want to let you know though.

  26. Thank you very very very much!!!!
    It work perfect in WinXP with Skype

  27. I receive the error that line 1 char 1 is an invalid character.
    Code 800A0408

  28. Thanks Itarato, great simple program. Few people have actually written something like this.

    Those of you getting this error:
    error says: Line 13 couldnt create the object "Skype4COM.Skype"
    I'm guessing that you either didn't install the Extras Manager when you installed Skype, or you're not logged into Skype when you run the VBS script.

    By the way, for those with access to a Unix command line, there's always the "tac" command to reverse the lines in the files.

  29. Hi, your script is cool, however, you have a problem in line 36. When oChat.Messagex.Count is equal to zero, the loop will cause a runtime error. The situation is not very probable, because you'll have to have at least one contact with no converstations at all. The modification is as follows:

    If oChat.Messages.Count > 0 Then
    For Each oMsg In oChat.Messages
    ' Fix by Vadim Kravchenko
    On Error Resume Next
    chat_file.WriteLine(oMsg.FromDisplayName & " (" & oMsg.Timestamp & "): " & oMsg.Body)
    End If

    It would be nice if you could include it in your original post, Peter.

  30. Fix is added, great thanks :)

  31. Simkl IM Chat & Voice Recorder will help you record all Skype conversations automatically including Text and Voice conversations. The program will also store these conversations online for easy access through website.

  32. Thank you for posting this code, I have written a C# .NET app based on your idea:


  33. great piece of code!
    worked fine for me!

  34. Can you please update it for Skype 5 as it is saying that 'Could not locate automation class named "Skype4COM.Skype"'

    I've Skype 5 installed.

  35. Brilliant, thank you, it worked a treat :-)

  36. perfect work, it's so easy, you have prepared it just to put and launch. thanks!

  37. Works fine. Thank you so much!

  38. Can you please update it for Skype 5.5 as it is saying that 'Could not locate automation class named "Skype4COM.Skype"'

  39. Thank you! I was inspired and have done this:

  40. Hi eigenein,

    That's great, I'm glad I could help:) I put the link into the blog so other people can find it.

  41. Please give us a new code--new Skype does not have Extras Manager!

    Thanks :)

  42. This comment has been removed by the author.

  43. Having same problem as others in Win 7, 64 bit.

    In a dialog box titled, "Windows Script Host" the message contents are:

    Script: ...\chatHistSave.vbs
    Line: 13
    Char: 1
    Error: Could not create object named "Skype4COM.Skype".
    Code: 80040154
    Source: WScript.CreateObject

    Anyone have a fix for this yet?

  44. thanx for info, but as for me, i usually record skype calls using this tool, it's simple and nice!)

  45. thanks a lot
    worked with Win7 and Skype
    (saved 1548 chat groups)

  46. Thanks a lot for the script. It seems to work on Skype 5.10. on my Win7 64bit (with a little tweak)

    A note for 64bit Vista/7 users:
    The script won't run by itself out of the box because "Currently it's been decided that it's by design that Skype4COM works only for 32bit applications on 64bit OS."

    That said, you can still run it with the 32bit version of cscript.exe in the following way:

    \Windows\SysWOW64\cscript.exe SkypeLogDump.vbs

    You could make a .bat file with that command to retain it's "click & go" functionality...

  47. Thanks for the script Peter, it works good in the Skype version 6.0.0 with the workaround proposed by IceDragon.
    Only for some chats cant collect the name of the other person, but thats minor :) and i pass well without that :D

  48. My Windows is x64 and Skype

    I used the command "\Windows\SysWOW64\cscript.exe SkypeLogDump.vbs" and WORKS GREAT !!!

    THANKS !!!

  49. Great Job Bro..

    Thanks a lot..


Note: only a member of this blog may post a comment.