[VBScript] partage de connection suivant hora

Fermé
Ze Big Duck - 6 juin 2005 à 16:55
 mmisterk - 23 mai 2007 à 15:13
Bonjour,

L'hôte de mon domaine coupe le partage de la connection internet à 20h30, il la re-partage à 9h.

voici son script, qu'il éxécute en tant que tâche planifiée (sur win XP) :


' 
'Title: toggleICS.vbs 
'Purpose: turn on and turn off the Internet Connection Sharing on a specified interface 
'Platform: Windows XP 
'Requirement: Wscript.exe 
' 
'Date: 20/05/05 
' 

DIM CONNECTION_ALL 
DIM NetSharingManager 
DIM EveryConnectionCollection 
DIM EveryConnection 

DIM Arguments 
DIM Interface 

CONNECTION_ALL = 2 
Interface = "Freebox" 

set WshShell = WScript.CreateObject("WScript.Shell") 

if initialize() then 
    if GetConnectionObjects() then 
        if FirewallTestByName(Interface) then 
            ChangeSharing() 
        end if 
    end if 
end if 


function FirewallTestByName(InterfaceName) 
on error resume next 
    DIM Item 
    DIM Properties 
    DIM InterfaceExist 
     
    InterfaceExist = FALSE 
    for each Item in EveryConnectionCollection 
        set EveryConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item) 
        set Properties = NetSharingManager.NetConnectionProps(Item) 
            
        if (ucase(InterfaceName) = ucase(Properties.Name)) then 
            InterfaceExist = TRUE 
            exit for        
        end if 
    next 
    FirewallTestByName = InterfaceExist 
end function 

function ChangeSharing() 
    if EveryConnection.SharingEnabled then 
        EveryConnection.DisableSharing 
    else 
        EveryConnection.EnableSharing(ICSSHARINGTYPE_PUBLIC) 
    end if 
end function 

function Initialize() 
'output: TRUE or FALSE 

    DIM Return 
    Return = FALSE 
    set NetSharingManager = Wscript.CreateObject("HNetCfg.HNetShare.1") 
    if (IsObject(NetSharingManager)) = FALSE then 
        Wscript.Echo("The Internet Sharing Manager cannot be contacted.  Internet Connection Firewall may not be available on this interface.") 
    else 
        if (IsNull(NetSharingManager.SharingInstalled) = TRUE) then 
            Wscript.Echo("Internet Connection Firewall may not be available on this interface.") 
        else 
            Return = TRUE 
        end if 
    end if 
    Initialize = Return 
end function 

function GetConnectionObjects() 
 
    DIM Return 
    DIM Item 
    
    Return = TRUE 
    
    if GetConnection(CONNECTION_ALL) = FALSE then 
        Return = FALSE 
    end if 
    
    GetConnectionObjects = Return      
 
end function 

function GetConnection(CONNECTION_TYPE) 

    DIM Return      
    DIM Connection 
    DIM Item 
    Return = TRUE 
    
    if (CONNECTION_ALL = CONNECTION_TYPE) then 
        set Connection = NetSharingManager.EnumEveryConnection 
        
        if (Connection.Count > 0) then 
            set EveryConnectionCollection = Connection 
        else 
            Return = FALSE 
        end if 
        
    else 
        Return = FALSE 
    end if 
    
    GetConnection = Return 
end function



J'aurais voulu savoir s'il était possible de mettre une connection en route à 21h, et de la couper à 6h du matin, et comment (en éxécutant le script sur son pc bien sûr) ?

Merci
A voir également:

2 réponses

Little Chicken
12 mai 2007 à 21:03
Une question :
Comment fais tu pour parametrer la "Connexion Reseau Domestique"
Merci
0
Ton script ne fait qu'activer le partage s'il ne l'est pas, et vis versa, donc tu n'a qu'à ajouter deux taches planifiées pour les heures voulues et le tour sera joué (execute ce meme script dans chacune des taches).
0