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"
  • 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`. – Tomalak Feb 10 '20 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. – Shubham Garg Feb 10 '20 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. – Tomalak Feb 10 '20 at 19:28
  • Yes, both the host and Python are 64-bit. – Shubham Garg Feb 11 '20 at 05:14
  • 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. – Tomalak Feb 11 '20 at 07:47
  • The first reg export you show seems right, although the human readable name is missing. Not much of a problem, that's optional anyway. The second one is strange and I can't imaging it does anything. What's at `HKEY_CURRENT_USER\Software\Classes\CLSID\{62F16FCC-730A-4CD4-9249-CE1B683AE423}`? – Tomalak Feb 11 '20 at 07:49
  • 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](https://stackoverflow.com/a/42208612/7553185) and this solves the problem. Thank you @Tomalak for pointing me in the right direction. – Shubham Garg Feb 12 '20 at 16:37

0 Answers0