Aşağıda kullanıcağınız script bir msi dosyasını web sayfasından indirip kurmak için hazırlanmıştır. Böylece Scriptin çalıştığı makinada belirttiğiniz adresten dosya indirilir ve kurulum sağlanır.
Aşağıdaki kodu
Comodo/Xcitium Panel > ITSM > Remote Monitoring and Management > Procedures kısmında yeni bir Presedür / Procedure Script oluştur deyip uygun yere yapıştırın.
Sorularınızı yorum kısmında sorabilirsiniz.
—————– KOD ————–
# -*- coding: utf-8 -*-
“””
====================================================================================================
SCRIPT KÜNYESİ VE TEKNİK DOKÜMANTASYON
====================================================================================================
SCRIPT ADI: Teramind Ajanı – Advanced Deployment Script (PowerShell DL + Smart Monitor)
YAZAR/TARİH: H. Kaan ATASOY (atasoyhk@gmail.com) / 05.12.2025
HEDEF SİSTEM: Windows 10 / 11 (Comodo/Itarian/Xcitium Entegrasyonu)
AÇIKLAMA:
Bu script, uç nokta yönetim sistemlerinde (RMM) yaşanan indirme ve kurulum sorunlarını
aşmak için geliştirilmiş hibrit bir dağıtım çözümüdür. BITS servisinin yanıt vermediği
senaryolarda PowerShell WebClient altyapısını devreye sokar.
TEKNİK DETAYLAR VE ÇÖZÜM MİMARİSİ:
1. POWERSHELL TABANLI GÜVENLİ İNDİRME:
– Standart Python kütüphanelerinin (urllib) takıldığı TLS 1.2/1.3 el sıkışma hatalarını
(Errno 10054) gidermek için .NET Framework altyapısını kullanır.
– [Net.SecurityProtocolType]::Tls12 zorlaması ile güvenli indirme sağlar.
2. DOSYA İSMİ VE KOMUT SATIRI UYUMLULUĞU:
– Dosya ismindeki özel karakterlerin (parantez vb.) komut satırı yorumlayıcısında (CMD)
neden olduğu “Exit Code 1” hatasını önlemek için ‘subprocess’ modülü ve escape
karakterleri optimize edilmiştir.
3. SMART MONITORING (60 SANİYE):
– Kurulum işlemi “Fire & Forget” yerine 60 saniyelik aktif izleme modunda başlatılır.
– Olası yetki, dosya bütünlüğü veya mimari hataları anlık olarak konsola basılır.
4. FAIL-SAFE MEKANİZMASI:
– Ağ adaptörünün sıfırlandığı kurulum senaryolarında RMM ajanının “Service Terminated”
hatası vermesini engellemek için, başarılı başlangıç sonrası script kontrollü olarak sonlanır.
LOG LOKASYONU: C:\\Kurulum_Loglari\\teramind_install.log
====================================================================================================
“””
import os
import ctypes
import sys
import subprocess
import time
# — YAPILANDIRMA —
Url = “https://siteadresi.com/dosyaadi.msi”
DosyaAdi = “dosyaadi.msi”
LogKlasoru = “C:\\Kurulum_Loglari”
LogDosyasiAdi = “teramind_install.log”
# — 64-BIT DOSYA SİSTEMİ YÖNLENDİRMESİ —
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
def Download_With_PowerShell(url, save_path):
print(“[INFO] Indirme islemi baslatiliyor (Metod: PowerShell / TLS 1.2)…”)
# PowerShell Komut Seti
# Dosya yolları tek tırnak içine alınarak özel karakter hataları engellenmiştir.
ps_script = “[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile(‘{0}’, ‘{1}’)”.format(url, save_path)
cmd = ‘powershell -Command “{0}”‘.format(ps_script)
try:
ret = os.system(cmd)
# Bütünlük Kontrolü
if os.path.exists(save_path):
size = os.path.getsize(save_path)
if size > 10240: # 10 KB alt limit kontrolü
print(“[OK] Dosya indirildi: ” + save_path)
print(“[INFO] Dosya Boyutu: ” + str(size) + ” bytes”)
return True
else:
print(“[ERROR] Dosya boyutu hatali (” + str(size) + ” bytes). Indirme engellenmis olabilir.”)
return False
else:
print(“[ERROR] PowerShell islemi tamamladi ancak dosya olusmadi. Exit Code: ” + str(ret))
return False
except Exception as e:
print(“[CRITICAL] PowerShell Runtime Hatasi: ” + str(e))
return False
def Install_Monitored(msi_path):
# Log dizini kontrolü
if not os.path.exists(LogKlasoru):
try: os.makedirs(LogKlasoru)
except: pass
log_path = os.path.join(LogKlasoru, LogDosyasiAdi)
if os.path.exists(log_path):
try: os.remove(log_path)
except: pass
print(“[INFO] Kurulum baslatiliyor (Izleme Suresi: 60sn)…”)
print(“[INFO] MSI Log Yolu: ” + log_path)
# MSIEXEC Parametreleri
# shell=False kullanımı ile komut enjeksiyonu ve karakter hataları önlenir.
command = [
‘msiexec.exe’,
‘/i’, msi_path,
‘/qn’, # Quiet Mode
‘/norestart’, # Suppress Reboot
‘/L*V’, log_path # Verbose Logging
]
try:
proc = subprocess.Popen(command, shell=False)
# — MONITORING LOOP (60s) —
start_time = time.time()
monitor_duration = 60
print(“\n— INSTALLATION LOG STREAM —\n”)
last_pos = 0
while (time.time() – start_time) < monitor_duration:
# Process durum kontrolü
return_code = proc.poll()
if return_code is not None:
if return_code == 0 or return_code == 3010:
print(“\n[OK] Kurulum surec icerisinde tamamlandi.”)
return True
else:
print(“\n[ERROR] Kurulum hatali sonlandi. Return Code: ” + str(return_code))
Print_Log_Tail(log_path)
return False
# Log okuma ve stream etme
if os.path.exists(log_path):
try:
with open(log_path, ‘r’) as f:
f.seek(last_pos)
new_data = f.read()
if new_data:
print(new_data)
last_pos = f.tell()
except: pass
time.sleep(2)
# — TIMEOUT / SUCCESS —
print(“\n— MONITORING COMPLETE —“)
print(“[INFO] Kurulum arka planda devam ediyor.”)
print(“[INFO] Servis kesintisi riskine karsi script basarili statsuyle sonlandiriliyor.”)
return True
except Exception as e:
print(“[CRITICAL] Kurulum Baslatma Hatasi: ” + str(e))
return False
def Print_Log_Tail(path):
# Hata durumunda son log satırlarını getirir
print(“\n— MSI ERROR DUMP —“)
try:
if os.path.exists(path):
with open(path, ‘r’) as f:
lines = f.readlines()
for line in lines[-20:]:
print(line.strip())
except: pass
# — MAIN EXECUTION BLOCK —
with disable_file_system_redirection():
# Geçici çalışma dizini (Windows Temp)
temp_folder = “C:\\Windows\\Temp”
if not os.path.exists(temp_folder):
try: os.makedirs(temp_folder)
except: pass
msi_path = os.path.join(temp_folder, DosyaAdi)
# Temizlik
if os.path.exists(msi_path):
try: os.remove(msi_path)
except: pass
# PHASE 1: DOWNLOAD
if Download_With_PowerShell(Url, msi_path):
# PHASE 2: INSTALLATION
if Install_Monitored(msi_path):
print(“[SUCCESS] ISLEM TAMAMLANDI.”)
sys.exit(0)
else:
print(“[FAILED] KURULUM BASARISIZ.”)
sys.exit(1)
else:
print(“[FAILED] INDIRME ISLEMI BASARISIZ.”)
sys.exit(1)