|
|
|
start date: Wed, 15 Aug 2007 07:34:00 -0700,
posted on: microsoft.public.dotnet.academic
back
| Thread Index |
|
1
Liam Mac
|
|
2
pvdg42 am
|
Having trouble creating shared and setting permission using vb.net
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
Date:Wed, 15 Aug 2007 07:34:00 -0700
Author:
|
Re: Having trouble creating shared and setting permission using vb.net
"Liam Mac" wrote in message
news:25C7B23D-8AD8-4C9D-A743-3B96CF85192F@microsoft.com...
> 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
Date:Wed, 15 Aug 2007 14:02:24 -0500
Author:
|
|
|