Batch Files

Posted on 2009-02-17
Last Modified: 2012-05-06
OK I am creating some batch files to shorten my setup on the various computers that I setup for the offices I work in. So I need to know a few things. 1) Is there away to change the internet time through command prompt. 2)Can I setup multiple dial-up connection through command prompt. 3) If i want to launch an app with a batch file in a localized file setting what would I put in. I know all this must seem like no big but it would be a huge help.
Question by:glenwdri

    Author Comment

    O and can i redirect the location of My Documents to and new location on a differnt drive
    LVL 21

    Accepted Solution

    Use NET TIME for the internet time.

    [\\computername | /DOMAIN[:domainname] | /RTSDOMAIN[:domainname]] [/SET]
             [\\computername] /QUERYSNTP
             [\\computername] /SETSNTP[:ntp server list]
    LVL 38

    Expert Comment

    Could you explain exactly what you mean in your point No. (3) please.

    Author Comment

    We have a modem pool that people vpn with can I want to add the connection lines using a batch file that will have the numbers and setting already put in for me.
    LVL 38

    Expert Comment

    Sorry, I should have quoted the point I was asking about. You explained (2).  I was interested in point (3) "launch an app with a batch file in a localized file setting".

    It's the "localized" expression I'm not sure of.  Local to what?  Do you mean running the applications from the workstation's hard drive and loading your own user-created settings from the workstation, rather than logging into the network server and running applications from the server using a roaming profile?

    What specific applications are you needing to run?  I ask this because applications store their settings in different ways, and may be launched using differing commands.
    LVL 67

    Expert Comment

    For point 2, it's easy if you omit the password. You can copy or append a set up rasphone.pbk to the client (%AllUsersProfile%\App Data\\Microsoft\Network\Connections\Pbk\rasphone.pbk).

    Or you use CMAK (see to create connection profiles for distribution. This allows for set up of all credentials.

    Author Comment

    O sorry bout that. I am running a setup program and i need the batch file to always launch the things from its local folder because it will be on a flash drive and moved to various other systems so its drive letter and path will change but not the files in its local folder.
    LVL 38

    Expert Comment

    Thank you for that glenwdri.  As you are running applications from a USB Flash Drive, you will probably find the following sites useful either now or at some future time:

    Most of the "portable" applications (ie. those that run only from their own directory without writing files or registry data to the host computer) make use of an *.INI (or *.XML or *.CFG) file in their own folder that configures the application as you have preset it to behave when launched.  Those that don't use external configuration files support command line switches and parameters to launch them in a certain way.

    In general, those programs that use *.ini files have the file named the same as the program *.exe, and the program will always look in its own folder for such a file when launched.  Some programs that support the use of *.ini files have to be told at the command line the name (and relative path, where the supporting files are in sub-folders) of the *.ini file.

    Unfortunately it isn't easy to provide general rules or guidance about what to put in your batch file, simply because each application that is capable of being run as a "portable" application uses different command line options.

    A good example of how to control program behaviour from the command line is the free image viewer and editor IrfanView:
    Install it and read "C:\Program Files\Irfanview\i_options.txt" to see what I mean.

    One handy thing to know about batch files is that the variable %0 stores the full path to the batch file.  Windows XP allows you to use the modified variable %~dp0 which will hold the full path to the folder containing the batch file, enclosed in " " and ending with a backslash, ie. the Current Directory.  %CD% will hold the full path to the folder containing the batch file, but without the trailing backslash.  Download and rename the attached *.txt file changing its extenson to *.bat or *.cmd then run it in various folders.  The screen output will demonstrate how variables can be used to store details relative to where the batch file is being run from.

    The reason I mention the above is that some programs may require you to specify the full path to something like a setup configuration file.  At the command line, you can sometimes use one of the variables demonstrated in the attached batch file to create the path.

    You are talking about running a setup program from a USB Flash Drive?
    The default behaviour of setup packages is to unpack the contents to the current user's %TEMP% folder and then run the installer using the directions in whatever setup configuration files are unpacked there (often *.ini or *.inf files).  It all depends what installer package yo have, and what software was used to compile it, but the common ones that use the Windows Installer (msiexec.exe) allow you to specify a "local" setup instruction file and/or *.ini file (eg. Microsoft Office).

    If you are talking about post-setup configuration using some kind of self-compiled setup package, then I would guess that the best way of configuring such an application would be by either:

    1. Including in the package one or more *.reg files exported from a computer where the application was configured to your liking, and then using the command to import the *.reg files to the registry:
    regedit path_to\filename.reg


    2. Using the REG command with the correct options and parameters to write directly to the registry.

    It's not really possible to embellish this general information because we don't know what applications you are intending to run or install from the flash drive.  Each one has different deployment or runtime options.

    Author Comment

    sorry I am not running the program when i say launch.  I am using a program called Windows Post Installer to Launch the installers for me and i need to know how to launch a batch file that will use it current (changes because this is the part on the flash drive) location and install, copies, changes setting on the system it is temporarily plugged into and then can go to the next computer to setup all its program from the same batch
    LVL 38

    Expert Comment

    Hmmm.  I downloaded the Windows Post Install Wizard a while ago with the intention of creating an "unattended" Windows XP SP3 DVD along with my common applications, but ended up using a mixture of nLite and manual editing.

    I sincerely hope I am not sounding dumb here if I have misunderstood your aim, nor do I wish to sound patronising in any way if I am correct in my assumption and you have misunderstood something, but isn't the whole concept of the "Windows Post Install Wizard" the provision of *.hta "wizard" interface that allows you to create sequential and unattended installations of selected programs or applications from setup source folders?

    The actual user interface allows you to create or modify JavaScript (*.js) configuration files without having to have programming skills that enable you to write them from scratch or edit them in a text editor.  After you finish and save your configuration settings, doesn't that same user interface then become the panel from which you either tick boxes to choose programs to install, or just let the timer run so that it makes a default selection and runs the setup sequences?

    That being the case, wouldn't you just need the command in a batch file to run WPI.HTA?  The default file association for the *.hta file type (on a Windows XP system and presumably also Vista) is:

    C:\WINDOWS\system32\mshta.exe "%1" %*

    So, if your batch file was in the root of the Flash Drive (assumed to be X: here, but the letter is only to give it a root) and your wpi.hta file was in the folder
    then the following command would launch wpi.hta using the program designed to open and run *.hta files in Windows:

    %SystemRoot%\System32\mshta.exe %CD%\WPI\wpi.hta
    %SystemRoot%\System32\mshta.exe %~dp0WPI\wpi.hta

    It doesn't work with a path (the 2nd part of the command ie. the parameter)that is relative to the batch file, eg.
    %SystemRoot%\System32\mshta.exe WPI\wpi.hta
    Mshta.exe needs to be told where the target file is, the the %CD% variable will always be the unquoted path to the folder from which the batch file is being executed.
    Avoid paths with spaces, but if unavoidable use quotes like this:
    %SystemRoot%\System32\mshta.exe "%CD%\My XP WPI\wpi.hta"

    It is highly probable that the batch file would still work, by virtue of the host computer's file association for the *.hta file type, if you just added this line:


    If you added START /WAIT  in front of a command (in this example the command to run mshta.exe, not the one immediately above this paragraph), the batch file would pause processing until you close the program called, and would then continue with other commands in the batch file.  This would be nonsensical where wpi.hta is concerned, but is useful to know for other purposes.

    To make it easy to run wpi.exe from CD, the authors have created a little Autorun.exe program that allows you to "Start WPI" or "Exit":
    (executable is autorun.exe).
    Accompanied by an autorun.ico and the following autorun.inf in the root of the drive, the CD would run to the little menu:


    If Autorun is enabled for Flash Drives on the host computer, then doing the same as for a CD will run the little menu on insertion.

    The FAQ and Help Files say this about where the latest version of WPI.HAT must reside on a drive, and also about the variables that may be used in the configuration scripts that load other configuration files or call setup packages:

    WPI can no longer be placed at the root of the CD. It must be at Least ONE folder deep on a standalone CD. (So just place the WPI folder at the root instead of having wpi.hta and the folders at the root.)

    With the above folder layout all your config entries should read like:

    It is because of the %wpipath% internal variable that you can create a completely standalone and autorunning CD that loads WPI.HTA and the setup commands can locate the packages.  When you build your setup scripts using the interface it (or you) adds commands that are relative to where wpi.hta resides.  The program allows the use of its own variables that force it to use paths relative to itself when loading configuration files and running automated and silent setup packages, so when run from CD or other removeable drive, you don't have to worry about drive letters when moving from one PC to another.

    More from the FAQ and Help:

    Command line uses of WPI:

    WPI supports the use of command line entries for selection of Options, Config files and time for even further customization of your WPI disks or setups.  Example:

    WPI.hta options=useroptions_mritter.js config=config_mritter.js check=Work timer=30

    If a path is not specified for the file, it will assume they are in the WPIScripts folder.  It will still check for:  WPI.hta Work 30
    Paths can be full (starting with a drive letter) or relative to WPI.hta (starting with '.\' or '..\') and must end in '.js'

    Spaces are supported ONLY if a path is provided and properly quoted: (config="c:\space in\file path.js")

    Command line arguments:

    This appears to allow you to have a number of custom scripts in the X:\WPI\WPIScripts folder, and be able to specify which to use at the command line.  I can only assume that you can use these parameters from an autorun.inf file and from a batch file in the root of the Flash Drive that tells mshta.exe to open wpi.hta.

    The following are internal variables which, along with the standard system variable %CD%, allow you to modify the wpi.hta command line parameters by starting off with the path to the containing folder or the root of the drive that folder is on:


    I hope this addresses your question properly and fully.

    Author Comment

    it does but in many cases there is not an option to do some task and many task the run in dos do not function properly in WPI I have been using it for months. In many cases when they make a an upgrade they break some code and some features that did work no longer work and visa versa. That is why I am using some batch files with WPI to get the desired result.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    737 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

    15 Experts available now in Live!

    Get 1:1 Help Now