darkleton Posted September 12, 2011 Posted September 12, 2011 On our old server 2003 server I had the following code that would remotely share a folder and set its permissions. Now on server 2008 r2 its not working and I can't figure out why $FILE_SHARE=0 $MAXIMUM_CONNECTIONS=-1 $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $datacomp & "\root\cimv2:Win32_Process") $Locator=ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $Locator.ConnectServer($datacomp, "\root\CIMV2") $objNewShare = $objWMIService.Get("Win32_Share") $objNewShare.Create('"' & "F:\Home Directories\Users\" & $username & '"', $username & "$", $FILE_SHARE, $MAXIMUM_CONNECTIONS, "Share for " & $username) Is there anything I'm missing, or is there another way? I also tried using rmtshare.exe but that has to be run directly on the server, not remotely any help would be greatly appreciated
darkleton Posted September 12, 2011 Author Posted September 12, 2011 Nevermind, I actually got it to work in the end using WMI to remotely run a cmd prompt and do rmtshare.exe Could a MOD delete this if they are available, as the issue is resolved for my needs. Sorry!
UEZ Posted September 12, 2011 Posted September 12, 2011 (edited) This one worked for me with Win2k8 R2! It will share c:temp: Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler") $host = "localhost" $ret = WMI_CreateShare($host, "C:\temp", "UEZ") Func WMI_CreateShare($host, $path, $username, $file_share = 0, $max_connections = -1, $usr = "", $pass = "") ;coded by UEZ 2011 Local $ping = Ping($host, 1000) If @error Then SetError(1, 0, -1) Local $aResult[1000][3], $i = 1 Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") If @error Then Return SetError(2, 0, 0) Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2:Win32_Process", $usr, $pass, "", "", 0x80) If @error Then Return SetError(3, 0, 0) Local $objNewShare = $objWMIService.Get("Win32_Share") If IsObj($objNewShare) Then Local $rmtshare = $objNewShare.Create($path, $username & "$", $file_share, $max_connections, "Share for " & $username) If Not $rmtshare Then Return SetExtended($rmtshare, True) Return SetError(5, $rmtshare, 0) EndIf Return SetError(4, 0, 0) EndFunc Func ObjErrorHandler() ConsoleWrite( "A COM Error has occured!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _ "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _ "err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _ "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _ "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _ ) EndFunc Br, UEZ Edited September 12, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now