Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create a vb script for net time on window server problem

Posted on 2013-11-15
9
Medium Priority
?
956 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 71

Assisted Solution

by:Qlemo
Qlemo earned 1668 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 332 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 71

Assisted Solution

by:Qlemo
Qlemo earned 1668 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

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 71

Assisted Solution

by:Qlemo
Qlemo earned 1668 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 71

Assisted Solution

by:Qlemo
Qlemo earned 1668 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 71

Accepted Solution

by:
Qlemo earned 1668 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

OfficeMate Freezes on login or does not load after login credentials are input.
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

971 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