Solved

Create a vb script for net time on window server problem

Posted on 2013-11-15
9
827 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
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 68

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
 

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 68

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 68

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 68

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 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 setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

862 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

21 Experts available now in Live!

Get 1:1 Help Now