Lee Evans Posted April 13, 2010 Posted April 13, 2010 I have tried a dllcall based on the SHGetSpecialFolderPath function from shell32.dll which was based on an example script however this only returns a boolean. expandcollapse popupConst $CSIDL_LOCAL_APPDATA = 28 $localappdata = LOCAL_APPDATA() MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$localappdata' & @lf & @lf & 'Return:' & @lf & $localappdata & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX Func LOCAL_APPDATA() Return SHGetSpecialFolderPath($CSIDL_LOCAL_APPDATA) EndFunc Func SHGetSpecialFolderPath($csidl) ;hwndOwner ;Reserved. ;lpszPath ;[out] A pointer to a null-terminated string that receives the drive and path of the ;specified folder. This buffer must be at least MAX_PATH characters in size. ;csidl ;[in] A CSIDL that identifies the folder of interest. If a virtual folder is specified ;, this function will fail. ;fCreate ;[in] Indicates whether the folder should be created if it does not already exist. If ;this value is nonzero, the folder is created. If this value is zero, the folder is ;not created. Local $hwndOwner = 0 , $lpszPath = "" , $fCreate = False , $MAX_PATH = 260 $lpszPath = DllStructCreate("char[" & $MAX_PATH & "]") $BOOL = DllCall("shell32.dll","int","SHGetSpecialFolderPath","int",$hwndOwner,"ptr", DllStructGetPtr($lpszPath),"int",$csidl,"int",$fCreate) if Not @error Then Return SetError($BOOL[0],0,$BOOL[0]) Else Return SetError(@error,0,3) EndFunc Here is the link to the example I have lifted my code from http://www.autoitscript.com/forum/index.php?showtopic=102783&st=0&p=729546&hl=$CSIDL_LOCAL_APPDATA&fromsearch=1&entry729546 Can also return the path as well (__out LPTSTR lpszPath) but how could I do this? See here for the MSDN documentation http://msdn.microsoft.com/en-us/library/bb762204(VS.85).aspx Or is there another way for me to find the Local Application Data folder for the current user. There does not seem to be an Autoit macro for this value. I need to find this information for all windows versions from Win 2000 onwards. Also would need this information if the user was logged on via a windows terminal server session as well. Thank you in advance for any help that you can give me.
BrettF Posted April 13, 2010 Posted April 13, 2010 Whipped this one up in a few seconds. Works on Win7 and seems to be the simplest way to do it. MsgBox (0, "", _GetAppDir()) Func _GetAppDir() $old_opt = Opt ("ExpandEnvStrings", 1) $dir = "%APPDATA%" Opt ("ExpandEnvStrings", $old_opt) Return $dir EndFunc Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
MHz Posted April 13, 2010 Posted April 13, 2010 On 4/13/2010 at 9:31 AM, 'BrettF said: Whipped this one up in a few seconds. Works on Win7 and seems to be the simplest way to do Open a command prompt and type set and then press enter. Now look for "APPDATA" and "LOCALAPPDATA" and notice the difference. One is for roaming and the other is local. Win2k will not have "LOCALAPPDATA". Also use EnvGet() to use environmental variables which is easier. @Lee Evans Looks like you tried the minor change at the bottom of your linked post. The one at the top of that page works for me under WinXP. Const $CSIDL_LOCAL_APPDATA = 28 $localappdata = LOCAL_APPDATA() MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @LF & '$localappdata' & @LF & @LF & 'Return:' & @LF & $localappdata & @LF & @LF & '@Error:' & @LF & @error) ;### Debug MSGBOX Func LOCAL_APPDATA() Return SHGetSpecialFolderPath($CSIDL_LOCAL_APPDATA) EndFunc ;==>LOCAL_APPDATA Func SHGetSpecialFolderPath($csidl) ;hwndOwner ;Reserved. ;lpszPath ;[out] A pointer to a null-terminated string that receives the drive and path of the ;specified folder. This buffer must be at least MAX_PATH characters in size. ;csidl ;[in] A CSIDL that identifies the folder of interest. If a virtual folder is specified ;, this function will fail. ;fCreate ;[in] Indicates whether the folder should be created if it does not already exist. If ;this value is nonzero, the folder is created. If this value is zero, the folder is ;not created. Local $hwndOwner = 0, $lpszPath = "", $fCreate = False, $MAX_PATH = 260 $lpszPath = DllStructCreate("char[" & $MAX_PATH & "]") $BOOL = DllCall("shell32.dll", "int", "SHGetSpecialFolderPath", "int", $hwndOwner, "ptr", _ DllStructGetPtr($lpszPath), "int", $csidl, "int", $fCreate) If Not @error Then ;~ Return SetError($BOOL[0],0,$BOOL[0]) Return SetError($BOOL[0], 0, DllStructGetData($lpszPath, 1)) Else Return SetError(@error, 0, 0) EndIf EndFunc ;==>SHGetSpecialFolderPath I get the output of: Quote --------------------------- Debug line ~4 --------------------------- Selection: $localappdata Return: C:\Documents and Settings\Michael\Local Settings\Application Data @Error: 0 --------------------------- OK ---------------------------
BrettF Posted April 13, 2010 Posted April 13, 2010 Ahhhhh woops Thanks MHz. Learn something every day Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Lee Evans Posted April 13, 2010 Author Posted April 13, 2010 Sometimes you just can't see the wood for the trees. @MHz you were right the first example returns exactly what I wanted which I thought the function could do as the MSDN documentation listed it as an output. For anyone intereseted here is my fixed example expandcollapse popupConst $CSIDL_LOCAL_APPDATA = 28 $localappdata = LOCAL_APPDATA() MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$localappdata' & @lf & @lf & 'Return:' & @lf & $localappdata & @lf & @lf & '@Error:' & @lf & @Error) ;### Debug MSGBOX Func LOCAL_APPDATA() Return SHGetSpecialFolderPath($CSIDL_LOCAL_APPDATA) EndFunc Func SHGetSpecialFolderPath($csidl) ;hwndOwner ;Reserved. ;lpszPath ;[out] A pointer to a null-terminated string that receives the drive and path of the ;specified folder. This buffer must be at least MAX_PATH characters in size. ;csidl ;[in] A CSIDL that identifies the folder of interest. If a virtual folder is specified ;, this function will fail. ;fCreate ;[in] Indicates whether the folder should be created if it does not already exist. If ;this value is nonzero, the folder is created. If this value is zero, the folder is ;not created. Local $hwndOwner = 0 , $lpszPath = "" , $fCreate = False , $MAX_PATH = 260 $lpszPath = DllStructCreate("char[" & $MAX_PATH & "]") $BOOL = DllCall("shell32.dll","int","SHGetSpecialFolderPath","int",$hwndOwner,"ptr", DllStructGetPtr($lpszPath),"int",$csidl,"int",$fCreate) if Not @error Then Return SetError($BOOL[0],0,DllStructGetData($lpszPath,1)) Else Return SetError(@error,0,3) EndIf I was returning the boolean value and not the DllStructGetData($lpszPath,1)
Danny35d Posted April 13, 2010 Posted April 13, 2010 Did you try to use @AppDataDir macro? MsgBox(0, 'Local Application Data', @AppDataDir) AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
BrettF Posted April 14, 2010 Posted April 14, 2010 On 4/13/2010 at 7:23 PM, 'Danny35d said: Did you try to use @AppDataDir macro? MsgBox(0, 'Local Application Data', @AppDataDir) Same issue as MHz pointed out in post 3. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
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