Solved

Create a vb script for net time on window server problem

Posted on 2013-11-15
9
818 Views
Last Modified: 2013-12-12
Hi All


         How do i create a vb script for below,


net time \\server_name /set  /y
 

is below example correct ? i created and double it, it has error pop up, any idea ?

WSHShell.RUN "NET TIME \\10.0.0.7 /set/y",0,True


Keith
0
Comment
Question by:piaakit
  • 5
  • 3
9 Comments
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
Comment Utility
Why are you doing that in the first place? Within a domain, time sync is automated. Outside it is different, though, and you should rather use a scheduled task.

Anyway, you are missing the space between /SET and /Y in your VBS command.
0
 

Assisted Solution

by:rgnambiar
rgnambiar earned 83 total points
Comment Utility
Try this:

CreateObject("WScript.Shell").Run _
  "%comspec% /c net time \\servername /set /yes"

where servername is the name of the computer you want to synchronize with.
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
Comment Utility
No comspec necessary! NET is a stand-alone executable, and can run without starting
cmd.exe. Using cmd.exe makes sense if you need to review the result in cmd prompt window (by using %comspec% /k then). But the other stuff is true:
CreateObject("WScript.Shell").Run ("net time \\10.0.0.7 /set /y")

Open in new window

0
 

Author Comment

by:piaakit
Comment Utility
Hi Qlemo


                Normally a client pc which has joined domain, the time will be sync with server, but in my case, for those pc who is joined the domain in remote site, some pc time just not the same 10 mins behind, for those pc they dont have admin right (power user right) , will this not affect the time sync i think, what i need to do is manually remote those pc and run net time /setsntp:time_server , thats why i would like to create a vb scripts and put it on GPO, any better ideas ?


Keith
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
Comment Utility
If you set the SNTP server once per GPO, you should be fine. You could also use a public time service instead of a domain controller, and that would allow for automated sync. In any case the local time service should be set up to do the sync, without any manual intervention. That is, w32tm needs to have the proper setup.
0
 

Author Comment

by:piaakit
Comment Utility
in window GPO is there one for sntp server ? or i need to manually create a vb script  for that ?  if need to create a vb script, is below details in vb script would be enough ? if i want to create a vb script with sync external time, how do i write in vb script ?




CreateObject("WScript.Shell").Run ("net time \\servername /set  /y")
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
Comment Utility
That script makes a one-time sync only, so is required to be called periodically (by a Scheduled Task).

Again, a much better option is to set the time source to a common Internet time source, with the command you already suggested. Time difference should be negligible (below a few seconds). You only need to set that up once, and time sync should happen automatically, as long as the W32Time service runs.
Example: net time /setsntp:time-nw.nist.gov
List of some public SNTP servers: http://tf.nist.gov/tf-cgi/servers.cgi
0
 

Author Comment

by:piaakit
Comment Utility
our DC has already done for setsntp time server with exteral time server, but i do not want to remote all the client computer to run this command, and suppose if the clients pc has joined the domain, time will be sync with DC, but i see some of the pc located in remote site who joined the DC, the time is around 20 mins slower,
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 417 total points
Comment Utility
The remote PCs probably are not able to sync because they are remote. You'll need the other time source stuff.
There is no way around that: Those PCs need to be nearly in sync, else Kerberos will not allow authentication (it is very picky about time skews). And you can get them in sync only if they do the sync with an external, public source. I'm pretty certain there is a GPO to set up the time source, you'll just have to find it.
But even then, the GPO might not be able to get applied because of authentication issues caused by the time offset ... But it is worth the try.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now