Last month, I showed you how to go from having an idea for a script to determining that script's requirements and writing the pseudocode. This month, I show you how to transform the pseudocode into a script and how to test this script.
You'll be creating the script ShareCapture.bat, which periodically captures share settings. Its output creates another script, RecreateShare.bat, which rebuilds shares if they disappear. Listing 1, page 2, contains a step-by-step explanation of what is occurring in ShareCapture.bat. You can download ShareCapture.bat from the Code Library on the Win32 Scripting Journal Web site at http://www.win32scripting.com. The downloadable version doesn't include the step-by-step explanation because this information would interfere with the script's execution. The Code Library also includes an example of RecreateShare.bat.
Transforming Pseudocode Tasks 1 and 2
After you write the pseudocode, you need to transform it into Windows NT shell scripting code. First, you need to write the code that captures the share information (i.e., pseudocode task 1). To accomplish pseudocode task 1, you use the basic Rmtshare command
Rmtshare \\work1
Next, you need to filter that command's output to remove the lines you don't want (i.e., pseudocode task 2). You must eliminate several lines, so let's begin by removing the lines that contain the administrative shares and the line that says the command completed successfully. To remove these lines, you use the Findstr command with two switches: . . .
A brilliant article, if only I could get it to work and I know it will. I couldn't get the piping of the rmtshare cmd to work. When I type the command with the /v, it just says <i>The command failed: 123.</i> If I leave the /v out, it just returns to a C:\> prompt with no command output.<br>
<br>
Piping works with all other commands apart from rmtshare it seems. I downloaded the rmtshare.exe and copied it my resource kit folder. I also tried it in the system32 folder on my Win2K server machine. I also tried this piping command on my Win2k prof machine same problem. Any ideas would be greatly appreciated.</p>
Stuart June 10, 2002