Solved

How to find the class id of an arbitrary object?  Example:Set x = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

Posted on 2016-08-04
10
74 Views
Last Modified: 2016-08-27
Please, do not post tangents about whether today's goal is good, bad, fast, slow, brilliant or stupid.  I already had a bunch of those tangents here.  Strangely enough, that long winded discussion never mentioned createobject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")  which I now believe might be a very useful construction.

My goal is to make vba code more portable by switching from early binding to late binding. I wanted to do this for ARBITRARY object types while keeping the object's methods and properties unchanged.  

For instance let us say I want to switch the following code to late binding.

Dim x as dataobject ' reference to ms forms 2.0 object library  which on my machine is c:\windows\syswow64\fm20.dll
set x = new dataobject

I accidentally found a webpage that showed the following alternative.
   dim x as object
  Set x = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

How can intentionally find similar classids? For instance, can I transform the following
    dim x as new SHDocVw.ShellWindows
0
Comment
Question by:rberke
  • 4
  • 3
10 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 300 total points (awarded by participants)
ID: 41743223
You can search in the registry below HKCR\CLSID for the value containing your class name to replace.
0
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 200 total points (awarded by participants)
ID: 41743364
I added the "Microsoft Internet Controls" as the fifth Reference in my VB(A)Project.

In the "Immediate" Window:

?ThisWorkbook.VBProject.References(5).Guid
{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}
0
 
LVL 5

Author Comment

by:rberke
ID: 41743383
I'll be a son of a gun -- that was really easy !!
 
To replace MSForms.dataobject I search for "dataobject" and found just what I needed:

HKEY_CLASSES_ROOT\CLSID\{1C3B4210-F441-11CE-B9EA-00AA006B1A69}\InprocServer32
        Class   Reg_SZ   Microsoft.Vbe.Interop.Forms.DataObjectClass

Next, I wanted to replace < set x =  New SHDocVw.ShellWindows > so I searched for "ShellWindows"

HKEY_CLASSES_ROOT\CLSID\{9BA05972-F6A8-11CF-A442-00A0C90A8F39
     (default)  REG_SZ   Shellwindows
     Appid      Reg_SZ   {9BA05972-F6A8-11CF-A442-00A0C90A8F39}

That actually worked in the following

Sub ShowIE()
Dim shellWins As Object, explorer As Object '  SHDocVw.ShellWindows & SHDocVw.InternetExplorer
    Set shellWins = CreateObject("New:{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")
    For Each explorer In shellWins
        Debug.Print explorer.LocationURL
    Next
End Sub

Open in new window

But, I still have one more question.  What if I had been try to replace   MsForms.Page?  Search for "Page" gives me a dozen false positives before I finally got to
      Class   Reg_SZ   Microsoft.Vbe.Interop.Forms.PageClass

I recognized that as the correct key because I had previously seen the same structure for the DataObject.  That is cheating, I want a methodology that finds an arbitrary object (without relying on previous success searching for a similar object).

Is there some methodology that will quickly get to the correct classId having just the library.class (E.G. SHDocVw.ShellWindows )?
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41743403
Sorry, but I don't think you will succeed in that. Some classes are translated into something more easily to use. "MsForms.Page" certainly is a VB alias for "Microsoft.Vbe.Interop.Forms.PageClass".
But in general, the classes are following the same scheme. "MsForms" translates to "Microsoft.Vbe.Interop.Forms" - always.
"Excel.Application" is a COM reference, and as such has an entry below HKCR\Excel.Application with CLSID pointing to HKCR\CLSID, and that again contains the real class name "Microsoft.Office.Interop.Excel.ApplicationClass". This shows the complexity of your request.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 5

Author Comment

by:rberke
ID: 41743430
I am still making more progress than I expected.  I will leave this question open for while, just in case someone has a better idea.  Then I will award you points.  

Thanks for you help.

rberke
0
 
LVL 5

Author Comment

by:rberke
ID: 41743468
To replace  set  var = new xxxxx.yyyy
With  Set var = CreateObject("new:{3F4DACA4-160D-11D2-A8E9-00104B365C9F}")

You must first find the “magic numbers”. The following procedure seems to work pretty well.
Open Notepad to be used as workspace.

Open regedit and manuver to HKEY_CLASSES_ROOT\CLSID\
Ctrl f to find in yyyyy.  (remove the checkbox next to Keys and Values, and keep Data)

Edit > Copy Key Name > then paste into notepad.
Edit > Modify > Ctrl C > then paste into notepad. The first entry might look like this
    HKEY_CLASSES_ROOT\CLSID\{1C3B4210-F441-11CE-B9EA-00AA006B1A69}\InprocServer32
    Class REG_SZ Microsoft.Vbe.Interop.Forms.DataObjectClass

Use F3 to repeat the find and record the next occurances of yyyyy.
If the search “hangs” for over a minute, you are done.
You are also done if the key name does not start with HKEY_CLASSES_ROOT\CLSID

For instance yyyyy = “InternetExplorer” might look like this
HKEY_CLASSES_ROOT\CLSID\{0002DF01-0000-0000-C000-000000000046}\ProgID
InternetExplorer.Application.1
HKEY_CLASSES_ROOT\CLSID\{0002DF01-0000-0000-C000-000000000046}\VersionIndependentProgID
InternetExplorer.Application

Summarize all the class ids and ignore duplicates.  
Eliminate incorrect class ids using code like this.

Sub test711()
On Error Resume Next
Dim x1 As SHDocVw.InternetExplorer ' your original early binding class
Dim x2 As Object
Dim x3 As Object
Set x2 = CreateObject("new:{0002DF01-0000-0000-C000-000000000046}") ' possible replacement
Set x3 = CreateObject("new:{xxxxxxx.....xxxx}") ' another possible replacement

Debug.Print TypeName(x1) & vbCrLf & TypeName(x2) & vbCrLf & TypeName(x3)

End Sub
0
 
LVL 5

Author Comment

by:rberke
ID: 41763088
I still believe there might be a more general answer and (when I have time) I am going to open a new question to pursue a general resolution to my question.
For instance, I am very intrigued by Fanpage's code which shows the GuiId associated with a referenced library.    Perhaps there is some way of diving lower into the reference and pull out all class names and their associated clsid?

But, for right now, I agree the question should be closed.

Qlemo should get best answer

300 Points should go to Qlemo, and 200 to Fanpages.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41765117
OP stated a different point distribution, so stopping the closing process.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now