Solved

Create a vb script for net time on window server problem

Posted on 2013-11-15
9
843 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 69

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 69

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
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.

 

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 69

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 69

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 69

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

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...
A safe way to clean winsxs folder from your windows server 2008 R2 editions
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…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

825 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