• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5657
  • Last Modified:

shell32.dll icon for HTA

I have looked pretty hard for this but just can't seem to find the answer i need.

All i want to do is use one of the icons in shell32.dll for my hta

Code snip:
-------------------------------------------------------------
<head>
     <title></title>
     <HTA:APPLICATION ID="oHTA"
     BORDER="thick"
     INNERBORDER="yes"
     SHOWINTASKBAR=yes
     SCROLL=Yes
     APPLICATIONNAME="HTA Verification"
     NAVIGABLE="yes"
     ICON="res://shell32.dll/2/230"
     >
</head>
-------------------------------------------------------------

The above "icon=" bit is what i thought might work.. but nope
0
pj_harro
Asked:
pj_harro
  • 8
  • 4
  • 3
  • +1
2 Solutions
 
merowingerCommented:
You cannot use the shell32 icons in hta, you have to deliver an own
0
 
pj_harroAuthor Commented:
you mean extract the icon as a .ico file and link that?
0
 
merowingerCommented:
yes use an own .ico file - exaclty
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
pj_harroAuthor Commented:
aw crap, i dont want to use another file. but if i cant then i cant.
0
 
TakedaTCommented:
You can extract the icons from most dll files using an app like this one.

http://www.online-tech-tips.com/free-software-downloads/how-to-extract-icons-from-exe-dll-ocx-and-cpl-files/

You can then try to imbed the icon into your hta file from a cmd prompt by doing the following.

type youricon.ico>newhta.hta
type yourhtafile.hta>>newhta.hta

I believe it only works well with icons with certain resolution, but you can give it a try.
0
 
TakedaTCommented:
Oh, and I forgot.  After you imbed the icon, you need to modify the hta code to reflect the imbeded icon like so.

<HTA:APPLICATION ID="oHTA"
    ICON="#"  
   >
0
 
pj_harroAuthor Commented:
Thanks TakedaT. I have used this method with other HTAs and it works well. Problem is i need to be able to read the HTA in question using another vbscript, and once it's embeded with an icon it doent read using readline method
0
 
TakedaTCommented:
Im not sure why it wouldnt work.  What problems were you running into?
0
 
jostranderCommented:
Here's a sample HTA that works for me in XP:
<html>

<script language="vbscript">
	
window.resizeTo 500,200
	

document.write "<HTA:APPLICATION" & vbCrLf & _
				"ID=""objTest""" & vbCrLf & _
				"ApplicationName=""Test"""	& vbCrLf & _
				"ICON=""res://shell32.dll/2/230""" & vbCrLf & _
				"/>"


</script>


<body>
This works in WinXP only.
<br><br>
Here is an image:
<br>
<img src="res://shell32.dll/2/130">
</body>

</html>

Open in new window

0
 
jostranderCommented:
Also, If you'd like to continue using the merged-icon method like TakedaT mentioned, this sample will read the file as Binary, get the text portion of it and then rewrite & merge with an icon you specify:


strOldHTA="old_hta_with_icon.hta"
strIconFile="c:\klingon.ico"
strNewHTA="c:\newhta.hta"
strTempHTA="c:\temp.hta"

Set WshShell=CreateObject("Wscript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject")

'Get binary data from the OLD HTA
bin=ReadBinaryFile(strOldHTA)

'Get the text portion of the HTA
text= BinaryToString(bin)

'Split text up to an array
arrText=split(text,vbCrLf)

'Create the new hta (temp)
Set oFile=fso.OpenTextFile(strTempHTA,2,true) 

'sample stuff... working with the file that was read
for each line in arrText
	If lcase(line)="</body>" then
		oFile.WriteLine "<br>Some stuff to add" & vbCrLf
	End If
	oFile.WriteLine line
next

'Close the new HTA
oFile.Close

'Merge the icon file to create the final HTA
MergeIcon "c:\klingon.ico",strTempHTA,strNewHTA

'Delete the Temp HTA
fso.DeleteFile(strTempHTA)

msgbox "Done",vbInformation,"Binary HTA Rewrite"


