Icon Ripper

Post your questions regarding programming in Visual Basic 6 in here.
13 posts Page 1 of 2
Contributors
User avatar
bjm0008
Dedicated Member
Dedicated Member
Posts: 69
Joined: Thu Aug 13, 2009 2:35 am

Icon Ripper
bjm0008
Hey I recently Decided to create an application that extracts or "rips" the .ico file from a .exe file. the entire code is here :
Code: Select all
Public Class Form1

    Private Sub RIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RIP.Click
        Dim ricon As Icon = Icon.ExtractAssociatedIcon(TextBox1.Text)
        PictureBox1.BackgroundImage = ricon.ToBitmap
    End Sub

    Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
        Using ofd As New OpenFileDialog
            ofd.Filter = ".exe (*exe*)|*.exe*"
            ofd.Title = "Select File"
            If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                TextBox1.Text = ofd.FileName
            End If
        End Using
    End Sub

    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
        Dim savefiledialog1 As New SaveFileDialog
        Try
            savefiledialog1.Title = "Save File"
            savefiledialog1.FileName = "*.ico"
            savefiledialog1.Filter = "Icon |*.ico"
            If savefiledialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Icon)
            End If
        Catch ex As Exception
            'Do Nothing
        End Try
    End Sub
End Class
:shock:

Contains:
3 buttons Save, Browse, Rip.
1 Textbox
1 Savefiledialog
1 Openfiledialog
2 Labels
1 Picturebox (32 pixles by 32 pixels, Default Icon size.)

Picture:http://s1003.photobucket.com/albums/af1 ... g&newest=1

Sadly, when I choose a the location to save the icon file to and click save the file isn't there. Vb 2008 doesn't detect any errors so can somebody test this for me and find out the issue with the save-button.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: Icon Ripper
CodenStuff
Hello bjm0008,

Nice application your building. Ive never tried to save an image as an *.ico file before using VB so I dont know exactly how its done. Ive done some research and this is the simplest way I could do it, the only issue is that it saves them in 16-colors.

The reason why your application wasnt saving anything was because in the RIP_click sub you set the image to the picturebox's background, you need to set it to Picturebox1.Image instead.

Here is the code I came up with and I hope it helps you in some way:
Code: Select all
Imports System.drawing
Imports System.IO

Public Class Form1
   
    Private Sub RIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RIP.Click
        Dim ricon As Icon = Drawing.Icon.ExtractAssociatedIcon(TextBox1.Text)
        PictureBox1.Image = ricon.ToBitmap
    End Sub

    Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
        Using ofd As New OpenFileDialog
            ofd.Filter = ".exe (*exe*)|*.exe*"
            ofd.Title = "Select File"
            If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                TextBox1.Text = ofd.FileName
            End If
        End Using
    End Sub

    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
        Try
            SaveFileDialog1.Title = "Save File"
            SaveFileDialog1.FileName = "*.ico"
            SaveFileDialog1.Filter = "Icon |*.ico"
            If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim Newico As New Bitmap(PictureBox1.Width, PictureBox1.Height)
                Dim ico As Graphics = Graphics.FromImage(Newico)
                ico.DrawImage(PictureBox1.Image, 0, 0, PictureBox1.Width, PictureBox1.Height)
                Dim SaveIcon As Icon = System.Drawing.Icon.ExtractAssociatedIcon(TextBox1.Text)
                SaveIcon.Save(New FileStream(SaveFileDialog1.FileName, FileMode.Create))
            End If
        Catch ex As Exception
            MsgBox("Error while saving!")
        End Try
    End Sub
End Class
Good luck! :)
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
bjm0008
Dedicated Member
Dedicated Member
Posts: 69
Joined: Thu Aug 13, 2009 2:35 am

Re: Icon Ripper
bjm0008
Thanks for the reply I tried the code and it works perfectly, well exept for the colors. I'm not so good with them anyways. Just post a reply if you get any more ideas.
Image
User avatar
bjm0008
Dedicated Member
Dedicated Member
Posts: 69
Joined: Thu Aug 13, 2009 2:35 am

Re: Icon Ripper
bjm0008
This was kinda fast but I think I've got it!

( I canched the browse butto so it automaticly puts the icon into the picturebox )
Code: Select all
Imports System.Drawing.Color
Imports System.Drawing
Imports System.IO

Public Class Form1

    Private Sub RIP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RIP.Click
        Dim ricon As Icon = Drawing.Icon.ExtractAssociatedIcon(TextBox1.Text)
        PictureBox1.Image = ricon.ToBitmap
    End Sub

    Private Sub Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Browse.Click
        Using ofd As New OpenFileDialog
            ofd.Filter = ".exe (*exe*)|*.exe*"
            ofd.Title = "Select File"
            If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
                TextBox1.Text = ofd.FileName
            End If
        End Using
    End Sub

    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
        Dim savedialog1 As New SaveFileDialog
        SaveFileDialog1.Filter = "Icon File (*.ico|*.ico |All Files | *.*"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Icon)
        End If
    End Sub
End Class

There is just one problem Visual Studio or even windows won't accept the .ico file.
If i named the .ico as icon1.ico it'll say "icon1.ico does not contain any icon files"
Image
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: Icon Ripper
CodenStuff
Hello,

Your rite the code you have does save the picturebox to an .ico file but for some reason VB doesnt save it with any icon format properties. What it actually does is save it in .png format, if you rename one of your saved icon files to say for example "icon1.png" then you will be able to view it inside an image viewer or VB.

The code I posted above saves the file with .ico format properties but its only 16-colors which isnt very good I know.

I would have thought it was simple to save a file as .ico but I guess its not :?
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: Icon Ripper
CodenStuff
Hello again,


I found this somewhere online (before my browser crashed). It lets you open a .BMP file and save it as a .ico file, seems to work pretty well. If you play about with it you should be able to change it so you can extract an icon from an .exe and save it to .ico.

This is the file:
IconEXSample.zip
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
bjm0008
Dedicated Member
Dedicated Member
Posts: 69
Joined: Thu Aug 13, 2009 2:35 am

Re: Icon Ripper
bjm0008
Thanks for the info.
Image
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: Icon Ripper
Martin
Looks Great
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: Icon Ripper
Nery
Seems good, its interesting how unprotected an EXE is :D

cooll;
User avatar
CodemaN
VIP Access - Denied
VIP Access - Denied
Posts: 74
Joined: Fri Sep 18, 2009 3:18 pm

Re: Icon Ripper
CodemaN
cool man!!!!!! you are the best
13 posts Page 1 of 2
Return to “General coding help”