Solved

Create a vb script for net time on window server problem

Posted on 2013-11-15
9
891 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
ID: 39650582
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
ID: 39650597
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 70

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
ID: 39651643
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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

Author Comment

by:piaakit
ID: 39654743
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
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
ID: 39654751
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
ID: 39658244
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 70

Assisted Solution

by:Qlemo
Qlemo earned 417 total points
ID: 39658645
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
ID: 39658673
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 70

Accepted Solution

by:
Qlemo earned 417 total points
ID: 39658684
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

734 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