NHSleep - Win32 command line sleep tool

Posted in: Projects
By dePoPo
Aug 23, 2009 - 9:41:54 AM

NHSLeep is a tiny utility you can run on the windows command line to sleep any batch file for a given number of seconds.

usage;

NHSleep.exe /t:<waittime>

Where waittime is the time in seconds you want your application to sleep

If you only need the tool itsself, download the NHSleep.zip file attached to the end of this article and extract it to some usable location (eg c:\tools). You can call it from any batchfile by inserting a line like

c:\tools\nhsleep.exe /t:5

Source code posted below;

Module Module1

    Sub Main()

        Dim mylist As New List(Of String)
        mylist = GetCommandLineParameters()
        Dim b_validentry As Boolean = False
        For Each item In mylist

            If Strings.Left(item, 3) = "/t:" Then

                ' --- Found a valid entry
                b_validentry = True
                Dim n_waittime As Integer = Strings.Mid(item, 4, Len(item))
                For f As Integer = 1 To n_waittime
                    System.Threading.Thread.Sleep(1000)
                Next
            End If

        Next

        If b_validentry = False Then
            ' --- No valid entry, tell the user
            Console.WriteLine("NHSleep 1.0, www.dePoPo.net")
            Console.WriteLine("Usage: NHSleep /t:<time>")
            Console.WriteLine("Where <time> is the time to sleep in seconds")
        End If


    End Sub


    Public Function GetCommandLineParameters() As List(Of String)

        Dim mylist As New List(Of String)

        mylist.Clear()
        For Each arg As String In Environment.GetCommandLineArgs()
            mylist.Add(arg)
        Next arg

        Return mylist

    End Function

    Public Function CheckCommandLineParameterExists(ByVal s_commandlineparamater As String) As Boolean

        For Each arg As String In Environment.GetCommandLineArgs()
            If arg = s_commandlineparamater Then Return True
        Next arg

    End Function


End Module




Downloads


Visitor Comments