MCPcopy Create free account
hub / github.com/mhammond/pywin32 / RegisterPythonServiceExe

Function RegisterPythonServiceExe

win32/src/PythonService.cpp:1329–1361  ·  view source on GitHub ↗

Register the EXE. This writes an entry to the Python registry and also to the EventLog so I can stick in messages.

Source from the content-addressed store, hash-verified

1327// This writes an entry to the Python registry and also
1328// to the EventLog so I can stick in messages.
1329static BOOL RegisterPythonServiceExe(void)
1330{
1331 printf("Registering the Python Service Manager...\n");
1332 const int fnameBufSize = MAX_PATH + 1;
1333 TCHAR fnameBuf[fnameBufSize];
1334 if (GetModuleFileName( NULL, fnameBuf, fnameBufSize)==0) {
1335 printf("Registration failed due to GetModuleFileName() failing (error %d)\n", GetLastError());
1336 return FALSE;
1337 }
1338 assert (Py_IsInitialized());
1339 CEnterLeavePython _celp;
1340 // Register this specific EXE against this specific DLL version
1341 PyObject *obVerString = PySys_GetObject("winver");
1342 if (obVerString==NULL || !PyString_Check(obVerString)) {
1343 Py_XDECREF(obVerString);
1344 printf("Registration failed as sys.winver is not available or not a string\n");
1345 return FALSE;
1346 }
1347 char *szVerString = PyString_AsString(obVerString);
1348 Py_DECREF(obVerString);
1349 // note wsprintf allows %hs to be "char *" even when UNICODE!
1350 TCHAR keyBuf[256];
1351 wsprintf(keyBuf, _T("Software\\Python\\PythonService\\%hs"), szVerString);
1352 DWORD rc;
1353 if ((rc=RegSetValue(HKEY_LOCAL_MACHINE,
1354 keyBuf, REG_SZ,
1355 fnameBuf, _tcslen(fnameBuf)))!=ERROR_SUCCESS) {
1356 printf("Registration failed due to RegSetValue() of service EXE - error %d\n", rc);
1357 return FALSE;
1358 }
1359 // don't bother registering in the event log - do it when we write a log entry.
1360 return TRUE;
1361}
1362
1363#endif // PYSERVICE_BUILD_DLL
1364

Callers 1

PythonService_mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected