Solved

Microsoft Windows Script Basics

Posted on 2004-10-04
10
149 Views
Last Modified: 2010-04-14
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.)
0
Comment
Question by:schmir1
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 15

Expert Comment

by:Yan_west
ID: 12220032
Check out microsoft script center:

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

everything you need is in there..

0
 
LVL 15

Expert Comment

by:Yan_west
ID: 12220036
If you click on "browse repository", you will find ALL the scripts you need in different categories..
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12220222
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
 
LVL 3

Expert Comment

by:DanGilbertTX
ID: 12220359
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
 

Author Comment

by:schmir1
ID: 12220855
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:DanGilbertTX
ID: 12221308
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
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 12222888
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
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 12222955
@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
 
LVL 3

Expert Comment

by:DanGilbertTX
ID: 12223337
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
 

Author Comment

by:schmir1
ID: 12361599
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

16 Experts available now in Live!

Get 1:1 Help Now