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"
\HKEY_CURRENT_USER\Software\Classes\CLSID\PythonForVBS.Utilitiesand/or\HKEY_CURRENT_USER\Software\Classes\WOW6432Node\CLSID\PythonForVBS.Utilities.\HKEY_CURRENT_USER\Software\Classes\CLSIDPythonForVBS.Utilitiesand\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....\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 subkeyCLSID, 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....\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.