1

I've created a python COM class for the current user so it can be used without admin privileges. I've modified the python win32com.server.register module to create registry for the current user only instead of all.

The standalone script works fine and COM server gets registered successfully. Here is my script:

import pythoncom, win32com.server.register_current_user

class Python_For_VBS:
    _reg_progid_ = 'PythonForVBS.Utilities'
    _reg_clsid_ = pythoncom.CreateGuid()
    _reg_desc_ = "Python Test COM Server"
    _public_methods = ['HelloWorld']


def HelloWorld(self, item=None):
    return 'Hello World!'


if __name__ == '__main__':
    print('Registering COM server?quo')
    win32com.server.register_current_user.UseCommandLine(Python_For_VBS)

But the problem is, I'm not able to use this class with VB CreateObject().

Sub Python_Test

Dim PythonUtils
Dim response

Set PythonUtils = CreateObject("PythonForVBS.Utilities")
response = PythonUtils.HelloWorld()
MsgBox response

End Sub

Can VB only use classes defined for all users? If not, how can I use this class from within a VBScript?

EDIT:

I'm using Python 64-bit and I'm running this VBScript in QlikView. So it does not show any error but the script does not execute and the debugger points to the line which calls CreateObject() function, so I guess that is where the error is.

registry export from HKEY_CURRENT_USER\Software\Classes\PythonForVBS.Utilities

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\PythonForVBS.Utilities]

[HKEY_CURRENT_USER\Software\Classes\PythonForVBS.Utilities\CLSID]
@="{62F16FCC-730A-4CD4-9249-CE1B683AE423}"

registry export from HKEY_CURRENT_USER\Software\Classes\CLSIDPythonForVBS.Utilities

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\CLSIDPythonForVBS.Utilities]
@="Python Test COM Server"
7
  • It would be helpful if you included the exact error you get, what Python version you use (32/64 bit) and the registry export from \HKEY_CURRENT_USER\Software\Classes\CLSID\PythonForVBS.Utilities and/or \HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\PythonForVBS.Utilities. Commented Feb 10, 2020 at 17:07
  • @Tomalak It seems like the registry is not present in any of the paths you mentioned. Instead, it is present here \HKEY_CURRENT_USER\Software\Classes\CLSIDPythonForVBS.Utilities and \HKEY_CURRENT_USER\Software\Classes\PythonForVBS.Utilities. Could this be a problem that the registry is not present at the path you mentioned? Also, I've added some more information in the original question. Commented Feb 10, 2020 at 18:28
  • Are you sure that your VBS host and your Python have the same bitness? Because calling 64-bit COM objects from a 32 bit host will not work. Commented Feb 10, 2020 at 19:28
  • 1
    How things are supposed to be: ...\Software\Classes\{Class.Name} is the root of the class registration. The default value there can be used for a human readable name. If there is a subkey CLSID, then its default value has a GUID that is listed at \SOFTWARE\Classes\CLSID\{my-class-guid} where the server and threading model are listed. Commented Feb 11, 2020 at 7:47
  • 1
    You are right, ...\Software\Classes\{Class.Name} seems problematic. Turns out my code has some errors and is not able to register the class properly. So I ended up using the code provided here and this solves the problem. Thank you @Tomalak for pointing me in the right direction. Commented Feb 12, 2020 at 16:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.