Jump to content
Sign in to follow this  
GoogleDude

Set Time of Networked computer as $var?

Recommended Posts

GoogleDude

How can I get the Time and or Date of a computer on my network and set the value as a $var?

I tried to use "$Time = RunWait("net time \\192.168.1.123") but it just returns a 0 stating that the command completed.

Thanks,

GD

Share this post


Link to post
Share on other sites
rasim

GoogleDude

$strComputer = "." ;remote computer name
$strResult = ""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LocalTime")

For $objItem In $colItems
    $strResult = "Year: " & $objItem.Year  & @LF & _
                 "Quarter: " & $objItem.Quarter & @LF & _
                 "Month: " & $objItem.Month & @LF & _
                 "WeekInMonth: " & $objItem.WeekInMonth & @LF & _
                 "DayOfWeek: " & $objItem.DayOfWeek & @LF & _
                 "Day: " & $objItem.Day & @LF & _
                 "Hour: " & $objItem.Hour & @LF & _
                 "Minute: " & $objItem.Minute & @LF & _
                 "Second: " & $objItem.Second
Next

MsgBox(0, "", $strResult)

MSDN

Share this post


Link to post
Share on other sites
GoogleDude

Thanks, Now I just have to figure out how to reformat $strResult so that it is in a format that can be set inside a StatusBar of my GUI.

Share this post


Link to post
Share on other sites
BrettF

Easy, just change the the str result string!

$strComputer = ".";remote computer name
$strResult = ""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LocalTime")

For $objItem In $colItems
    $strResult = $objItem.Month & "/" & _
            $objItem.Day & "/" & _
            $objItem.Year & " " & _
            $objItem.Hour & ":" & _
            $objItem.Minute & ":" & _
            $objItem.Second & "(MM/DD/YYYY HH:MM:SS)"
Next


MsgBox(0, "", $strResult)

Hope it helps!

:mellow:

Cheers,

Brett

Share this post


Link to post
Share on other sites
GoogleDude

Easy, just change the the str result string!

$strComputer = ".";remote computer name
$strResult = ""

$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_LocalTime")

For $objItem In $colItems
    $strResult = $objItem.Month & "/" & _
            $objItem.Day & "/" & _
            $objItem.Year & " " & _
            $objItem.Hour & ":" & _
            $objItem.Minute & ":" & _
            $objItem.Second & "(MM/DD/YYYY HH:MM:SS)"
Next


MsgBox(0, "", $strResult)

Hope it helps!

:mellow:

Cheers,

Brett

It does. Thanks. I think I can achieve my goal with your above sample.

Thanks,

GD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.