Guy's Scripting Ezine - 97 Net Time /setsntpContents for Ezine 97 - Net Time /setsntpIntroduction to 2006 EzinesThe New Year is a classic time for fresh initiatives, coupled with reflections on the previous 12 months. As far as this ezine is concerned, the new initiative is a 10 part series specializing in the basis and basics of VBScript. As far as looking to the past, I just want to say that this ezine will continue with the twin aims of providing working script examples, while giving general learning points to help you adapt my scripts to your environment. Occasionally, I will feature CSVDE, LDIFDE or DS Services. The other reason to retain your free ezine subscription is that I send out complimentary ebook whenever I write a new ebook, or update an existing one.
♣ This Week's SecretAbout five years ago, when this site was just a few pages, I noticed that the Logon Script page had more hits than all the rest of the pages added together. Realising the interest in VBScript for Windows, I developed a whole scripting section. Two years ago, I started this ezine primarily as a way of giving those who bought my ebooks an after sales service. From the first ezine, my specialty has been getting people started. So for the next ten editions I am going to concentrate on the basics of VBScript. I will be choosing real world examples for you to copy and paste, but my real objective is to explain how scripts are put together. In particular, I want to explain which elements of the script you can and should change, and which elements are fixed terms have fixed names that you should learn, apply, but never change. This Week's MissionThis Week's Mission is to configure your machine to synchronize with an internet time server. Trust me, accurate time is important on a server. As yet, no-one can explain to my satisfaction, why left to its own devices, my $1,000 computer regularly loses nearly a minute every week. Especially when my 10 year old, $5, 'Mickey Mouse' watch keeps perfect time. Theory that it's helpful to know.
Important Scripting PrincipleIf we look at the big picture, then we realize that almost all scripts mimic actions that you can perform manually. The secret of success is to perfect the manual steps then convert them to lines of VBScript code. In this instance we want to create a cmd session by: Clicking on the Start Button, typing: run, cmd. From the black 'dos box', we now type, net time /? to check the switches. Try: net time /querysntp. I was surprised that Windows Server 2003 returned time.windows.com, 0x1, as its time server. We want to change this to an internet time server such as: time-a.nist.gov. The crucial command is: net time /setsntp:time-a.nist.gov Pure Scripting Learning PointsWe have established the need for a command shell, which will run our net time instructions. Therefore, we create turn to our VBScript skills and create a shell object called objShell. The instruction is: objShell=CreateObject("Wscript.Shell"). My learning point is that you can call this object zpv23K instead of objShell. However, VBScript would not understand makemeobj("Wscript.Shell"), it has to be precisely, CreateObject("Wscript.Shell"). WScript is VBScript's underlying program or host, more of that another time, suffice to say that here we specify a .Shell type of object. In other scripts we will create .Network objects, which support different WScript properties or 'handles'. The focal point of our script is ObjShell. We will utilize two of its methods, .Run to create a cmd session and .SendKeys to mimic keystrokes that we enter at the cmd prompt. I also use the .Sleep method, principally to tell the script to wait, so that I can see what is happening. Such scripts rarely work perfectly first time and I need to see if the instructions are going according to plan. Note: Both .SendKeys and .Sleep are interesting and useful for learning or applying 'sticking plaster' to broken scripts, however, in production scripts seek alternative methods. As you get to know me, you will realise that I have an addiction to WScript.echo messages. Many readers say that I am obsessed with calling for WSH boxes to confirm that my code has produced action. What I reply is that in production scripts, or if the messages annoy you, just ' Rem out the WScript.echo lines using a ' single quote. Guy Recommends:
The Free IP Address Tracker (IPAT)
| |||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |