G
Guest
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 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