Google Custom Search

Wednesday, May 30, 2007

Create Windows network shares

This procedure can be used to share any windows folders with default permissions
This procedure accepts 3 parameters
-- @path - The path of the share folder
-- @sharename - The sharename to be given
-- @type - This accepts 2 vaules either to create or revoke if create a new share is created if revoke the share ie removed

Script:

create procedure windowsshare (@path varchar(200), @sharename varchar(50),@type varchar(10))
as
begin
declare @cmd varchar(100)
if lower(@type) = lower('create')
BEGIN
set @cmd = 'net share '+@sharename+'='+@path
print @cmd
exec master..xp_cmdshell @cmd,no_output
PRINT ' SHARE '+@sharename+' HAS BEEN CREATED SUCCESSFULLY'
end
ELSE
BEGIN
set @cmd = 'net share '+@sharename+' '+@path+' /delete'
exec master..xp_cmdshell @cmd,no_output
PRINT ' SHARE '+@sharename+' HAS BEEN REMOVED SUCCESSFULLY'
end
END

No comments: