using WSH scripts in vb.net

G

Guest

Folks,

Not sure if this is the correct forum for this posting, but I'm banging by
head against the wall, I have been trying to use my WSH scripts in vb. net
environment but not having much joy. The script is to create a shared folder
and set permission. I have added all referneces to WSH and WMI refernce in
VS2005. Can anyone tell me what changes do I need to make to the below code
to work in VB.NET? or even direct me to code for creating remote shares and
set permission in vb.net, I'm amazed at how diffcult it is to get vb.net code
to do such a simple thing!!! This code works fine in VBA environment such
Access that I'm currently running in.

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

' 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)


' 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")

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)
 
R

Rad [Visual C# MVP]

Folks,

Not sure if this is the correct forum for this posting, but I'm banging by
head against the wall, I have been trying to use my WSH scripts in vb. net
environment but not having much joy. The script is to create a shared folder
and set permission. I have added all referneces to WSH and WMI refernce in
VS2005. Can anyone tell me what changes do I need to make to the below code
to work in VB.NET? or even direct me to code for creating remote shares and
set permission in vb.net, I'm amazed at how diffcult it is to get vb.net code
to do such a simple thing!!! This code works fine in VBA environment such
Access that I'm currently running in.

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

' 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)


' 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")

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)

Personally I would use windows scripting host as a last resort,
because almost all anti viruses will block it right from the start.
What anti virus do you use?
 
G

Guest

Rad said:
Personally I would use windows scripting host as a last resort,
because almost all anti viruses will block it right from the start.
What anti virus do you use?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top