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

VBScript Discussion :

Manipulation date et l'heure


Sujet :

VBScript

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2013
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2013
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Manipulation date et l'heure
    [j'ai besoin de faire un programme .vbs qui me dis la date et l'heure qu'il est.
    sa encore c'est plutot simple, mais ensuite le programme dois m'afficher, 2h après, que cela fait 2 heure que l'ordinateur est allumé et qu'il s'étendra dans 30 seconde. je n'y arrive pas du tout alor j'implore votre aide.
    merci d'avance

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut

    Testez ce code
    Code : 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
    Titre = "Alarme"
    Set ws = CreateObject("wscript.Shell")
    alarmDansMin  = Trim ( InputBox( "Dans combien de minutes voulez-vous déclenchez l'alarme ? " & vbCrLf & vbCrLf & NOW,Titre, "120") )
    If alarmDansMin = ""  Then Wscript.Quit
    If Not IsNumeric(alarmDansMin) or alarmDansMin <= 1 Then
        ws.Popup "Il faut Taper un Nombre strictement supérieur à 1 !","2",Titre,0+16 'Afficher un Popup durant 2 secondes puis quitte le script 
        Wscript.Quit
    End if 
    sMessage = "Reste " & alarmDansMin/2 & " minutes !"
    alarmDansmmsec = alarmDansMin*60*1000 'en millisecondes
    alaramSecondes = alarmDansMin*60 'en secondes
    nMinutes = alarmDansMin/2
    WScript.sleep  alarmDansmmsec/2
    nSeconds = 0
    sMessage = "<font color=red size=4><b>ALARME</b></font>"
    ' Open a chromeless window with message
    with HTABox("lightBlue", 175, 450, 400,100)
        .document.title = "Notification"
        .msg.innerHTML = sMessage
        do until .done.value or (nMinutes + nSeconds < 1)
            .msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _
            & " restantes <br>"
            wsh.sleep 1000 ' milliseconds
            nSeconds = nSeconds - 1
            if nSeconds < 0 then 
                if nMinutes > 0 then
                    nMinutes = nMinutes - 1
                    nSeconds = 59
                end if
            end if
        loop
        .done.value = true
        .close
    end with
    ws.Popup "C'est FINI !","5",Titre,0+64
    Call Run_Shutdown(120)
    Call Poser_question()
    '*****************************************************************************************************************
    Function HTABox(sBgColor, h, w, l, t)
        Dim IE, HTA, sCmd, nRnd
        randomize : nRnd = Int(1000000 * rnd)
        sCmd = "mshta.exe ""javascript:{new " _
        & "ActiveXObject(""InternetExplorer.Application"")" _
        & ".PutProperty('" & nRnd & "',window);" _
        & "window.resizeTo(" & w & "," & h & ");" _
        & "window.moveTo(" & l & "," & t & ")}"""
        Set WshShell = WScript.CreateObject("WScript.Shell")
        with CreateObject("WScript.Shell")
            .Run sCmd, 1, False
            do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
            end with  'WSHShell
            For Each IE In CreateObject("Shell.Application").windows
                If IsObject(IE.GetProperty(nRnd)) Then
                    set HTABox = IE.GetProperty(nRnd)
                    IE.Quit
                    HTABox.document.title = "HTABox"
                    HTABox.document.write _
                    "<HTA:Application contextMenu=no border=thin " _
                    & "minimizebutton=no maximizebutton=no sysmenu=no />" _
                    & "<body scroll=no style='background-color:" _
                    & sBgColor & ";font:normal 10pt Arial;" _
                    & "border-Style:inset;border-Width:3px'" _
                    & "onbeforeunload='vbscript:if not done.value then " _
                    & "window.event.cancelBubble=true:" _
                    & "window.event.returnValue=false:" _
                    & "done.value=true:end if'>" _
                    & "<input type=hidden id=done value=false>" _
                    & "<center><span id=msg>&nbsp;</span><br>" _
                    & "<input type=button id=btn1 value=' OK ' "_
                    & "onclick=done.value=true><center></body>"
                    HTABox.btn1.focus
                    Exit Function
                End If
            Next
            MsgBox "HTA window not found."
            wsh.quit
    End Function
     
    Sub Poser_question()
    	Question = MsgBox ("Vouliez-vous annuler le shutdown de votre PC ?",VBYesNO+VbQuestion,Titre)
    	If Question = VbYes then
    		Call Annuler_Shutdown()
    		Wscript.Quit
    	else
    		Wscript.Quit    
    	end if
    End Sub
     
    Sub Run_Shutdown(N)
    	Dim Command,Execution
    	Command = "Cmd /c Shutdown -s -t "& N &" -c "& DblQuote("Sauvegarder votre travail car votre PC va s'arrêter dans "& N &" seconde(s)")
    	Execution = ws.run(Command,0,True)
    End sub
     
    Sub Annuler_Shutdown()
    	Dim Command,Execution
    	Command = "Cmd /c Shutdown -a"
    	Execution = ws.run(Command,0,True)
    End Sub
     
    '*****************************************************************
    'Fonction pour ajouter des guillemets dans une variable
    Function DblQuote(Str)
    	DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '*****************************************************************

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2020
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2020
    Messages : 114
    Points : 92
    Points
    92
    Par défaut Manipulations de la date et de l'heure
    Bonjour. à tous

    Étant nouveaux sur ce forum

    Je me permet de posé une question

    J'ai par moi même testé ce script récemment je confirme qu'il fonctionne à merveille. Un grand Merci Hackoofr.

    Ma question est, peut on modifier ce script pour qu' au lieu d'éteindre le pc il exécute un script ou un mp3 à la place...

    Merci par avance...

Discussions similaires

  1. Manipulation de date et l'heure Excel
    Par yacinew dans le forum Excel
    Réponses: 9
    Dernier message: 18/09/2013, 16h33
  2. [Date] enregistrer la date et l'heure
    Par Nanoua dans le forum JDBC
    Réponses: 19
    Dernier message: 25/05/2012, 03h33
  3. Recuperer la date sans l'heur dans un champ datetime
    Par bob33 dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 22/06/2010, 12h59
  4. Réponses: 7
    Dernier message: 16/09/2005, 10h14
  5. Bloque la date et l'heure sous Win XP ??
    Par Djedjeridoo dans le forum Windows
    Réponses: 2
    Dernier message: 05/04/2004, 12h11

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