1

Is there a way to get CreateOleObject to work in a Delphi Form Application? I know it requires ComObj, which I'm guessing might mean it is Console Application use only. If I cannot use it in form applications, is there an alternative I can use?

To give context, I am trying to get the HWID of a computer for identification reasons. According to a guide (That uses Console), I need to do the following:

objSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
objWMIService   := objSWbemLocator.ConnectServer('localhost','root\cimv2', '','');

That is fine in Console, but I need to work with forms so it will be more easily accessible to my users.

So to reiterate; is there a way to implement this in a non-console application? If not, are there alternatives?

user1937198
  • 4,987
  • 4
  • 20
  • 31
ozdrgnaDiies
  • 1,909
  • 1
  • 19
  • 34

1 Answers1

1

CreateOleObject works just fine from forms applications. This is a non-problem.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I guess there must be something wrong with my library setup then. ComObj shows an error on Form applications for some reason. Sorry for the post. – ozdrgnaDiies Jan 03 '12 at 11:43
  • If you show us all your code and tell us exactly what the error is I'm sure we can help identify what the real problem is. – David Heffernan Jan 03 '12 at 11:45
  • I think I found the problem. I do in-fact have the ComObj library and it is being used, but for some reason my ComObj library has all the normal functions except `CreateOleObject`. It must be my version or something, but it's weird to have only that one function missing. – ozdrgnaDiies Jan 03 '12 at 11:55
  • 1
    ComObj is part of the product. You shouldn't be modifying it. – David Heffernan Jan 03 '12 at 11:57
  • @ozdrgnaDiies, you should employ $include file rather than modifying units directly for portability reasons. – OnTheFly Jan 03 '12 at 18:02