Announcement

Collapse
No announcement yet.

Remote Timezone

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Remote Timezone

    Are there any API calls to get the timezone and possibly DST Status of a remote PC?
    sigpic
    Mobile Solutions
    Sys Analyst and Development

    #2
    Hey Roger,

    You could use WMI.
    See wmi info
    with the following parametres...

    Win32_TimeZone
    : Bias in minutes, ex.: -300 (min) = -5 (hour)
    : DaylightBias in minutes

    Also interesting:
    Win32_SystemTimeZone
    Win32_CurrentTime
    Win32_LocalTime
    Win32_UTCTime

    Comment


      #3
      Lots of code there...is all of that required just to get timezone and DST Bias? I've never used WMI before.
      sigpic
      Mobile Solutions
      Sys Analyst and Development

      Comment


        #4
        I found this Script Online:

        Code:
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
        For Each objItem In colItems
          WScript.Echo "Current Time Zone (Hours Offset From GMT): " & (objItem.CurrentTimeZone / 60)
          WScript.Echo "Daylight Saving In Effect: " & objItem.DaylightInEffect
        Next
        What is needed for this in PB?
        sigpic
        Mobile Solutions
        Sys Analyst and Development

        Comment


          #5
          I guess the easiest way is to use José's WMI Wrappers Generator
          with the downloadable include "TB_WmiLib.inc" and you can come-up with something like this...

          Code:
          #COMPILE EXE '#Win 8.04#
          #DIM ALL
          #INCLUDE "WIN32API.INC" '#2005-01-27#
          #INCLUDE "TB_WmiLib.inc" 'Get it from [URL]http://www.com.it-berater.org/wmi.htm[/URL]
          '______________________________________________________________________________
           
          SUB WMI_Win32_ComputerSystem (OPTIONAL BYVAL sComputer AS STRING)
           LOCAL oServices         AS DISPATCH 'Services object
           LOCAL oItems            AS DISPATCH 'Generic collection object
           LOCAL oItem             AS DISPATCH 'Generic item object
           LOCAL vServices         AS VARIANT  'Services object reference
           LOCAL vItems            AS VARIANT  'Generic collection object reference
           LOCAL vItem             AS VARIANT  'Generic item object reference
           LOCAL vCount            AS VARIANT  'Number of items in the collection
           LOCAL vQuery            AS VARIANT  'Query string
           LOCAL vCurrentTimeZone  AS VARIANT  'Signed 16-bit integer
           LOCAL vDaylightInEffect AS VARIANT  'Boolean value
           LOCAL penum             AS DWORD    'Generic collection's enumerator reference
           LOCAL Looper            AS LONG     'Loop counter
           
           IF LEN(sComputer) = 0 THEN sComputer = "."
           IF WmiGetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\CIMV2", vServices) = %S_OK THEN
             SET oServices = vServices
             vServices = EMPTY
             IF ISOBJECT(oServices) THEN
               vQuery = "SELECT * FROM Win32_ComputerSystem" 'Execute a query to get a reference to the collection of objects
               OBJECT CALL oServices.ExecQuery(vQuery) TO vItems
               IF OBJRESULT = %FALSE THEN
                 SET oItems = vItems
                 vItems = EMPTY
                 IF ISOBJECT(oItems) THEN
                   OBJECT GET oItems.Count TO vCount 'Retrieve the number of items in the collection
                   IF Wmi_NewEnum(OBJPTR(oItems), penum) = %S_OK THEN 'Retrieve a reference to the collection's enumerator
                     IF penum THEN
                       FOR Looper = 1 TO VARIANT#(vCount) 'Iterate through the collection of objects.
                         IF WmiEnum_NextItem(penum, vItem) <> %S_OK THEN EXIT FOR 'Retrieve a reference to the next object in the collection
                         SET oItem = vItem
                         vItem = EMPTY
                         IF ISOBJECT(oItem) = %FALSE THEN EXIT FOR
                         OBJECT GET oItem.CurrentTimeZone TO vCurrentTimeZone 'Retrieve the values of the properties
                         ? "CurrentTimeZone  " & STR$(VARIANT#(vCurrentTimeZone) / 60)
                         OBJECT GET oItem.DaylightInEffect TO vDaylightInEffect
                         ? "DaylightInEffect " & IIF$(VARIANT#(vDaylightInEffect), "True", "False")
                         SET oItem = NOTHING 'Release the object
                       NEXT
                       WmiRelease penum 'Release the collection enumerator
                       SET oItems = NOTHING 'Release the collection object
                     END IF
                   END IF
                 END IF
               END IF
               SET oServices = NOTHING  'Release the Services object
             END IF
           END IF
           
          END SUB
          '______________________________________________________________________________
           
          FUNCTION PBMAIN() AS LONG
           
           WMI_Win32_ComputerSystem "." 'Use "." for current computer name
           
          END FUNCTION
          '______________________________________________________________________________
          Last edited by Pierre Bellisle; 8 Nov 2007, 03:55 PM.

          Comment


            #6
            Thanks, that is much easier to manage. Now I just have to figure out using it with the local call and making everything get in sync. My main need for this was determining if the Timezone is one that doesn't support DST and then not adjusting for it locally too when working with files from the remote machine.
            sigpic
            Mobile Solutions
            Sys Analyst and Development

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