How to get a icon from a Program running!
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
8 posts
Page 1 of 1
First you will need:
1 button
1 textbox
1 picturebox
The next 2 code boxes are for creating varibles for the button click event and what will happen when button 1 is clicked.
Now for the button1 click event code.
picturebox1 = picture you get
button1 = starts process of getting icon from
NOTE: THIS DOES NOT SAVE THE PICTURE!
but i am sure you can figure out yourself, because that code is pretty easy.
have fun with it!
1 button
1 textbox
1 picturebox
The next 2 code boxes are for creating varibles for the button click event and what will happen when button 1 is clicked.
Code: Select all
Sub GetFileIcon(ByVal Path As String)
Try
If Path.ToLower.EndsWith(".jpg") Or Path.ToLower.EndsWith(".bmp") Or Path.ToLower.EndsWith(".gif") Or Path.ToLower.EndsWith(".png") Then Image.FromFile(Path)
PictureBox1.Image = Drawing.Icon.ExtractAssociatedIcon(Path).ToBitmap()
Catch
End Try
Code: Select all
Just put both of the code boxes anywhere before the button1 click event.Public Function GetProcessPath(ByVal prc As Process) As String
Dim query As String = String.Format("select * from Win32_Process where name='{0}.exe'", prc.ProcessName)
Dim searcher As New ManagementObjectSearcher("root\CIMV2", query)
Dim result = searcher.Get().GetEnumerator()
If Not result.MoveNext() Then Throw New ArgumentException("Process not found")
Return CStr(result.Current("ExecutablePath"))
End Function
Now for the button1 click event code.
Code: Select all
textbox1 = process you want to get icon fromDim proc As Process() = Process.GetProcessesByName(TextBox1.Text)
GetFileIcon(GetProcessPath(proc(0)))
picturebox1 = picture you get
button1 = starts process of getting icon from
NOTE: THIS DOES NOT SAVE THE PICTURE!
but i am sure you can figure out yourself, because that code is pretty easy.
have fun with it!
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
Proprogrammer, not just a Programmer.
yet another piece of code i never seen before.Thanks
Good Job Proprogrammer
Good Job Proprogrammer
You can find me on Facebook or on Skype mihai_92b
I'd make it so all open window icons can be displayed and saved.
Updates:
14/11/10 Fixed a possible filename bug, added better filetype save support.
21/11/10 Better memory managment for the icons
Updates:
14/11/10 Fixed a possible filename bug, added better filetype save support.
21/11/10 Better memory managment for the icons
You do not have the required permissions to view the files attached to this post.
Last edited by mandai on Thu Mar 22, 2012 5:27 pm, edited 5 times in total.
Pretty cool!
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
Proprogrammer, not just a Programmer.
I'm getting an IndexOutOfRangeException Error.
ooh i just got an idea for a program :P
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

ok i just tried this and there is an error in this code
Code: Select all
Dim searcher As New ManagementObjectSearcher("root\CIMV2", query)
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023