HighTechTalks DotNet Forums  

Having trouble creating shared and setting permission using vb.net

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Having trouble creating shared and setting permission using vb.net in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?TGlhbSBNYWM=?=
 
Posts: n/a

Default Having trouble creating shared and setting permission using vb.net - 08-15-2007 , 10:34 AM






Hi Folks,

I have embeded WMI scripting within a Visual Basic application to create
remote shares and set permissions, I'm now moving to vb.net environment and
having trouble getting my scripting to work, I have search the net for vb.net
code to create shared folders and set permsission but no joy, if anyone can
help or recommend good web sites on this or is there anyway I can get my
exisiting code to work in vb.net please see code below that works.

Thanks,
Liam

Private Function Create_Share_and_Set_Permissions(strGCN As String,
strServerName As String, strShortCourseCode As String, strDriveLetter As
String)


Set WshShell = CreateObject("Wscript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Set objFS = CreateObject("Scripting.FileSystemObject")


strFullPath = strDriveLetter & ":\" & strShortCourseCode & "\" & strGCN
strMapName = strServerName & "\" & strGCN & "$"


Me.txtStatus.Value = "Creating Student X Drive"
Me.txtAlert.Value = "Path for X Drive:" & strFullPath

' creating the folder on a remote machine


Set objWMIService = GetObject _
("winmgmts:\\" & strServerName & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create _
("cmd.exe /cmd " & strFullPath & "", Null, Null, intProcessID)

subDelay (5)
Me.txtStatus.Value = "Setting Share Permissions on Student X Drive"
Me.txtAlert.Value = ""


' setting the sharing of a folder

Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25


Set objWMIService = GetObject _
("winmgmts:\\" & strServerName & "\root\cimv2")

Set objNewShare = objWMIService.Get("Win32_Share")

strShareName = strGCN & "$"
errReturn = objNewShare.Create("" & strFullPath & "", "" & strShareName &
"", FILE_SHARE, MAXIMUM_CONNECTIONS, "X Drive")

subDelay (3)

'strUser = "l00069029"
DisconnectDrive
MapDrive
USER_ROOT_UNC = "T:\"

Call WshShell.Run("cacls " & USER_ROOT_UNC & " /e /g CS SysAdmin:F",
HIDE_WINDOW, WAIT_ON_RETURN)
Call WshShell.Run("cacls " & USER_ROOT_UNC & " /e /g " & strUser & ":C",
HIDE_WINDOW, WAIT_ON_RETURN)


Set WshShell = Nothing
Set fso = Nothing
Set WshNetwork = Nothing


Reply With Quote
  #2  
Old   
pvdg42
 
Posts: n/a

Default Re: Having trouble creating shared and setting permission using vb.net - 08-15-2007 , 03:02 PM







"Liam Mac" <LiamMac (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi Folks,

I have embeded WMI scripting within a Visual Basic application to create
remote shares and set permissions, I'm now moving to vb.net environment
and
having trouble getting my scripting to work, I have search the net for
vb.net
code to create shared folders and set permsission but no joy, if anyone
can
help or recommend good web sites on this or is there anyway I can get my
exisiting code to work in vb.net please see code below that works.

Thanks,
Liam

Private Function Create_Share_and_Set_Permissions(strGCN As String,
strServerName As String, strShortCourseCode As String, strDriveLetter As
String)


Set WshShell = CreateObject("Wscript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Set objFS = CreateObject("Scripting.FileSystemObject")


strFullPath = strDriveLetter & ":\" & strShortCourseCode & "\" & strGCN
strMapName = strServerName & "\" & strGCN & "$"


Me.txtStatus.Value = "Creating Student X Drive"
Me.txtAlert.Value = "Path for X Drive:" & strFullPath

' creating the folder on a remote machine


Set objWMIService = GetObject _
("winmgmts:\\" & strServerName & "\root\cimv2:Win32_Process")
errReturn = objWMIService.Create _
("cmd.exe /cmd " & strFullPath & "", Null, Null, intProcessID)

subDelay (5)
Me.txtStatus.Value = "Setting Share Permissions on Student X Drive"
Me.txtAlert.Value = ""


' setting the sharing of a folder

Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25


Set objWMIService = GetObject _
("winmgmts:\\" & strServerName & "\root\cimv2")

Set objNewShare = objWMIService.Get("Win32_Share")

strShareName = strGCN & "$"
errReturn = objNewShare.Create("" & strFullPath & "", "" & strShareName &
"", FILE_SHARE, MAXIMUM_CONNECTIONS, "X Drive")

subDelay (3)

'strUser = "l00069029"
DisconnectDrive
MapDrive
USER_ROOT_UNC = "T:\"

Call WshShell.Run("cacls " & USER_ROOT_UNC & " /e /g CS SysAdmin:F",
HIDE_WINDOW, WAIT_ON_RETURN)
Call WshShell.Run("cacls " & USER_ROOT_UNC & " /e /g " & strUser & ":C",
HIDE_WINDOW, WAIT_ON_RETURN)


Set WshShell = Nothing
Set fso = Nothing
Set WshNetwork = Nothing

I'd suggest the VB.NET group for this question, rather than this academic
group:

microsoft.public.dotnet.languages.vb




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.