Microsoft Windows Script Basics

I need some basics for Microsoft Windows Script language.  I need to write a very simple script which I could do in MS DOS batch commands.  I would rather use something a little more capable and newer.  Here is what I need to do:
  Ask user question and use answers to make decision
  Copy files
  May need to get user's name or machine name
  Test for the presents of files

I need this script to do the following:  
  Run on user's Win2000 standard machine without having to load any compilers, etc.
  I'm not sure how many different version of scripting languages are available but I need the easiest to use.

I need an example and how to prepare it for the user (compile, etc.)
schmir1Asked:
Who is Participating?
 
Lee W, MVPConnect With a Mentor Technology and Business Process AdvisorCommented:
@echo off
:SetChoice
Echo Do you want to copy (F)ront-end only or (B)oth Front and Back End?
Echo NOTE - if you copy the back-end, any test data you have generated will be overwritten!!!
set /p copychoice=Enter "F" for Front-End Only; "B" for Front and Back-end:
REM Checks to see if the user entered "B" or "F".  Any other entry results in a loop back to ask the question again.
If "%copychoice%" == "B" Goto CopyBoth
If "%copychoice%" == "F" Goto CopyFront
Goto SetChoice

:CopyBoth
REM Copies the backend.file from a place on a network share to a place on the local computer,
REM surpressing any prompts to overwrite
copy /y \\server\share\path\backend.file X:\Path\backend.file
REM A failed copy should result in an Errorlevel = 1.  We'll check for this in a couple of lines.
REM Sets a variable with information about where the error occurred - IF it occurs at all
Set ErrNote=Back-end
REM Check for a failed copy (likely because the file was open).  If it was, goto the FileOpened section
If "%errorlevel%" == "1" Goto FileOpened

:CopyFront
REM Copies the frontend.file from a place on a network share to a place on the local computer,
REM surpressing any prompts to overwrite
copy /y \\server\share\path\frontend.file x:\path\frontend.file
REM A failed copy should result in an Errorlevel = 1.  We'll check for this in a couple of lines.
REM Sets a variable with information about where the error occurred - IF it occurs at all
Set ErrNote=Front-end
REM Check for a failed copy (likely because the file was open).  If it was, goto the FileOpened section
If "%errorlevel%" == "1" Goto FileOpened
REM If no error, the script completed.  Goto the end section of the script.
Goto End

:FileOpened
REM Determines whether it was the front end or back end that caused the error,
REM based on the ErrNote variable we set earlier.
If "%ErrNote%" == "Front-end" If "%CopyChoice%" == "B" Echo Back-end copied; Front-end found in use.
Echo %ErrNote% file in use.  Close the database and rerun this file.

:End
REM The next two lines create variables for creating the timestamp, including date and time.
For /f "tokens=2" %%a in ('date /t') do Set DateStamp=%%a
For /f "tokens=1 delims=" %%a in ('time /t') do Set TimeStamp=%%a
REM Appends the attempt to run the script as well as the options selected by the user
REM to the file log.file in some path specified by you.  ">>" are important - using a single
REM ">" every time will result in the log file being overwritten every time it's written to.
Echo %DateStamp% %TimeStamp% - %copychoice% - %username% - %errnote% >> x:\path\log.file 2>>&1
REM Cleans up the environment variables we created.
Set ErrNote=
Set CopyChoice=
Set DateStamp=
Set TimeStamp=
0
 
Yan_westCommented:
Check out microsoft script center:

http://www.microsoft.com/technet/scriptcenter/default.mspx

everything you need is in there..

0
 
Yan_westCommented:
If you click on "browse repository", you will find ALL the scripts you need in different categories..
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Lee W, MVPTechnology and Business Process AdvisorCommented:
You can do all of what you ask with a DOS-based script.

set /p variable=question
%username% is a system variable for who is logged on.
%computername% is a system variable for which computer the script is running on
if exist "filename.ext" dosomething - would test for the presence of a file.
copy/robocopy (reskit)/xcopy can be used for file copies

No compilers to load or third party applications or even resource kit utils (except if you choose to use Robocopy).

If you can post exactly what you need this script to do, someone here - including myself - can probably write it for you.  (I'll be out for a couple hours so it might not be me).
0
 
DanGilbertTXCommented:
I would use the built-in Windows NT Scripting Language. It is much more powerful than most people think. Like Leew said, don't have to load any third party stuff and it works on Win9x and WinNT already, not to mention Win2k and higher. So, post up what you are your variables are and we will see what kind of script we can churn out.
0
 
schmir1Author Commented:
DanGilbertTx

Is the built-in Windows NT Scripting Language different then the Batch Language.  Do I put the commands in a file with a .bat extension?

I need to be able to:
Ask the user: "Do you want to copy the Front-end only or both the Front and Back-end"
Note to user: "If you copy the back-end, any test data you have generated will be overwritten!!!"
Copy the files in overwrite mode.
If the files are opened (so the copy fails) then tell the user to close the Database and rerun this file.
Add a line to an existing file containing the username and timestamp.

That should do it.
0
 
DanGilbertTXCommented:
Wow, tough script. Ok, it may take a while to write this up. NT Scripting Language uses .bat or .cmd files. So, it is basically just an updated batch language from the DOS days. Has a lot more variables now though.
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
The script below should do what you are looking for - I have not tested it, but I'll explain it below.

----------8<-----------------------------
@echo off
:SetChoice
Echo Do you want to copy (F)ront-end only or (B)oth Front and Back End?
Echo NOTE - if you copy the back-end, any test data you have generated will be overwritten!!!
set /p copychoice=Enter "F" for Front-End Only; "B" for Front and Back-end:
If "%copychoice%" == "B" Goto CopyBoth
If "%copychoice%" == "F" Goto CopyFront
Goto SetChoice
:CopyBoth
copy /y \\server\share\path\backend.file X:\Path\backend.file
Set ErrNote=Back-end
If "%errorlevel%" == "1" Goto FileOpened

:CopyFront
copy /y \\server\share\path\frontend.file x:\path\frontend.file
Set ErrNote=Front-end
If "%errorlevel%" == "1" Goto FileOpened
Goto End

:FileOpened
If "%ErrNote%" == "Front-end" If "%CopyChoice%" == "B" Echo Back-end copied; Front-end found in use.
Echo %ErrNote% file in use.  Close the database and rerun this file.

:End
For /f "tokens=2" %%a in ('date /t') do Set DateStamp=%%a
For /f "tokens=1 delims=" %%a in ('time /t') do Set TimeStamp=%%a
Echo %DateStamp% %TimeStamp% - %copychoice% - %username% - %errnote% >> x:\path\log.file 2>>&1
Set ErrNote=
Set CopyChoice=
Set DateStamp=
Set TimeStamp=
----------8<-----------------------------
0
 
DanGilbertTXCommented:
Nice script. Just took a quick glance at it, but damn nice. Give that man some points. Sorry I didn't get to it sooner. Had some errands to run.
0
 
schmir1Author Commented:
I could has sworn that I had put a comment in early.

Anyhow, thank for the script.  Looks very detail.  I'm not going to get a chance to try it right away (big push on another project) so I'm going to close this question.  Looks like it will do just what I want and I will be using it (probably in a week or two).

Thanks for you help.
0
All Courses

From novice to tech pro — start learning today.