INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Feedback
"...It's fun to see others going through the same stuff I did and be able to help. It's also a way for me to stay sharp and not lose the stuff I've learned..."
Geography
Where in the world do Tek-Tips members come from?
|
Microsoft: Windows Server 2000 FAQ
|
General Troubleshooting
|
Scripting for newbies: Batch Scripts
Posted: 23 Sep 03 (Edited 7 Jan 04)
|
Hello!
I recently helped a TT member with batch scripting. He had to previous experience of this and was new to IT - so after writting so much back in that post I thought that a FAQ on it may help other people in the same situation.
There are two major types of scripting used in a Windows networking enviroment. These are Windows Scripting Host (WSH) and Batch Scripts. WSH is a relativity new scripting technology that came out in Windows NT. Its a lot more powerful than Batch Scripts but is also a lot more complex. Also there are different version depending on the OS. A WSH script I use for installing printers and defaulting them for my clients (XP) will not work on my Windows 2000 Pro workstations! Batch Scripts are very easy. They are DOS based, therefore very easy to learn.
Every Administrator needs to know scripting. As powerful as Group Policies maybe in a Win2k enviroment, its not always enough.
OK, Well the only way that I learnt to do batch scripting is by learning DOS. Batch scripts are very, very basic scripts. For example I have a script that sends a message to three workstations telling them that a server will be restarting shortly, I would use the net send command. For example, if I wanted to do it manually I would go to Start - Run - "CMD". In the Command Window I would type in:
net send [name or IP of workstation] [message] (Then hit enter!) net send [name or IP of workstation] [message] (Then hit enter!) net send [name or IP of workstation] [message] (Then hit enter!)
Now if I wanted to do this automatically I would open up notepad and type in:
rem Informing users of server shutdown @ Echo Off net send [name or IP of workstation] [message] net send [name or IP of workstation] [message] net send [name or IP of workstation] [message]
rem End script
I would then go to Save As, change the file type to 'All Files' and save as 'shutdownmessage.bat'.
From now on, I just have to double click this file and it will do all the work for me!
Tools such as the "Net" command are probably used the most in Batch scripts. "Net" will provide you with power to stop/start services, send messages, map/delete network drive and install printers. Go to the Windows Command Prompt (Run - CMD) and type in net /?. This will show you how to use the net command.
Another useful script I use is XCOPY. I have a proxy server that provides its logs in a .log file format. Well to view the logs properly I need to import them into Access. Access doesn't import .log files but will .txt. So I use the following script to change them over!: (Note: The script is cut down. Otherwise it would have 90+ users!)
rem Script to copy .log file to same DIR but with .txt extension. @ Echo Off X: cd\AllegroSurf\Data\Auditx copy andis.log "andis.txt" /s /y xcopy richard.log "richard.txt" /s /y xcopy tony.log "tony.txt" /s /y xcopy julian.log "julian.txt" /s /y rem Script Ends
The "Rem" take tells Windows to ignore this line so that you can insert comments. "@ Echo Off" is a command to stop commands echoing. "X:" changes the drive to where the proxy is installed. "cd\allegrosurf\data\audit" changes the directory to where the files are kept and the "xcopy nameofuser.log "nameofuser.txt" /s /y" is the command to copy nameofuser.log to "nameofuser.txt". The "/s /y" are parameter switches. From memory they stop comfirmation I think. I then set the script to run using the Windows Scheduler every 5 mins. If you want to get a bit more techy type in "AT /?" at the Command Prompt and its a text based version of the Windows scheduler. May want to play with that.
The actual question asked was regarding logging users off at a certian time. Here was the actual response:
As your server is Windows 2000 you will need to install the SHUTDOWN.EXE application. Simply copy the application which is included in Windows XP and floating about on the Internet to your WINNT\SYSTEM32 directory. The below script will shutdown a remote workstation called SALES1 with a 60 second warning. There is a cusom message ("You logon session has expired..."):
rem Script to reboot sales1 with 60 second warning @ Echo Off shutdown -r -m \\sales1 -t 60 -c "Your logon session has expired. This workstation is shutting down." -f rem Script Ends
Parameters:
-r Tells Windows to do a restart -m Name of the remote machine -t How long the countdown is -c Custom messatge -f Forceful. System will close regardless of open applications
If you don't type in the -m and the name of the sales machine then the system will do it to the localhost. If you don't input a countdown then the system will start from 30 seconds, and if no custom message then the message will a default. Now save this file as a .bat and create a schedule for it. Either use the AT command(Go to CMD and type in AT /?) or Windows Scheduler. At the desired time the server will force all machines you have listed in the script to shutdown using the parameters of your script.
A handy script to have on your desktop is a cancel. The parameters are "shutdown -m \\computername -a" That will abort the reboot. Again, no computer name means it will work on the localhost only.
Good Luck! |
Back to Microsoft: Windows Server 2000 FAQ Index
Back to Microsoft: Windows Server 2000 Forum |
|
 |
|
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close