refs #1221 add ogUninstallWindowsClient()

pull/1/head
Natalia Serrano 2024-12-05 15:02:47 +01:00
parent 7dccc621cb
commit 9f94951f3f
1 changed files with 93 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import SystemLib
import FileSystemLib
import FileLib
import NetLib
import RegistryLib
#/**
# ogCleanOs int_ndisk int_nfilesys
@ -34,6 +35,11 @@ import NetLib
#@brief Metafunción para instalar archivo que se ejecutará en el arranque de Windows.
#@see ogInstallFirstBoot ogInstallRunonce
#*/ ##
def ogInstallMiniSetup (disk, par, cmdfile, user=None, pwd=None, autologin=False, userauto=None, pwdauto=None):
if user:
ogInstallRunonce (disk, par, cmdfile, user, pwd, autologin, userauto, pwdauto)
else:
ogInstallFirstBoot (disk, par, cmdfile)
#/**
@ -46,6 +52,30 @@ import NetLib
#@exception OG_ERR_FORMAT Formato incorrecto.
#@note El archivo estará en system32 y será visible por el sistema.
#*/ ##
#ogInstallFirstBoot ('1', '1', 'filename.cmd')
def ogInstallFirstBoot (disk, par, cmdfile):
mntdir = FileSystemLib.ogMount (disk, par)
if not mntdir: return
for i in ['winnt', 'windows']:
dir = FileLib.ogGetPath (file=f'{mntdir}/{i}/system32')
if dir: cmddir = dir
if not cmddir:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{mntdir}/windows/system32')
return
full_cmdfile = f'{cmddir}/{cmdfile}'
# Creamos el archivo cmd y creamos un par de comandos para que una vez acabe la
# postconfiguracion resetee el mini setup, sino lo haria en cada arranque.
with open (full_cmdfile, 'w') as fd:
fd.write ('REG ADD HKLM\System\Setup /v SystemSetupInProgress /t REG_DWORD /d 0 /f\n')
fd.write ('REG ADD HKLM\System\Setup /v CmdLine /t REG_SZ /d "" /f\n')
# Crear los valores de registro necesarios para que se haga la ejecución del .cmd al aranque.
RegistryLib.ogSetRegistryValue (mntdir, 'SYSTEM', r'\Setup\SystemSetupInProgress', 1)
RegistryLib.ogSetRegistryValue (mntdir, 'SYSTEM', r'\Setup\SetupType', 4)
#RegistryLib.ogDeleteRegistryValue (mntdir, 'SYSTEM', r'\Setup\CmdLine')
RegistryLib.ogAddRegistryValue (mntdir, 'SYSTEM', r'\Setup\CmdLine')
RegistryLib.ogSetRegistryValue (mntdir, 'SYSTEM', r'\Setup\CmdLine', f'cmd.exe /c $(basename {full_cmdfile})')
#/**
@ -62,6 +92,44 @@ import NetLib
#@return (nada)
#@exception OG_ERR_FORMAT Formato incorrecto.
#*/ ##
#ogInstallRunonce ('1', '1', 'filename.cmd', 'administrator', 'passadmin', '1', 'userauto', 'pwdauto')
#ogInstallRunonce ('1', '1', 'filename.cmd', 'administrator', 'passadmin', '0')
def ogInstallRunonce (disk, par, cmdfile, user, pwd, autologin, userauto=None, pwdauto=None):
mountpoint = FileLib.ogGetPath (src=f'{disk} {par}', file='/')
for i in ['winnt', 'windows']:
dir = FileLib.ogGetPath (file=f'{mountpoint}/{i}/system32')
if dir: cmddir = dir
if not cmddir:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{mountpoint}/Windows/System32')
return
full_cmdfile = f'{cmddir}/{cmdfile}'
if not autologin:
# Si no queremos hacer autologin despues de la postconfiguracion lo indicamos en las claves de registro
with open (full_cmdfile, 'w') as fd:
fd.write (r'DEL C:\ogboot.*\n')
fd.write (r'REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /f\n')
fd.write (r'REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d "" /f\n')
fd.write (r'REG DELETE "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /f\n')
else:
# Si queremos hacer autologin despues de la postconfiguracion introducimos la informacion en las claves de registro
with open (full_cmdfile, 'w') as fd:
fd.write (r'DEL C:\ogboot.*' + '\n')
fd.write (r'REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f' + '\n')
fd.write (fr'REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d "{userauto}" /f' + '\n')
fd.write (fr'REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d "{pwdauto}" /f' + '\n')
#Creamos las claves de registro necesarias para que meter el cmd en el runonce del usuario y este haga autologin
RegistryLib.ogAddRegistryValue (mountpoint, 'software', r'\Microsoft\Windows\CurrentVersion\RunOnce\PostConfiguracion')
RegistryLib.ogSetRegistryValue (mountpoint, 'software', r'\Microsoft\Windows\CurrentVersion\RunOnce\PostConfiguracion', rf'C:\windows\system32\{full_cmdfile}')
RegistryLib.ogAddRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon')
RegistryLib.ogSetRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon', 1)
RegistryLib.ogAddRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName')
RegistryLib.ogSetRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName', user)
RegistryLib.ogAddRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName')
RegistryLib.ogSetRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName', '.\\')
RegistryLib.ogAddRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword')
RegistryLib.ogSetRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword', pwd)
RegistryLib.ogDeleteRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\ForceAutoLockOnLogon')
RegistryLib.ogDeleteRegistryValue (mountpoint, 'software', r'\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoLogonCount')
#/**
# ogAddCmd int_ndisk int_npartition str_filename str_commands
@ -74,6 +142,20 @@ import NetLib
#@exception OG_ERR_FORMAT Formato incorrecto.
#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
#*/ ##
#ogAddCmd ('1', '1', 'filename.cmd', 'command')
def ogAddCmd (disk, par, cmdfile, cmd):
mountpoint = FileSystemLib.ogMount (disk, par)
if not mountpoint: return
full_cmdfile = FileLib.ogGetPath (file=f'{mountpoint}/windows/system32') + '/' + cmdfile
if not full_cmdfile:
ogInstallMiniSetup (disk, par, cmdfile)
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{mountpoint}/windows/system32/{cmdfile}')
return
# Concatenamos el comando en el fichero de comandos
with open (full_cmdfile, 'a') as fd:
fd.write (cmd + '\n')
#/**
@ -209,3 +291,14 @@ def ogUninstallLinuxClient (disk, par):
#@exception OG_ERR_PARTITION Paritición o sistema de archivos incorrectos.
#@exception OG_ERR_LOCKED Sistema de archivos bloqueado.
#*/ ##
#ogUninstallWindowsClient ('1', '1', 'filename.cmd')
def ogUninstallWindowsClient (disk, par, cmdfile):
mntdir = FileSystemLib.ogMount (disk, par)
if not mntdir: return
exe1 = FileLib.ogGetPath (file=f'{mntdir}/windows/ogAdmWinClient.exe')
exe2 = FileLib.ogGetPath (file=f'{mntdir}/winnt/ogAdmWinClient.exe')
if exe1 or exe2:
ogAddCmd (disk, par, cmdfile, 'ogAdmWinClient -remove')
ogAddCmd (disk, par, cmdfile, r'DEL C:\Windows\ogAdmWinClient.exe')
ogAddCmd (disk, par, cmdfile, r'DEL C:\Winnt\ogAdmWinClient.exe')