forked from shaba/openuds
Merge branch 'master' of github.com:dkmstr/openuds
This commit is contained in:
commit
7f4e7e3309
@ -39,6 +39,7 @@ import win32net
|
||||
import win32event
|
||||
import pythoncom
|
||||
import servicemanager
|
||||
import winreg as wreg
|
||||
|
||||
from . import operations
|
||||
from . import store
|
||||
@ -197,6 +198,17 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
except Exception as e:
|
||||
logger.error('Exception removing user from Remote Desktop Users: {}'.format(e))
|
||||
|
||||
def isInstallationRunning(self):
|
||||
'''
|
||||
Detect if windows is installing anything, so we can delay the execution of Service
|
||||
'''
|
||||
try:
|
||||
key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State')
|
||||
data, _ = wreg.QueryValueEx(key, 'ImageState')
|
||||
return data != 'IMAGE_STATE_COMPLETE' # If ImageState is different of ImageStateComplete, there is something running on installation
|
||||
except Exception: # If not found, means that no installation is running
|
||||
return False
|
||||
|
||||
def SvcDoRun(self) -> None: # pylint: disable=too-many-statements, too-many-branches
|
||||
'''
|
||||
Main service loop
|
||||
@ -209,6 +221,17 @@ class UDSActorSvc(win32serviceutil.ServiceFramework, CommonService):
|
||||
|
||||
pythoncom.CoInitialize() # pylint: disable=no-member
|
||||
|
||||
# Check if some install is running on windows before proceeding
|
||||
while self._isAlive:
|
||||
if self.isInstallationRunning():
|
||||
win32event.WaitForSingleObject(self._hWaitStop, 1000) # Wait a bit, and check again
|
||||
continue
|
||||
break
|
||||
|
||||
if not self._isAlive: # Has been stopped while waiting windows installations
|
||||
self.finish()
|
||||
return
|
||||
|
||||
# Unmanaged services does not initializes "on start", but rather when user logs in (because userservice does not exists "as such" before that)
|
||||
if self.isManaged():
|
||||
if not self.initialize():
|
||||
|
@ -76,9 +76,9 @@ def writeConfig(config: types.ActorConfigurationType) -> None:
|
||||
except Exception:
|
||||
key = wreg.CreateKeyEx(BASEKEY, PATH, 0, wreg.KEY_ALL_ACCESS)
|
||||
|
||||
fixRegistryPermissions(key.handle)
|
||||
fixRegistryPermissions(key.handle) # type: ignore
|
||||
|
||||
wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, pickle.dumps(config))
|
||||
wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, pickle.dumps(config)) # type: ignore
|
||||
wreg.CloseKey(key)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user