Sub MergeIcon(myIconFile,mySourceFile,myDestinationFile)
	WshShell.run "cmd /c copy /y /b " & Chr(34) & myIconFile & Chr(34) & "+" & _
		Chr(34) & mySourceFile & Chr(34) & " " & _
		Chr(34) & myDestinationFile & Chr(34),0,true
End Sub


'------------------------------------------------------------
'	Borrowed Functions
'	http://www.motobit.com/tips/detpg_read-write-binary-files/
'	http://www.motobit.com/tips/detpg_BinASP/
'------------------------------------------------------------

Function ReadBinaryFile(FileName)
  Const adTypeBinary = 1
  
  'Create Stream object
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  
  'Specify stream type - we want To get binary data.
  BinaryStream.Type = adTypeBinary
  
  'Open the stream
  BinaryStream.Open
  
  'Load the file data from disk To stream object
  BinaryStream.LoadFromFile FileName
  
  'Open the stream And get binary data from the object
  ReadBinaryFile = BinaryStream.Read
End Function

Function BinaryToString(Binary)
  Dim I, S
  For I = 1 To LenB(Binary)
    S = S & Chr(AscB(MidB(Binary, I, 1)))
  Next
  BinaryToString = S
End Function

Open in new window

0
 
pj_harroAuthor Commented:
Nice jostrander,

Check out this slightly modified version. Some odd stuff in that dll


<head>
     <title></title>
     <HTA:APPLICATION ID="oHTA"
     BORDER="thick"
     INNERBORDER="yes"
     SHOWINTASKBAR=yes
     SCROLL=Yes
     APPLICATIONNAME="HTA Verification"
     NAVIGABLE="yes"
     ICON="res://shell32.dll/2/230"
     >
</head>

<script language="vbscript">

For i = 1 to 500
     sHTML = sHTML & "(" & i & "):<img src=""res://shell32.dll/2/" & i & """> <BR>"
Next

Sub MyRun()
     document.getElementById("iconSpan").InnerHTML = sHTML
End Sub

</script>

<html>
<body>
<form name="frmMyForm">

<input class="input" type="button" value="Run" name="btnMyRun" onclick="MyRun">
<br>
<span id=iconSpan></span>

</body>
</html>

Open in new window

0
 
jostranderCommented:
I was so busy thinking of a workaround for the original issue, that I didn't even realize your example worked fine on my XP box, didn't even have to do the document.write...

I think the merged icon approach is probably best anyway... seems to work fine on my XP and Win7.

There certainly is a lot of stuff in that DLL.  Not sure if you've used it before or not, but Resource Hacker is a great tool for viewing/replacing resources in DLL/EXE files.
http://www.angusj.com/resourcehacker/

Joe
0
 
pj_harroAuthor Commented:
You are right.

This may seem odd, but the reason i didn't want to go for a merged icon is because my hta actually saves over itself.
1. It loads its own file into an array
2. changes some text
3. deletes itself (yeh it can)
4. writes a new "changed" version of itself

This all works fine untill i embed an icon into it, then I get "invalid procedure call or arguement" for my writeline into the new file, funny enough after this has failed the .hta is blank :)
0
 
pj_harroAuthor Commented:
Joe,

well there u go. I grabbed the binary stuff from your example above and now i can read in and change the merged icon hta.

Nice work :)
0
 
pj_harroAuthor Commented:
hmmm, on further investigation i am conderned with this:

"The behavior of the AscB function depends on the byte ordering of the hardware platform, and the number of bytes used to represent Unicode characters in the system software. The function will produce different results on each supported operating system. Use with caution. The described behavior pertains to the Win32 version."

Maybe i'll just bite-the-bullet and not worry about an icon.
0
 
jostranderCommented:
Sometimes I like to turn the sysmenu off, so I have no icon and then I add a button to the hta to close it.
0
 
pj_harroAuthor Commented:
Thanks for you help Joe.

I am splitting the poitns between merowinger and jostrander.

Merowinger answered my origianl question succinctly, but jostrander helped my understand it and gave me other options
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 8
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now