sliceofpie Posted August 3, 2011 Posted August 3, 2011 Hello Everyone, Is there a way to find out if a selected folder is shared? From the command prompt I can run "NET VIEW \\LOCALHOST" which shows me the folders that are shared. I'm wondering if I can do this through AutoIT... so if I select a directory using TreeView, it first checks if the folder is shared over the network. Not quite sure if that's quite enough explanation. Anyhow, if someone can point me in the right direction I would really appreciate it!!! Thank you .. :)
PsaltyDS Posted August 4, 2011 Posted August 4, 2011 One way would be _Net_Share_ShareGetInfo() but that assumes you know the name of the share (it doesn't have to match the folder name).Better would be using the WinAPIEx.au3 UDF function _WinAPI_ShellGetFileInfo() to get the $tSHFILEINFO struct, and pull the "Attributes" field out of that, then check it for the SFGAO_SHARE bit. This way you can check a given folder without having to guess what the shared name might have been: #include <WinAPIEx.au3> Global Const $SFGAO_SHARE = 0x00020000 $sFolder = "C:\Temp" $tSHFILEINFO = DllStructCreate($tagSHFILEINFO) _WinAPI_ShellGetFileInfo($sFolder, $SHGFI_ATTRIBUTES, 0, $tSHFILEINFO) $iAttributes = DllStructGetData($tSHFILEINFO, "Attributes") If BitAND($iAttributes, $SFGAO_SHARE) Then ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; Shared!" & @LF) Else ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; NOT Shared!" & @LF) EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
sliceofpie Posted August 5, 2011 Author Posted August 5, 2011 PsaltyDS,Thank you for the great insight! This works great
PsaltyDS Posted August 5, 2011 Posted August 5, 2011 Glad it helped. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
BobboP Posted March 5 Posted March 5 I appreciate this is an old thread and so things have likely moved on since the original solution was supplied by @PsaltyDS. I'm trying to achieve the same result in identifying if a folder is shared or now, but have identified two issues now. 1. When i run the example script from @PsaltyDS without any other changes, it seems Global Const $SFGAO_SHARE = 0x00020000 is already declared in WinAPIEx.au3 and so it appears that I just need to remove this line. Is this simply due to changes in more recent versions of AutoIt than when this solution was proposed? 2. My main script currently needs to use Permissions.au3 by @FredAI, but it seems to have a conflict with WinApiEx.au3. Again not surprising as it seems the Permissions.au3 was written around 15 years ago! When i run the example script but include Permissions.au3, I receive a number of "previously declared as a 'Const'" errors relating to most of the "AccessMask constants". #include <WinAPIEx.au3> #include <Permissions.au3> _CheckFolderShareStatus("C:\Temp"); for illustration purposes only ;Global Const $SFGAO_SHARE = 0x00020000 ; this seems no longer relevant Func _CheckFolderShareStatus($sFolder) $tSHFILEINFO = DllStructCreate($tagSHFILEINFO) _WinAPI_ShellGetFileInfo($sFolder, $SHGFI_ATTRIBUTES, 0, $tSHFILEINFO) $iAttributes = DllStructGetData($tSHFILEINFO, "Attributes") If BitAND($iAttributes, $SFGAO_SHARE) Then ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; Shared!" & @LF) Return True Else ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; NOT Shared!" & @LF) Return False EndIf EndFunc ;==> _CheckFolderShareStatus() I get a number of errors along the lines of: "C:\!AutoIT-USERINCLUDE\Permissions.au3"(108,45) : error: $FILE_READ_DATA previously declared as a 'Const'. Global Const $FILE_READ_DATA = 0x00000001 APIFilesConstants.au3 is opened highlighting the same Const name. I believe I'm using the original version of the permissions.au3 udf by @FredAI and have tried the modified version by @AdamUL, which didn't help. Do I just remove the Constant declarations in permissions.au3 and add an include for WinAPIEx.au3 (or the APIFilesConstants.au3) so that there's no dual declaration of these constants? I'm using Autoit 3.3.16.1 I would be grateful for a steer in the right direction, or any recommendation of an alternative solution for what I'm trying to achieve please? I'm an occasional AutoIT user and don't code for a living, so please kindly keep any explanation basic Thanks in advance.
argumentum Posted March 5 Posted March 5 (edited) #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <APIShellExConstants.au3> #include <WinAPIShellEx.au3> _CheckFolderShareStatus("R:\Temp") ; for illustration purposes only Func _CheckFolderShareStatus($sFolder) Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO) _WinAPI_ShellGetFileInfo($sFolder, $SHGFI_ATTRIBUTES, 0, $tSHFILEINFO) Local $iAttributes = DllStructGetData($tSHFILEINFO, "Attributes") If BitAND($iAttributes, $SFGAO_SHARE) Then ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; Shared!" & @LF) Return True Else ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; NOT Shared!" & @LF) Return False EndIf EndFunc ;==>_CheckFolderShareStatus Edit: added Au3Check parameters to make sure that the variables are declared. In SciTE, that line will help the coder ( you or me ) to have a better coded script. Edited March 5 by argumentum better robertocm and BobboP 2 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
BobboP Posted March 5 Posted March 5 15 minutes ago, argumentum said: #include <APIShellExConstants.au3> #include <WinAPIShellEx.au3> _CheckFolderShareStatus("R:\Temp") ; for illustration purposes only Func _CheckFolderShareStatus($sFolder) Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO) _WinAPI_ShellGetFileInfo($sFolder, $SHGFI_ATTRIBUTES, 0, $tSHFILEINFO) Local $iAttributes = DllStructGetData($tSHFILEINFO, "Attributes") If BitAND($iAttributes, $SFGAO_SHARE) Then ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; Shared!" & @LF) Return True Else ConsoleWrite("Attributes = 0x" & Hex($iAttributes) & "; NOT Shared!" & @LF) Return False EndIf EndFunc ;==>_CheckFolderShareStatus Thanks @argumentum. I see the addition of "Local" and subsequent testing in my main script highlighted that to me (although i don't understand why it's not flagged up in the test script. I did butcher the Permissions.au3 udf as i had suggested and that resolved the conflict as I had suspected. Are you suggesting that your alternate #includes, will also avoid those conflicts? I'll take a look, and perhaps give it a try, although if that's what you're indicating, i'm inclined to suggest that declaring widely used const in a custom udf, will create opportunity for conflict with main app udf's as i've found here. Thanks anyway for the quick response, it's much appreciated.
argumentum Posted March 5 Posted March 5 (edited) 20 minutes ago, BobboP said: ..had suggested ... Are you suggesting ... This, is Sparta ! Coding !, we don't suggest, we do The code I posted works because those old UDFs are now included in the standard distribution. All you needed was the current incudes/UDF names ..also edited the code to include the line with "#AutoIt3Wrapper_Au3Check_Parameters" Edited March 5 by argumentum more Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
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