IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Popup écran de veille inactivité 15min [PowerShell]


Sujet :

Scripts/Batch

  1. #1
    Membre averti
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Août 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 15
    Par défaut Popup écran de veille inactivité 15min
    Bonjour,

    Je souhaite savoir s'il y a une solution pour mes utilisateurs pour faire apparaitre un popup ou un message au bout de 15 min d'inactivité pour dire que la session Windows va se fermer merci de cliquer sur un bouton pour empêcher la déconnection, et si la personne ne fait rien la session se ferme automatiquement.

    Merci d'avance pour votre aide.
    Bien cordialement,

  2. #2
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut

    Je crois que j'ai fait un vbscript similaire à votre demande mais dommage l’utilisateur n'a pas encore mentionner que la question a été
    Comment déclencher une action après un période d’inactivité de l'ordinateur
    Dans votre situation, juste repérer cette ligne : Timeout_Idle = "60" et changer la comme ça : Timeout_Idle = "15"

  3. #3
    Membre averti
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Août 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 15
    Par défaut On y est Presque
    Merci hackoofr pour votre réponse. on y est presque arrivé à la solution finale.

    Il me faut si c'est possible :

    1 - verouiller l'ordinateur au lieu d'arreter la machine.

    2 - il me faut si la personne clique sur un bouton rien ne se fait car j'estime qu'il est devant sa machine et qu'il ne souhaite pas verouiller pour le coup sa session.

    Merci beaucoup pour votre aide. je suis du Maroc loll.

  4. #4
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut Auto-Lock_On_Idle_TimeOut.vbs : Verrouillage automatique de votre poste de travail après un délai d'inactivité

    Auto-Lock_On_Idle_TimeOut.vbs : Verrouillage automatique de votre poste de travail après un délai d'inactivité (15 minutes)
    Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    '##########################################################################################################################
    '# Script Name : Auto-Lock_On_Idle_TimeOut.vbs                                                                            #
    '# Auto-Lock your workstation after Idle Timeout                                                                          #
    '# Verrouillage automatique de votre poste de travail après un délai d'inactivité                                         #
    '# Idea comes from here ==>  This snippet is from http://stackoverflow.com/a/15846912                                     #
    '# https://stackoverflow.com/questions/15845508/get-idle-time-of-machine/15846912#15846912                                #
    '# https://gist.github.com/wendelb/1c364bb1a36ca5916ca4 ===> Auto-Lock your workstation after Idle-Timeout with PowerShell#
    '##########################################################################################################################
    Option Explicit
    Dim Copyright,Msg
    Msg = Lang
    Copyright = Msg(0) & ChrW(169) &" Hackoo 2020"
    If AppPrevInstance() Then 
        MsgBox Msg(1) & VbCrLF & CommandLineLike(WScript.ScriptName),VbExclamation,Copyright
        WScript.Quit   
    Else 
        Dim Timeout_Idle,strCommand,VbsPath,ShortcutName
        Timeout_Idle = "15" '15 minutes
        strCommand = "rundll32.exe user32.dll,LockWorkStation"
        VbsPath = Wscript.ScriptFullName
        ShortcutName = "Auto-Lock_On_Idle_TimeOut"
        Call Shortcut(VbsPath,ShortcutName)
        Call Write_Run_PScript(Timeout_Idle,strCommand)
    End If
    '---------------------------------------------------------------------------------------------------------------
    Sub Shortcut(PathApplication,ShortcutName)
        Dim objShell,StartFolder,objShortCut,MyTab
        Set objShell = CreateObject("WScript.Shell")
        MyTab = Split(PathApplication,"\")
        If ShortcutName = "" Then
            ShortcutName = MyTab(UBound(MyTab))
        End if
        StartFolder = objShell.SpecialFolders("Startup")
        Set objShortCut = objShell.CreateShortcut(StartFolder & "\" & ShortcutName & ".lnk")
        objShortCut.TargetPath = DblQuote(PathApplication)
        ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,44"
        objShortCut.Save
    End Sub
    '---------------------------------------------------------------------------------------------------------------
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '---------------------------------------------------------------------------------------------------------------
    Sub Write_Run_PScript(Timeout_Idle,strCommand)
        Const ForWriting = 2
        Dim fs,Ws,ts,Ret,PSFile,ByPassPSFile,M
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set Ws = CreateObject("WScript.Shell")
        PSFile = Ws.ExpandEnvironmentStrings("%Temp%") & fs.GetTempName & ".ps1"
        ByPassPSFile = "PowerShell -ExecutionPolicy bypass -noprofile -file "
        Set ts = fs.OpenTextFile(PSFile,ForWriting,True)
        ts.WriteLine "$idle_timeout = New-TimeSpan -Minutes "& Timeout_Idle &""
        ts.WriteLine "Add-Type @'"
        ts.WriteLine "using System;"
        ts.WriteLine "using System.Diagnostics;"
        ts.WriteLine "using System.Runtime.InteropServices;"
        ts.WriteLine "namespace PInvoke.Win32 {"
        ts.WriteLine "    public static class UserInput {"
        ts.WriteLine "        [DllImport(""user32.dll"", SetLastError=false)]"
        ts.WriteLine "        private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);"
        ts.WriteLine "        [StructLayout(LayoutKind.Sequential)]"
        ts.WriteLine "        private struct LASTINPUTINFO {"
        ts.WriteLine "            public uint cbSize;"
        ts.WriteLine "            public int dwTime;"
        ts.WriteLine "        }"
        ts.WriteLine "        public static DateTime LastInput {"
        ts.WriteLine "            get {"
        ts.WriteLine "                DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);"
        ts.WriteLine "                DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks);"
        ts.WriteLine "                return lastInput;"
        ts.WriteLine "            }"
        ts.WriteLine "        }"
        ts.WriteLine "        public static TimeSpan IdleTime {"
        ts.WriteLine "            get {"
        ts.WriteLine "                return DateTime.UtcNow.Subtract(LastInput);"
        ts.WriteLine "            }"
        ts.WriteLine "        }"
        ts.WriteLine "        public static int LastInputTicks {"
        ts.WriteLine "            get {"
        ts.WriteLine "                LASTINPUTINFO lii = new LASTINPUTINFO();"
        ts.WriteLine "                lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));"
        ts.WriteLine "                GetLastInputInfo(ref lii);"
        ts.WriteLine "                return lii.dwTime;"
        ts.WriteLine "            }"
        ts.WriteLine "       }"
        ts.WriteLine "    }"
        ts.WriteLine "}"
        ts.WriteLine "'@"
        ts.WriteLine "$locked = 0;"
        ts.WriteLine "Do {"
        ts.WriteLine "    $idle_time = [PInvoke.Win32.UserInput]::IdleTime;"
        ts.WriteLine "    if (($locked -eq 0) -And ($idle_time -gt $idle_timeout)) {"
        ts.WriteLine "$ws = New-Object -ComObject ""Wscript.Shell"""
        ts.WriteLine "$Title = """ & Msg(0) & """"
        ts.WriteLine "$Answer = $ws.Popup(""" & Msg(2) & """ +" 
        ts.WriteLine """" & Msg(3) & """,""20"",$Title,48+4+4096)"
        ts.WriteLine "if ($Answer -eq 7) # Si l'utilisateur clique sur le bouton No "
        ts.WriteLine "{"
        ts.WriteLine "        $locked = 0;"
        ts.WriteLine "}"
        ts.WriteLine "else # Sinon la session va être verouillé au bout de 20 secondes si l'utilsateur ne clique sur aucun bouton"
        ts.WriteLine "{"
        ts.WriteLine "        "& strCommand &""
        ts.WriteLine "        $locked = 1;"
        ts.WriteLine "}"
        ts.WriteLine "    }"
        ts.WriteLine "    if ($idle_time -lt $idle_timeout) {"
        ts.WriteLine "        $locked = 0;"
        ts.WriteLine "    }"
        ts.WriteLine "    Start-Sleep -Seconds 10"
        ts.WriteLine "}"
        ts.WriteLine "while (1 -eq 1)"
        ts.Close
        Ret = Ws.run(ByPassPSFile & PSFile,0,True)
    End sub
    '----------------------------------------------------------------------------------------------------------------
    Function AppPrevInstance()   
        With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")   
            With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
                " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")   
                AppPrevInstance = (.Count > 1)   
            End With   
        End With   
    End Function    
    '----------------------------------------------------------------------------------------------------------------
    Function CommandLineLike(ProcessPath)   
        ProcessPath = Replace(ProcessPath, "\", "\\")   
        CommandLineLike = "'%" & ProcessPath & "%'"   
    End Function
    '----------------------------------------------------------------------------------------------------------------
    Function OSLang()
        Dim dtmConvertedDate,strComputer,objWMIService,oss,os
        Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
        For Each os in oss
            OSLang = os.OSLanguage
        Next
    End Function
    '----------------------------------------------------------------------------------------------------------------
    Function Lang()
    Dim MsgFR,MsgEN
     
    MsgFR = Array("Verrouillage automatique en cas d'inactivité " ,"ATTENTION ! Il y a une autre instance en cours d'exécution !",_
    "Attention ! Votre Session va être verrouillé dans 20 secondes !`n`n Voulez-vous confirmer le Verrouillage de votre session ?","`n`n OUI ou NON ?")
     
    MsgEN = Array("Automatic Lock Session On Idle TimeOut ","ATTENTION ! There is another instance running !",_
    "Warning ! Your Session will be locked in 20 seconds !`n`n Do you want to confirm the Locking of your session ?","`n`n YES or NO ?")
     
    'Vérifiez si le système est français pour définir le tableau français comme message, sinon définissez-le comme anglais
    'Check if the system is french to set the French array as message otherwise set it as English
     
    If Oslang = 1036 Then
        Lang = MsgFR ' French Array Message to be set
    Else
        Lang = MsgEN ' English Array Message to be set
    End If
    End Function
    '----------------------------------------------------------------------------------------------------------------
    Fichiers attachés Fichiers attachés

  5. #5
    Membre averti
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Août 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 15
    Par défaut Je peux convertir ce code en Powershell ?
    Votre Code répond parfaitement à mes attentes, Merci beaucoup.Néanmoins serait il possible de le convertir en PowerShell afin de le propager aux utilisateurs de la boite?

    Bien cordialement,

  6. #6
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut Auto-Lock_On_Idle_TimeOut.ps1 : Verrouillage automatique de votre poste de travail après un délai d'inactivité

    Auto-Lock_On_Idle_TimeOut.ps1 : Verrouillage automatique de votre poste de travail après un délai d'inactivité (15 minutes)
    Code Powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    cls
    # This background job automatically locks your Workstation after a specified amount of
    # time. It will come in handy if you cannot access the screensaver settings due to policy
    # restriction but want to lock your screen after a idle timeout. Or you could just
    # press [Win]+[L] everytime you leave your desk ;) .
    #
    # start with
    #     powershell.exe -windowstyle hidden -executionpolicy Unrestricted P:\ATH\TO\logoff.ps1
    #
    # `-windowstyle hidden` will make your PowerShell disappear/run in background
    # `-executionpolicy Unrestricted` will enable this PowerShell process to allow non-signed scripts
    #
     
    # This is the only setting: How long before locking?
    # Alternative Options:
    # * -Seconds 10 ( = 10 Seconds)
    # * -Minutes 10 ( = 10 Minutes)
    # * -Hours 10 ( = 10 Hours)
    #
    $idle_timeout = New-TimeSpan -Minutes 15
     
    # DO NOT CHANGE ANYTHING BELOW THIS LINE
    ####################################################################################################################################################################
     
    # This snippet is from http://stackoverflow.com/a/15846912
    # https://stackoverflow.com/questions/15845508/get-idle-time-of-machine/15846912#15846912
    Add-Type @'
    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
     
    namespace PInvoke.Win32 {
     
        public static class UserInput {
     
            [DllImport("user32.dll", SetLastError=false)]
            private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
     
            [StructLayout(LayoutKind.Sequential)]
            private struct LASTINPUTINFO {
                public uint cbSize;
                public int dwTime;
            }
     
            public static DateTime LastInput {
                get {
                    DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);
                    DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks);
                    return lastInput;
                }
            }
     
            public static TimeSpan IdleTime {
                get {
                    return DateTime.UtcNow.Subtract(LastInput);
                }
            }
     
            public static int LastInputTicks {
                get {
                    LASTINPUTINFO lii = new LASTINPUTINFO();
                    lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
                    GetLastInputInfo(ref lii);
                    return lii.dwTime;
                }
            }
        }
    }
    '@
    #End snippet
     
    # Helper: Is currently locked?
    $locked = 0;
     
    do {
        # 1st: How long is your computer currently idle?
        $idle_time = [PInvoke.Win32.UserInput]::IdleTime;
        #Write-Host ("Idle for " + $idle_time);
     
     
        # Your computer is not locked, but idle time is longer than allowed? -> Lock it!
        if (($locked -eq 0) -And ($idle_time -gt $idle_timeout)) {
            $ws = New-Object -ComObject "Wscript.Shell"
            $Title = "Verrouillage de la Session !"
            $Answer = $ws.Popup("Attention ! Votre Session va être verrouillé dans 20 secondes !" + 
            "`n`n Voulez-vous confirmer le Verrouillage de votre session ?" +
            "`n`n OUI ou NON ?","20",$Title,48+4+4096)
     
            if ($Answer -eq 7) # Si l'utilisateur clique sur le bouton No 
             {
                 $locked = 0;
             }
            else # Sinon la session va être verouillé au bout de 20 secondes si l'utilsateur ne clique sur aucun bouton
            {
                rundll32.exe user32.dll,LockWorkStation
                $locked = 1;
            }
            # Lock it
            # rundll32.exe user32.dll,LockWorkStation
            # Setting $locked to 1 will prevent it from relocking every 10 seconds
            #$locked = 1;
            #Write-Host ("Locking");
        }
     
        # Your computer is idle for less than the allowed time -> in most cases this means it is unlocked and
        # therefore ready to be locked again!
        if ($idle_time -lt $idle_timeout) {
            $locked = 0;
        }
     
        # Save the environment. Don't use 100% of a single CPU just for idle checking :)
        Start-Sleep -Seconds 10
    }
    while (1 -eq 1)

  7. #7
    Membre averti
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Août 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2013
    Messages : 15
    Par défaut Merci beaucoup. Résolu
    Problème Résolu. Merci beaucoup pour votre aide.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Popup écran de veille inactivité 15min
    Par forcapedro10 dans le forum Windows 10
    Réponses: 1
    Dernier message: 25/10/2020, 08h25
  2. Lancer l'écran de veille
    Par The Lord of Nesquik dans le forum C
    Réponses: 9
    Dernier message: 14/05/2006, 20h17
  3. [VB]écran de veille qui reste en icone réduite
    Par marco62118 dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 25/04/2006, 23h51
  4. [VB6] activer Écran de veille
    Par Jean-François Boileau dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 31/03/2006, 22h22
  5. Creer un écran de veille
    Par Willand dans le forum C++Builder
    Réponses: 2
    Dernier message: 09/08/2002, 12h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo