potitpanda Posted June 11, 2008 Share Posted June 11, 2008 I want to detect the presence of Shared folders, and delete them before running actions in my script How can i do that Anyone can give me an example ? Thanks Link to comment Share on other sites More sharing options...
potitpanda Posted June 11, 2008 Author Share Posted June 11, 2008 Sorry this is the bad section of the forum to post this topic Anyone can delete this topic please ??? Thanks Potitpanda Link to comment Share on other sites More sharing options...
rasim Posted June 11, 2008 Share Posted June 11, 2008 (edited) potitpandaHi! Try this:expandcollapse popup$aShare = _NetGetShareList("") If @error Then Exit For $i = 1 To $aShare[0] ConsoleWrite("Deleting a " & $aShare[$i] & " share..." & @LF) RunWait(@ComSpec & " /c net share " & $aShare[$i] & " /delete", "", @SW_HIDE) Next Func _NetGetShareList($sComputer) Local $EntriesRead = DllStructCreate("int") Local $TotalEntries = DllStructCreate("int") Local $pBuffer = DllStructCreate("ptr"), $tBuffer $aRet = DllCall("netapi32.dll", "int", "NetShareEnum", _ "wstr", $sComputer, _ "dword", 0, _ "ptr", DllStructGetPtr($pBuffer), _ "dword", -1, _ "ptr", DllStructGetPtr($EntriesRead), _ "ptr", DllStructGetPtr($TotalEntries), _ "ptr", 0) If $aRet[0] Then Return SetError(1, $aRet[0], 0) $EntriesRead = DllStructGetData($EntriesRead, 1) Local $aRes[$EntriesRead+1]=[$EntriesRead] Local $SHARE_INFO_0 = DllStructCreate("ptr["& $EntriesRead &"]", DllStructGetData($pBuffer, 1)) For $i = 1 To $EntriesRead $tBuffer = DllStructCreate("wchar[256]", DllStructGetData($SHARE_INFO_0, 1, $i)) $aRes[$i] = DllStructGetData($tBuffer, 1) Next DllCall("netapi32.dll", "int", "NetApiBufferFree", "ptr", DllStructGetData($pBuffer,1)) Return $aRes EndFunc Edited June 11, 2008 by rasim Link to comment Share on other sites More sharing options...
potitpanda Posted June 12, 2008 Author Share Posted June 12, 2008 That's not OK... I explain I want to delete all the \\Server\Share on my local computer before activities of my script I want to delete all of the Shared resources visible with Net use Link to comment Share on other sites More sharing options...
smashly Posted June 12, 2008 Share Posted June 12, 2008 (edited) Crude and maybe should add some sort of filter to the query so you only delete the specific shares you want..This just deletes all shares on a local computer (well that's what it does my XP SP2 laptop).$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") $colShares = $objWMIService.ExecQuery("Select * from Win32_Share") For $objShare in $colShares $objShare.Delete NextCheersEdit: I pieced the above crude example together from info from Microsoft Technet - Storage - Shared Folders(just in case you were curious) Edited June 12, 2008 by smashly Link to comment Share on other sites More sharing options...
rasim Posted June 12, 2008 Share Posted June 12, 2008 smashlyI pieced the above crude example together from info from Microsoft Technet - Storage - Shared FoldersHi! Thank you for link. Link to comment Share on other sites More sharing options...
smashly Posted June 12, 2008 Share Posted June 12, 2008 Your welcome, I've been poking around there for the past couple of days. I never played with autoit and objects, but the basics of it seems simple enough. The biggest part is the error handling, it really bloats a simple 3 line script into 10 fold..lol Cheers Link to comment Share on other sites More sharing options...
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