1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Dim objWMIService, nResult
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & shareserver & "\root\cimv2" )
'-- create a local folder
nResult = CreateLocalFolder(objWMIService, sharepath)
If (nResult <> 0) Then
Err.Raise 1, "Local folder creation error = " & nResult
Exit Sub
End If
'******************************************************************
' CreateLocalFolder - creates a new local folder
' ----------
' objWMIService - WMI serice instance
' sharepath - path to local folder, for ex.: "C:\MyFolder"
' ----------
' return value - Error code. O for OK
Function CreateLocalFolder(ByRef objWMIService, ByVal sharepath)
Dim objProcess, nProcessId, nResult
Set objProcess = objWMIService.Get("Win32_Process")
' --- try to start a process for a folder creation
nResult = objProcess.Create("cmd.exe /c md " & sharepath, Null, Null, nProcessId)
If (nResult <> 0) Then
CreateLocalFolder = nResult
Exit Function
End If
Dim arrItems, objItem, boolFound
' --- wait for folder creation completion
Do While (True)
Set arrItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId=" & nProcessId)
boolFound = False
For Each objItem In arrItems
boolFound = True
Exit For
Next
If (boolFound = False) Then Exit Do
Loop
CreateLocalFolder = 0
End Function |
Partager