Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Script: MakeShare

Posted by on Saturday, March 13, 2004 (PST)

Script: Creates share on a local disk. Uses WMI, Win32_Share, Create.
Author: Dan Casier
/**  
*    Script:   MakeShare.js
*    Purpose:  Makes a share on a local disk
*    Author:   Dan Casier
*    Date:     7 march 2004
*    Web:      none
*    Note:     Administrator rights needed to run te script.
*              $-sign hides the share in the networkbrowser.
*              Copyright 2004 Dan Casier
**/
var FILE_SHARE = 0;
var Path="D:\\Users";
var shareName="Users$";
var objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
var objNewShare = objWMIService.Get("Win32_Share");
var errReturn = objNewShare.Create(Path,shareName,FILE_SHARE);
if (errReturn>0)
   {
     WScript.Echo(" Foldersharing failed :" + errReturn);
   }
else
   {
     WScript.Echo(" Folder " + "Path" + " is shared as " + shareName );
   }

Comments:

re
By mevo on Sunday, June 13, 2004 (PST)

This code is good, but

you have not setting the maximum number and adding a share description.

it may be ...

var FILE_SHARE = 0;
var MAXIMUM_CONNECTIONS = 25;
var Path="D:\\Users";

var shareName="Users$";

var objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");

var objNewShare = objWMIService.Get("Win32_Share");
var errReturn = objNewShare.Create(Path,shareName,FILE_SHARE, MAXIMUM_CONNECTIONS, "Public share for the Finance group.");

Reply to this Comment

Add Your Comment



WSH and ADSI Administrative Scripting

New Articles
  • List installed COM objects and associated ProgIDs
    Script: Lists all COM Objects and their associated ProgIDs (If available). Win32_ClassicCOMClassSetting

  • Script: File Rotator
    Script: Rotate files where the most current file has the lowest number in the archive. When files exceed the retention period, they are deleted. Typically used for log files, backups, etc..

  • Script: Create IIS Website and DNS record
    Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.


  • Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon