Scripting Central--The Magnificent Eleven--November 3, 2006
In this issue, learn about 11 mini scripts that pack a punch despite their size and how to prevent those scripts from accidentally launching.
February 14, 2007
Perspectives
The Magnificent Eleven
This & That
Your Vote Counts!
Script Watch
An Easy Way to Prevent Runaway Scripts
Info To Go
Perspectives
by Karen Bemowski, [email protected]
The Magnificent Eleven
In "Favorite Tools and Favorite Articles" (http://www.windowsitpro.com/Articles/ArticleID/93888/93888.html), I mentioned that I'd narrow my list of favorite scripting articles to two and talk about them this month and next. My pick for this month is Dick Lewis' "Small Scripts Pack Power" (http://www.windowsitpro.com/Articles/ArticleID/49078/49078.html). In this article, Dick provides 11 mini scripts that perform a variety of focused tasks related to system security and stability. The scripts include:
GetHostsFileSize.bat, which lets you quickly spot machines that might have unusual HOSTS file entries
GetHotFix.bat, which lets you search your environment for a specific installed hotfix to verify that your automated or pushed updates are working correctly
GetLastUserFromReg.bat, which helps you identify users who are logging on using service or Administrator accounts
I've made this typically locked-down article available for public viewing so that you can check it out. To download the scripts in this article, simply click the "Download the Code Here" button near the top of the page.
This & That
Your Vote Counts!
Vote for the next "IT Pro of the Month!" Take the time to reward excellence to an IT pro who deserves it. The first 100 to cast their vote will receive a one-year print subscription to Windows IT Pro magazine - compliments of Microsoft. Voting only takes a few seconds, so don't miss out. Cast your vote now:
http://www.windowsitpro.com/go/itpromonth
Scripter's Toolkit
An Easy Way to Prevent Runaway Scripts
A script can perform numerous operations quickly, but that blinding speed can work against you if you launch a script accidently. A misplaced double-click can send a script into action, copying files, deleting users, or performing some other operation at warp speed. A runaway script can do considerable damage before you have the chance to cancel it.
One way you can prevent the accidental launching of a script is to add a .txt extension to its filename after you've executed the script. For example, the script DelOldFiles.bat becomes DelOldFiles.bat.txt. Adding a .txt extension defuses the danger of accidental launches but lets you keep the script's original filename and keeps the code intact for future reference and use. To use the script again, you just remove the .txt extension.
Although you can add the .txt extension manually, a simple one-line
Move %0 %0.txt
uses the Move command with %0--an argument-holding environment variable whose value is the script's pathname. By using %0 as the source parameter (i.e., a pathname that specifies the file's current location and filename) and %0.txt as the destination parameter (i.e., a pathname that specifies the file's new location and filename), you're appending the .txt extension to the filename while "moving" the script to the same location.
To use this Move command, you must place it at the end of your script. It must be the final line of code; any code after it won't execute. When you run the script, you must launch it with the extension specified. For example, when you run the script DelOldFiles.bat, you need to type
scriptsdeloldfiles.bat
on the command line. Typing only
scriptsdeloldfiles
will cause the Move command to fail.
Because you're changing the name of the .bat file while it's running, you'll likely receive the message, "The batch file cannot be found." Despite this message, the Move command will have successfully added the .txt extension.
If you're familiar with Windows shell scripting, you might be wondering why I didn't use the Rename command to add the .txt extension. To use this command to rename a file, you follow the syntax
Rename [drive:] [path] filename1 filename2
As this syntax shows, the Rename command requires the file's path to be stated only once. If you were to use the %0 argument-holding environment variable with the Rename command, you'd be specifying the path twice because %0 contains the complete pathname, thereby causing the command to fail.
Thanks to Dick Lewis for writing and sharing this tip.
Info To Go
Can disaster recovery planning create real value for your business beyond mere survival? Justify your investments in DR planning, and get real answers to your questions about how DR planning and implementation affect the financial performance of your organization. Make cost-effective decisions to positively impact your bottom line! Live event: Tuesday, November 14
http://www.windowsitpro.com/go/seminars/xosoft/drplanning/?partnerref=1101emailannc
How do you manage security vulnerabilities? If you depend on vulnerability assessments to determine the state of your IT security systems, you won't want to miss this Web seminar. Special research from Gartner indicates that deeper penetration is needed to augment your existing vulnerability management processes. Learn more today!
http://www.windowsitpro.com/go/seminars/coresecurity/vulnerability/?code=1101Emailannc
Learn all you need to know about code-signing technology, including the goals and benefits of code signing, how it works, and the underlying cryptographic and security concepts and building blocks. Download this complete eBook today--free!
http://www.windowsitpro.com/go/ebooks/codesigning?code=1101emailannc
Does your company have $500,000 to spend on one email discovery request? Join us for this free Web seminar to learn how you can implement an email archiving solution to optimize email management and proactively take control of e-discovery--and save the IT search party for when you really need it! On-demand Web Seminar
http://www.windowsitpro.com/go/seminars/symantec/itsearchparty/?partnerref=1101emailannc
Total Cost of Ownership--TCO. It's every executive's favorite buzzword, but what does it really mean and how does it affect you? In this podcast, Ben Smith explains how your organization can use virtualization technology to measurably improve the TCO for servers and clients.
http://www.windowsitpro.com/go/podcast/hp/virtualization/?code=1101emailannc
Is your email easily accessible, yet secure, in the event of an e-discovery request? With the phenomenal growth in email volume and the high cost of failing to comply with a discovery request, you can’t afford to lose any email. Download this free white paper and implement a strong email retention and management system today!
http://www.windowsitpro.com/go/whitepapers/Symantec/retention/?code=1101featwp
Uncover Essential Windows Knowledge Through Excavator
Try out the ultimate vertical search tool--Windows Excavator. Windows Excavator gives you fast, thorough third-party information while filtering out unwanted content. Visit http://www.winexcavator.com today!
Contact Us
About Scripting Central -- [email protected]
About product news -- [email protected]
About your subscription -- [email protected]
This email newsletter is brought to you by Windows IT Pro, the leading publication for IT professionals deploying Windows and related technologies. Subscribe today!
https://store.pentontech.com/index.cfm?s=1&promocode=eu205xfb
View the Windows IT Pro Privacy Policy.
http://www.winnetmag.com/aboutus/index.cfm?action=privacy
Windows IT Pro is a division of Penton Media, Inc. 221 East 29th Street, Loveland, CO 80538, Attention: Customer Service Department
Copyright 2006, Penton Media, Inc. All Rights Reserved.
Read more about:
ITPro TodayAbout the Author
You May Also Like