Project

General

Profile

Feature #7449 » sleep.txt

Geco-it Staff, 04/05/2017 10:15 AM

 
1
' ___________________________________________________________________
2
'
3
'  VBScript File:   Sleep.vbs
4
'  Author:          Frank-Peter Schultze
5
'
6
'  Updates:         http://www.fpschultze.de/modules/smartfaq/faq.php?faqid=73
7
'  Enhancement Req.
8
'  And Bug Reports: support@fpschultze.de
9
'
10
'  Built/Tested On: Windows 98 SE, Windows 2000
11
'  Requirements:    OS: Windows 95+, Windows NT4+
12
'                   WSH: 2.0+
13
'
14
'  Purpose:         Batch file wait.
15
'
16
'  Syntax:          Sleep time-to-sleep-in-seconds
17
'
18
'  State Changes:   Returns exit code 0
19
'
20
'  Assumptions And
21
'  Limitations:     -
22
'
23
'  Last Update:     2003-02-11
24
' ___________________________________________________________________
25
'
26

    
27
Option Explicit
28

    
29
On Error Resume Next
30

    
31
Dim sSecs
32

    
33
If Not IsCscript() Then
34
  WScript.Echo "Please run this script using CSCRIPT."
35
  WScript.Quit(1)
36
End If
37

    
38
If ParseCmdLine(sSecs) Then
39
  WScript.Sleep CInt(sSecs)*1000
40
End If
41

    
42
WScript.Quit(0)
43

    
44

    
45
Private Function ParseCmdLine(sSecs)
46

    
47
  ParseCmdLine = False
48

    
49
  If WScript.Arguments.Count = 1 Then
50
    Select Case WScript.Arguments(0)
51
      Case "/?" : ShowUsage(True)
52
      Case "-?" : ShowUsage(True)
53
      Case "/h" : ShowUsage(True)
54
      Case "-h" : ShowUsage(True)
55
      Case "h"  : ShowUsage(True)
56
      Case Else : sSecs = WScript.Arguments(0)
57
                  ParseCmdLine = True
58
    End Select
59
  Else
60
    ShowUsage(True)
61
  End If
62

    
63
End Function
64

    
65

    
66
Private Function IsCscript()
67

    
68
  IsCscript = False
69

    
70
  If InStrRev(LCase(WScript.FullName), "cscript.exe", -1) Then
71
    IsCscript = True
72
  End If
73

    
74
End Function
75

    
76

    
77
Private Sub ShowUsage(bExit)
78

    
79
  WScript.Echo "Batch file wait."
80
  WScript.Echo ""
81
  WScript.Echo "Sleep causes the computer to wait for a specified amount of time. Sleep is"
82
  WScript.Echo "useful in batch files and may be more convenient to use than the AT command"
83
  WScript.Echo "(part of Windows NT 4+) in certain cases."
84
  WScript.Echo ""
85
  WScript.Echo "Sleep time"
86
  WScript.Echo ""
87
  WScript.Echo "  time     The number of seconds to pause."
88

    
89
  If bExit Then
90
    WScript.Quit(1)
91
  End If
92

    
93
End Sub
(1-1/2)