[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1744
  • Last Modified:

Batch Files

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.
1 Solution
glenwdriAuthor Commented:
O and can i redirect the location of My Documents to and new location on a differnt drive
Use NET TIME for the internet time.

[\\computername | /DOMAIN[:domainname] | /RTSDOMAIN[:domainname]] [/SET]
         [\\computername] /QUERYSNTP
         [\\computername] /SETSNTP[:ntp server list]
Could you explain exactly what you mean in your point No. (3) please.
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

glenwdriAuthor Commented:
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.
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.
QlemoC++ DeveloperCommented:
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 http://technet.microsoft.com/en-us/library/cc739464.aspx) to create connection profiles for distribution. This allows for set up of all credentials.
glenwdriAuthor Commented:
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.
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.
glenwdriAuthor Commented:
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
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.
glenwdriAuthor Commented:
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.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now