home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / wsh.cab / network.js < prev    next >
Text File  |  1997-09-16  |  4KB  |  111 lines

  1. // Windows Script Host Sample Script
  2. //
  3. // ------------------------------------------------------------------------
  4. //               Copyright (C) 1996 Microsoft Corporation
  5. //
  6. // You have a royalty-free right to use, modify, reproduce and distribute
  7. // the Sample Application Files (and/or any modified version) in any way
  8. // you find useful, provided that you agree that Microsoft has no warranty,
  9. // obligations or liability for any Sample Application Files.
  10. // ------------------------------------------------------------------------
  11. //
  12. // This sample demonstrates how to use the WSHNetwork object.
  13. // It reads network properties (username and computername), 
  14. // connects, disconnects, and enumerates network drives.
  15.  
  16. var vbOKOnly = 0;
  17. var vbOKCancel = 1;
  18. var vbYesNo = 4;
  19. var vbQuestion = 32;
  20. var vbInformation = 64;
  21. var vbCancel = 2;
  22. var vbYes = 6;
  23.  
  24. var L_Welcome_MsgBox_Message_Text   = "This script demonstrates how to use the WSHNetwork object.";
  25. var L_Welcome_MsgBox_Title_Text     = "Windows Scripting Host Sample";
  26. Welcome();
  27.  
  28. //////////////////////////////////////////////////////////////////////////////////
  29. // 
  30. //  WSH Network Object.
  31. // 
  32.  
  33. var WSHShell = WScript.CreateObject("WScript.Shell");
  34. var WSHNetwork = WScript.CreateObject("WScript.Network")
  35. var colDrives, SharePoint
  36.  
  37.  
  38.  
  39. function Ask(strAction){
  40.    // This function asks the user whether to perform a specific "Action"
  41.    // and sets a return code or quits script execution depending on the 
  42.    // button that the user presses.  This function is called at various
  43.    // points in the script below.
  44.  
  45.     var intButton
  46.     intButton = WSHShell.Popup(strAction,
  47.                                0,
  48.                                L_Welcome_MsgBox_Title_Text,
  49.                                vbQuestion + vbYesNo );
  50.     return intButton == vbYes;
  51. }
  52.  
  53. //////////////////////////////////////////////////////////////////////////////////
  54. // 
  55. //  Show WSHNetwork object properties
  56. // 
  57. // 
  58. WSHShell.Popup("UserDomain\t= " + WSHNetwork.UserDomain  +
  59.                "\r\nUserName\t= " + WSHNetwork.UserName  +
  60.                "\r\nComputerName\t= " + WSHNetwork.ComputerName,
  61.                0,
  62.                "WSHNetwork Properties",
  63.                vbInformation + vbOKOnly );
  64.  
  65. //////////////////////////////////////////////////////////////////////////////////
  66. // 
  67. //  WSHNetwork.EnumNetworkDrive
  68. // 
  69. // 
  70. //Ask user whether to enumerate network drives
  71. if (Ask("Do you want to enumerate connected network drives?")) {
  72.     //Enumerate network drives into a collection object of type WshCollection
  73.     var colDrives = WSHNetwork.EnumNetworkDrives();
  74.  
  75.     //If no network drives were enumerated, then inform user, else display 
  76.     //enumerated drives
  77.     if (colDrives.length == 0) {
  78.         WSHShell.Popup("There are no drives to enumerate.",
  79.                        0,
  80.                        L_Welcome_MsgBox_Title_Text,
  81.                        vbInformation + vbOKOnly );
  82.     } else {
  83.         strMsg = "Current network drive connections: \r\n";
  84.         for (i = 0; i < colDrives.length; i += 2) {
  85.             strMsg = strMsg + "\r\n" + colDrives(i) + "\t" + colDrives(i + 1);
  86.         }
  87.         
  88.         WSHShell.Popup(strMsg,
  89.                        0,
  90.                        L_Welcome_MsgBox_Title_Text,
  91.                        vbInformation + vbOKOnly );
  92.     }
  93. }
  94.  
  95. //////////////////////////////////////////////////////////////////////////////////
  96. //
  97. // Welcome
  98. //
  99. function Welcome() {
  100.     var WSHShell = WScript.CreateObject("WScript.Shell");
  101.     var intDoIt;
  102.  
  103.     intDoIt =  WSHShell.Popup(L_Welcome_MsgBox_Message_Text,
  104.                               0,
  105.                               L_Welcome_MsgBox_Title_Text,
  106.                               vbOKCancel + vbInformation );
  107.     if (intDoIt == vbCancel) {
  108.         WScript.Quit();
  109.     }
  110. }
  111.