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 Skype.com. 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") set_next_free_dir() ' 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 oSkype.Client.Start() 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 Else names = names & "_" & oUser.FullName End If Next 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) Next End If chat_file.Close Next 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 SET oFSO = NOTHING SET oSkype = 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 Wend folder_to_save = folder_to_save & "_" & ext End If oFSO.CreateFolder(folder_to_save) 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: http://eigenein.github.com/skype-historian-website/
Sleep well!
Excellent work...
ReplyDeleteIt doesn't work to me. Restores just 3 files and makes error
ReplyDeleteline 37
char 3
error: Invalid procedure call or agrument
code 800A0005
Hi,
ReplyDeleteUnfortunately 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:
Enumerator:
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.
Cheers,
Peter
Peter, you are AWESOME!
ReplyDeleteI 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!
Sincerely,
Tariq Rana - USA
Greet Job..
ReplyDeleteCan u give me suggestion how to run your vb script file in button click event in html.I don't know vb script.
Thanks
Basanth.
alluribasanth@gmail.com
When running I receive the following error message from Windows Script Host:
ReplyDeleteScript: C:\...
Line: 34
Char: 2
Error: Invalide procedure call argument
Code: 800A0005
Source: Microsoft VBScript runtime error
Hi,
ReplyDeleteGreat 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).
Regards,
Peter
Excellent work!
ReplyDeleteWorks just FINE!
Copied the code into Notepad, copied and pasted the code into it and saved it as a vbs extension. Works excellent... Thanks!!
ReplyDeleteExcellent work Peter!
ReplyDeleteI 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
Thank you so much!!! I spent 3 hours on the net looking for a tool like yours.
ReplyDeleteJust 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.
works great!! Cheers mate!
ReplyDeleteI just copy and pasted straight into notepad and saved as vbs file - and it worked :)
You're a legend; Thank you!
ReplyDeleteI'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!
ReplyDeleteHello, I'm using Win 7, and it doesnt worked for me, because, it found an error in 34. lime:
ReplyDeletechat_file.WriteLine(vbNewLine & "==== CHAT HYSTORY (" & Replace(names, "_", "") & ") ====" & vbNewLine)
I dont know what is the problem :S please help !
thanks. works great! this is what i need.
ReplyDeleteTry to replace following subroutine as shown:
ReplyDeleteSub get_file(file_name)
file_name = Replace(file_name, "/", "-")
Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True)
End Sub
Thanks excellent
ReplyDeleteFor fixing error in line 34 you can replace line 54 from
ReplyDeleteSet chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True)
to:
Set chat_file = oFSO.OpenTextFile(folder_to_save & "/" & file_name, 8, True, -1)
And your files will be saved in UTF-8
The fix is in the code, thanks rommeech ;)
ReplyDeleteI get an error saying:
ReplyDeleteline: 13
char: 1
error: could not create object named "Skype4COM.Skype"
code:80040151
source: WScript.CreateObject
my computer runs windows 7, i don't know if that's important..
Great stuff, thanks! Windows 7 Home Premium 64bit, saved as a .vbs file and it just worked, lovely :)
ReplyDeleteOh yeah, and it's Skype Beta 5.0.0.105
Little typo correction:
Line 34 Col 45: change the Y to an I to read "HISTORY", instead of "HYSTORY" ;)
Typo fixed, thanks Luke ;)
ReplyDeleteHi, thanks v.much worked well - phil
ReplyDeleteGood work!
ReplyDeleteThank you very much!
ReplyDeleteCould you give me a hint on how to extract chats from backed up files of a previous OS (WinXP)? Thanks
Do I just copy the code and save it as a vbs file with wordpad?
ReplyDeleteHello,
ReplyDeletethanks 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 ?
i have an error on line 55 char 1
ReplyDeletei dont know much about scripts, but i will try to solve this. i just want to let you know though.
Thank you very very very much!!!!
ReplyDeleteIt work perfect in WinXP with Skype 4.2.0.169
I receive the error that line 1 char 1 is an invalid character.
ReplyDeleteCode 800A0408
Thanks Itarato, great simple program. Few people have actually written something like this.
ReplyDeleteThose 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.
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:
ReplyDeleteIf 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)
Next
End If
It would be nice if you could include it in your original post, Peter.
Fix is added, great thanks :)
ReplyDeleteSimkl IM Chat & Voice Recorder http://download.simkl.com 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 history.im website.
ReplyDeleteThank you for posting this code, I have written a C# .NET app based on your idea:
ReplyDeletehttp://www.gammatwo.com/2010/12/18/save-skype-chat-history/
Bye
great piece of code!
ReplyDeleteworked fine for me!
Can you please update it for Skype 5 as it is saying that 'Could not locate automation class named "Skype4COM.Skype"'
ReplyDeleteI've Skype 5 installed.
Brilliant, thank you, it worked a treat :-)
ReplyDeleteperfect work, it's so easy, you have prepared it just to put and launch. thanks!
ReplyDeleteWorks fine. Thank you so much!
ReplyDeleteCan you please update it for Skype 5.5 as it is saying that 'Could not locate automation class named "Skype4COM.Skype"'
ReplyDeleteThank you! I was inspired and have done this: http://eigenein.github.com/skype-historian-website/
ReplyDeleteHi eigenein,
ReplyDeleteThat's great, I'm glad I could help:) I put the link into the blog so other people can find it.
Please give us a new code--new Skype does not have Extras Manager!
ReplyDeleteThanks :)
This comment has been removed by the author.
ReplyDeleteHaving same problem as others in Win 7, 64 bit.
ReplyDeleteIn 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?
woWW.... :) Thanks Alot... :)
ReplyDeleteVow.. Thumbs Up.. :)
ReplyDeleteThanks a lot!
ReplyDeletethanx for info, but as for me, i usually record skype calls using this tool http://www.imcapture.com/IMCapture_for_Skype/, it's simple and nice!)
ReplyDeletethanks a lot
ReplyDeleteworked with Win7 and Skype 5.10.0.116
(saved 1548 chat groups)
Thanks a lot for the script. It seems to work on Skype 5.10. on my Win7 64bit (with a little tweak)
ReplyDeleteA 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."
[Source: https://jira.skype.com/browse/SPA-420?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel]
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...
Thanks for the script Peter, it works good in the Skype version 6.0.0 with the workaround proposed by IceDragon.
ReplyDeleteOnly for some chats cant collect the name of the other person, but thats minor :) and i pass well without that :D
My Windows is x64 and Skype 6.0.0.126
ReplyDeleteI used the command "\Windows\SysWOW64\cscript.exe SkypeLogDump.vbs" and WORKS GREAT !!!
THANKS !!!
Great Job Bro..
ReplyDeleteThanks a lot..