Ir para o conteúdo
  • Revista PROGRAMAR: Já está disponível a edição #57 da revista programar. Faz já o download aqui!


[Python]-Login Scripts em Python

Mensagens Recomendadas

teckV    1

Os créditos estão apresentados...

Title: Migrate your Windows login scripts to Python

Submitter: Fadly Tabrani (other recipes)

Last Updated: 2005/06/27

Version no: 1.0

Category: System

  --Rate-- 5 - Excellent 4 - Very good 3 - Good 2 - Needs work 1 - Poor 

Not Rated yet


The following is a guide for Windows administrators who would like to use Python for their login scripts. Onceyou've found Pythonyou'll never go back to VbScript or the dreaded batch files.

Source: Text Source

#!/usr/bin/env python
# -*- coding: utf-8 -*


1. Install Python 2.3 from to your computer.

2. Install your favourite modules:


        pywin32 module - accessing COM and other lovely windows stuff

        subprocess module - launching subprocesses from ya login scripts

        ctypes module - wrap any win32api       

3. Copy your Python23 folder to the NETLOGON (or any shared network) directory.

4. Copy these dll files from your system directory to that folder


    pythoncom23.dll - pywin32

    pywintypes23.dll - pywin32

5. Running your python scripts

    create a batch file with the lines:

        rem - path to python23 folder%\0.. refers to the current directory

        SET PYTHONPATH=%0\..\Python23

        rem - path to script to execute

        %PYTHONPATH%\python.exe %0\..\

6. What can you do in python? Endlesssee below...

 #pywintypes must be imported b4 any win32 modules
import pywintypes
import win32com.client

# Disconnect previously mapped drives.
wshnetwork = win32com.client.Dispatch('Wscript.Network')
network_drives = wshnetwork.EnumNetworkDrives()
for mapped_drive in [network_drives.Item(i) 
                     for i in range(0network_drives.Count() -1 2) 
                     if network_drives.Item(i)]:

# Network drive mapping.
drive_mappings = [
for drive_letternetwork_path in drive_mapping:
    except Exceptionerr:
        print err

# Batch execute other python files in some_dir.
import sys
import virusupdate
import checkhotfix

# Other advantages:
# GUI for your logon scripts with TKInterWin32Gui.
# Centrally managed python installation.
# Access to the Win32 API.
# Robust error handling.
# Not to mentionmultithreading!
# Can also be used with Group Policy scripts.


Have you been scouring for utilities from resource kitssitesjust to do something from your login scripts. Well I haveand I have given up. Moving to Python have eliminated that needeverything and I mean everything can be done from Python itself.

I work in a company where different user environments are created frequentlyongoing projectsnew clientsnew serversnew requirements. Moving to Python allows me to code faster and be more flexible.

Login scripts run much faster and long running processes can be multithreaded for performance.

Don't believe me? Try it and you'll never look back.


Partilhar esta mensagem

Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!

Registar nova conta


Já tem conta? Inicie sessão aqui.

Entrar Agora


Aviso Sobre Cookies

Ao usar este site você aceita os nossos Termos de Uso e Política de Privacidade