Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    Dhaka,Bangladesh
    Posts
    86

    Question Unanswered: Net Time Command Value Stored in VB Variable

    Hello Experts...

    By the Net Time Command Like
    Net Time \\localhost

    i can get my server time and date. now i want issued it in Visual basic
    using "shell" command. I want to store the output in Visual basic variable
    i dont want to save the output in text file. I want to use variable to store
    the output.Plz help me.

    mahfuz
    hello

  2. #2
    Join Date
    Mar 2004
    Location
    Oakland, CA, USA
    Posts
    26

    RE: Store shell command output in VB variable

    Hello Mahfuz,

    Just a workaround solution. Assume that file test.txt has been created by net time command. Hope it helps.

    '-------------------------
    Dim myString As String
    Open "c:\test.txt" For Input As #1
    Input #1, myString
    Close #1
    MsgBox myString
    '-------------------------

  3. #3
    Join Date
    Nov 2003
    Location
    Dhaka,Bangladesh
    Posts
    86

    Unhappy

    Tnaks McCampbell

    but i can do save the output in text file using vb's file operation i can rad it in variable but i want to store the output straight in variable.

    Like I declare

    Dim serverTime

    now want to save "Shell" Return string in serverTime....

    If u can Plz help me.

    mahfuz
    hello

  4. #4
    Join Date
    Mar 2004
    Location
    Oakland, CA, USA
    Posts
    26

    Re:

    Hello Mahfuz,

    Again, just a workaround. I believe someone out there will have a better solution.


    '-------------------------------------
    Private Sub cmdTime_Click()
    Dim procID
    Dim ServerTime

    procID = Shell("c:\windows\system32\cmd.exe /c net time \\servername > c:\time.log", vbNormalFocus)

    'take some sleep here, I guess.

    Open "c:\time.log" For Input As #1
    Input #1, ServerTime
    Close #1
    ServerTime = Trim(Right(ServerTime, 18))

    MsgBox "Current date and time on my server: " & ServerTime

    End Sub
    '-------------------------------

  5. #5
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    228
    Why not get the info from the netapi?

    Code:
    Public Type TIME_OF_DAY_INFO
        tod_elapsedt    As Long
        tod_msecs       As Long
        tod_hours       As Long
        tod_mins        As Long
        tod_secs        As Long
        tod_hunds       As Long
        tod_timezone    As Long
        tod_tinterval   As Long
        tod_day         As Long
        tod_month       As Long
        tod_year        As Long
        tod_weekday     As Long
    End Type
    
    Private Declare Function NetRemoteTOD Lib "netapi32" (tServer As Any, pBuffer As Long) As Long
    Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal lpBuffer As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
    
    Public Function GetTimeOfDay(ByRef Server As String) As TIME_OF_DAY_INFO
        Dim pBuffer As Long
        Dim Status As Long
        
        Status = NetRemoteTOD(ByVal StrPtr(Server), pBuffer)
           
        If pBuffer <> 0 Then
            If Status = 0 Then
                CopyMemory GetTimeOfDay, ByVal (pBuffer), LenB(GetTimeOfDay)
            End If
            NetApiBufferFree pBuffer
        End If
        
    End Function
    Last edited by Apel; 11-02-04 at 11:07.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •