WScript Object

Unable to access

I am not all that experienced with VBScript, so sorry if this is a dumb question.

I have a DX script that accesses the WScript COM object directly (if "directly" is the right word) instead of through the CreateObject function. When I try to run the script, DesktopX gives me the error, "Object required: wscript". Here's an example of what I'm doing:

If wscript.arguments.count=0 Then msgbox "Drop files on me to extract the icons."

I've seen other users use WScript like that (while I was searching the forums to solve my problem :P), but apparently it isn't working for me.

Ultimately, I am trying to extract an icon from an EXE/DLL/any PE file using a script I found from http://gilpin.us/IconSiphon/. I copied and pasted the code from the .vbs file into my object's script editor, but I get that "object required" error. Possibly copying/pasting is the problem? Do I have to run the script in some other way, like right from the file? After looking at MSDN for WScript, it seems like it has to do with the file itself.

Any ideas why WScript isn't working would be appreciated.

Thanks,
Electo
6,437 views 12 replies
Reply #1 Top
WScript is better suited for regular vbscript/jscript files, not to mention that that DesktopX has it's own callback "Sub Object_OnDropFiles (files)".

If you post the script I can help you convert it over.
Reply #2 Top
Thanks, SirSmiley.

You can find the script at the website that I wrote in the original post:

http://gilpin.us/IconSiphon/

not to mention that that DesktopX has it's own callback "Sub Object_OnDropFiles (files)".


I realize that, but it doesn't work very well using that by itself. If you want to move the object so it is aligned with other icons inside the background, the label doesn't even move with it. Plus, you can't change the label without going into the Object Properties window. I was looking for a way to easily drag programs into the list (as a client) while arranging them at the same time.
Reply #3 Top
I'll have a look at this tomorrow. The label thing is one of my peeves. The work-a-round I use is to clone text objects and position them relative to the icon.

To position the shortcuts you could use a grid function. Every time you add a shortcut, basically this would check that the icon doesn't go past the edge.
Reply #4 Top
The work-a-round I use is to clone text objects and position them relative to the icon.

Does this mean that you somehow got rid of the icon label through script? If I could know how to do that, I'd be able to figure it out from there. I've already written a script to arrange text shortcuts, but I want to retain the shortcut's icon as well.
Reply #5 Top
No, I don't use the label and the base container is just a plain layer with no drag and drop. You let scripting do the rest.

There are two examples. One single and the second will clone shortcuts in a grid when they are dropped on the base container. There's an issue with folders in the second one.
See the screenshot below.

http://www.box.net/shared/0x8i9wj4sw

Reply #6 Top
Wow... I'm really stupid :P. I didn't realize that the actual icon extraction occurred in its own function.

Thanks, SirSmiley. I appreciate your time. I probably would have just thrown away the icon extraction idea. I should be able to incorporate it into my own theme now.
Reply #7 Top
Don't feel to bad I didn't figure that out until I was searching to solve the folder icon issue. Most likely to resolve that you need to add in a line to update the object picture at one of the exit statements.
Reply #8 Top
until I was searching to solve the folder icon issue.


Have you got a positive results with this?

I think it would be great to get folder icon (and any other that you need) directly from shell32.dll. It seems this code should work but I have no free time to check up this idea.

May be you know more easy way than dll parsing?
Reply #9 Top
The script actually seems a bit flaky... I get an error message for about every other file I try to add to my list. Maybe it's just the way that I'm implementing the script. And it also doesn't check the format of .EXE files because I tried to import the .EXE I made in assembly (does not have PE headers and such) and it throws an error about reaching the end of the file (it's an extremely simple program).

Unless I'm able to solve all these bugs before I get bored of it (I give up easily :)), I might just have to scrap the idea of the icons...

May be you know more easy way than dll parsing?

I searched quite a while for a method to get a file's icon in VBScript, and this script is all I came up with, though there might be another method that I didn't find.

Actually, if you're asking for an easier way to get just the folder icon, I'd think you could just extract the icon from shell32.dll yourself with a program like Resource Hacker and then use that .ico file.
Reply #10 Top
I actually looked at shell32.dll in Resource Hacker, and the folder icons are listed under "Icons" and they are numbers 16 - 37. Each icon size/format has a different icon number. You probably actually want the icons 23-26, though (they are 32-bit closed folders)
Reply #11 Top
Resource Hacker is the impossible way for me because I need some completed code which must be included into the main script to create shortcuts (with extracted icons) not only for files but for folders too.

Ok. One day I'll find free time and make this code. Hope this will be much soon.  ;) 
Reply #12 Top
It does pull the folder icon out of the shell32.dll.

I noticed some errors but, have been using it mostly with shortcuts and it seems to work most of the time. Noticed the issue with exe's. Older conventional app's it works fine.

Somewhere in my codebase is another icon script but, I'm positive it's just for standard shell icons. It's obviously not simple because even a regular DX container doesn't get all the icons.