Friday, February 22, 2019
Vbscript Network Shares Lab
VBScript net income Shares Lab Objectives In this lab, students ordain complete the following bearingives. * Create a VBScript political weapons platform apply NotePad++. * employment WScript. Shell objective and its methods. * Use Scripting. FileSystemObject and its methods. * Use LanmanServer,FileService objects and its methods. * Use WScript. mesh object and its methods. Element K Network Connections For this lab, we pass on need to connect to vlab-PC1 and vlab-PC2. The computer vlab-PC1 is the computer on the left case while vlab-PC2 is on the right.If you leave the cursor on the PC painting for a few seconds, a tool-tip heart will appear indicating the hostname of the PC. outdoors vlab-PC1 and login as Administrator with the news password. Return to the mesh and devote vlab-PC2 and login as Administrator with the password password. Note All captures must be text onlyDO NOT capture the NotePad++ application window or the overleap prompt window. Use copy and paste of text only. trade union movement 1 NetShareServer. vbs Program on vlab-PC1 * On vlab-PC1, open NotePad++ and from the File menu, apportion New. Create a Programmer Header that includes the name of your VBScript file, your name, the date, the class, and the name of your professor. all(prenominal) of these VBScript comment lines mystify with a () character. * From the File menu, select cede. Save your course as NetShareServer. vbs in the CScripts leaflet as shown below. * Define the Scripting. FileSystemObject fso that provides affirm of local leaflets and files. The WinNT//hostname/LanmanServer,FileService object fileServ allows us to do and manage network contends comparable to the NET touch commands we discussed stopping point week.Note When you create the fileServ object, the hostname value vlab-PC1 must see the hostname of the computer acting as the server. If you dont k like a shot your Windows hostname, open a Windows command line interface and execute the host name command. Task 2 Create a Folder and Copy Files to the New Folder * Use the fso. CreateFolder( ) to create the folder C humanity. The path and name of the folder to be created is place indoors the parentheses and delimited with double quotes. * Use the fso. CopyFile method to copy all files in the CWindowsCursors folder that start with the letter w to the C in the public eye(predicate) folder.There are no parentheses used for this method. The syntax for this method is Note The basic argument is the file/s to be copied and second argument ( afterwards the ,) is the finish folder. * Skip several lines and commemorate the following statements. The WScript. Echo statement exactly outputs a bare-ass line and announces the end of the computer political programme. * Save your program (S). barrack the function signalise and enter cscript NetShareServer. vbs. Click OK to execute your program. * down the stairs is the run of the program. It should run without errors although it does not produce either output.Check to see if the program successfully created the C in the public eye(predicate) directory and copied the files from the CWindows directory by clicking in the NotePad++ cabinet window and entering the command dir CPublic as shown below. You could besides open the Windows CLI and execute the same command to test your script. * Go to the command line or Windows Explorer to verify that CPublic folder has been created and populated with some files. If you have any problems with the RUN, delete the CPublic folder if it exists in Windows Explorer and re-run the script from the Windows CLI using cscript.Check your VBScript program for errors, make the needed changes, delete the CPublic folder if it exists, and run the program again. Task 3 Display Current Network Shares and Create New Share * Skip a line after the fso. CopyFile line and enter the following program lines. * WScript. Echo vaunts a depicted object to the console windows or desktop. The F or Each Next spiral is used to display all of the current network administers on the local computer. From the Windows CLI, the NET SHARE command would display the same information. Note The For Each Next loop is a special For loop used to access the elements or comp binglents in an array.The fileServ object contains an array name( ) that contains all the current network shares fileServ. name(0) .. fileServ. name(n) where n is the last index in the array. * Within a VBScript program, you need to use the LanmanServer,FileService object to create a new network share. Enter the following lines to share the CPublic folder with the share name PublicData. Note where the share name and folder path go in the following commands. MaxUserCount sets the upper limit simultaneous connections allowed for this share. After we have created the new share, we necessitate see if the new PublicData share has been added.Type the following code to view the current shares again. The WScript. Echo vbCrLf command displays a blank line. * Save your program (S). Press the function key and enter cscript NetShareServer. vbs. Click OK to execute your program. You should live an error marrow as shown below because the folder you are trying to create now already exists. * * Add a new line just in a higher place the fso. CreateFolder( ) line with this statement On Error Resume Next. This statement will ignore noncritical errors and allow the program to continue. * * Save your program (S) and shrink the function key and enter cscript NetShareServer. vbs. Click OK to execute your program. You should get a run in the console windows similar to the one below. avow that the new network share PublicData has been created. Note If you have errors and need to re-run the program at this point in the development, you may see the PublicData share in both the Current and New Shares because the share may still be valid from your earlier run. Task 4 Add Time Delay, efface PublicData Share, and take C Public Just above the End of Program message, add the following code. The WScript. Sleep(60000) will pause the script for 60 seconds (or 60,000 milliseconds). The fileServ. Delete and fso. DeleteFolder methods will delete the Network Share and delete the CPublic folder and the files it contains. * Save your program (S) and press the function key and enter cscript NetShareServer. vbs. Click OK to execute your program. You should get a run in the NotePad++ console window similar to the one shown on the next page. live until you see the End of Program after the 60-second delay.Copy and paste your NetworkShareServer program sourcecode from NotePad++ and your get off from the NotePad++ Console or the Windows CLI RUN into the spaces provided in your lab-report document. Task 5 NetShareClient. vbs Program on vlab-PC2 * Leave vlab-PC1 open and return to the Network draw and select vlab-PC2. If it isnt labeled, it will be the computer on the right. * one time the vlab-PC2 computer opens , log in as Administrator with a password of password. Cascade the two computer windows, so you erect go easier from one computer to the other as shown below. Open NotePad++ on vlab_PC2 and create a Programmer Header that includes the name of your VBScript file, your name, the date, the class, and the name of your professor. Each of these VBScript comment lines begin with a () character. Save your program as NetShareClient. vbs. Task 6 map the Shared Folder to X and Display Files * You will need to create Scripting, FileSystemObject called fso to display the files in the mapped drive. The WScript. Network object networkObj actually does the mapping and unmapping of the network share to drive X. The UNC notation network share we want to access is vlab-PC1PublicData. Keep in mind that the network share PublicData can be anywhere on the network and is not typically a local share. The networkObj. MapNetworkDrive method is used to map the network share on vlab-PC1 to X drive on vlab-PC 2. The Set folder = fso. GetFolder(X) creates a folder object for the mapped X drive. * The line Set files = folder. Files creates files collection object that contains all of the files in the X folder. The For Each loop sequences through the items in the files collection object and displays those files.Type in the code shown on the next page. * Save your program (S) and complete the remaining VBScript code that will display the content of the mapped drive X, unmap the mapped drive X and end the program with the message End of Program. * Check your NetShareClient. vbs program for errors and save it using S. Task 7 Final Run of NetShareServer and NetShareClient * Return to vlab-PC1 and start the NetShareServer. vbs program running with . As soon as the vlab-PC1 NetShareServer. vbs program is running, quickly return to vlab-PC2 and start the NetShareClient. vbs program with .Remember, you only have 60 seconds after you have started the NetShareServer program to successfully run the N etShareClient program. * If you do not get the output shown above, for the NetShareClient. vbs program. Correct any errors and re-save your program. Run the NetShareServer program again on vlab-PC1 and run the corrected NetShareClient program on vlab-PC2. Copy and paste your NetShareClient program sourcecode from NotePad++ and your NotePad++ console run (or Windows CLI run) into the spaces provided in your lab-report document. Submit your completed lab-report document to the iLab Dropbox for this week.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.