trof Posted June 14, 2017 Posted June 14, 2017 Hi, I use this script to save the list of files present in a directory. I launch it from Directory background context menu. #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> Opt("ExpandEnvStrings", 1) #include <File.au3> Local $aFileList = _FileListToArrayRec(@WorkingDir & "\", "*", 0 +8, 1, 1, 1) For $i = 1 To UBound($aFileList) - 1 Local $sFilePath = $aFileList[$i] If Not FileWrite("elenco relative.txt", $sFilePath & @CRLF) Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") EndIf Next It works well: output is saved on the working directory. However It doesn't work on folder who requires high privilegies, so I have added #RequireAdmin Now the script doesn't work well anymore because the working dir is changed and it is C:\Windows\System32
anthonyjr2 Posted June 14, 2017 Posted June 14, 2017 Why don't you just specify the working directory, or use a different macro? There are a list of others here: https://www.autoitscript.com/autoit3/docs/macros.htm When you elevate to admin access your working directory always switches to System32, this can be seen if you start an elevated command prompt vs. a normal one. If you want the user directory you can use Local $aFileList = _FileListToArrayRec(@UserProfileDir & "\", "*", 0 +8, 1, 1, 1) UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=
Danyfirex Posted June 14, 2017 Posted June 14, 2017 Hello. how do you add your script to the Directory background context menu ? I think is better to pass the current directory path as commanline parameter. so you can do something like this: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\TestApp] @="Test Script" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\TestApp\command] @="\"C:\\Users\\MyUserName\\Desktop\\MyAppp.exe\" \"%V\"" Then you can handle this way Local $sWorkingDir=$CmdLine[1] Local $aFileList = _FileListToArrayRec($sWorkingDir & "\", "*", 0 +8, 1, 1, 1) Saludos trof 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
trof Posted June 15, 2017 Author Posted June 15, 2017 (edited) Sorry, I was offline for a while. 12 hours ago, anthonyjr2 said: Why don't you just specify the working directory, or use a different macro? There are a list of others here: https://www.autoitscript.com/autoit3/docs/macros.htm When you elevate to admin access your working directory always switches to System32, this can be seen if you start an elevated command prompt vs. a normal one. If you want the user directory you can use Local $aFileList = _FileListToArrayRec(@UserProfileDir & "\", "*", 0 +8, 1, 1, 1) I prefer to not specify the working directory, so I can use the script in every path. 10 hours ago, Danyfirex said: Hello. how do you add your script to the Directory background context menu ? I think is better to pass the current directory path as commanline parameter. so you can do something like this: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\TestApp] @="Test Script" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\TestApp\command] @="\"C:\\Users\\MyUserName\\Desktop\\MyAppp.exe\" \"%V\"" Then you can handle this way Local $sWorkingDir=$CmdLine[1] Local $aFileList = _FileListToArrayRec($sWorkingDir & "\", "*", 0 +8, 1, 1, 1) Saludos I attach my registry entries. Your script works well. However, if I use it with my registry key I have this error background.zip Edited June 15, 2017 by trof I made an error
Skysnake Posted June 22, 2017 Posted June 22, 2017 Use @ScriptDir in stead of @WorkingDir ; use @ScriptDir ; returns local folder where script is located... ; instead of @WorkingDir ; returns the working dir from the Win environmnent Skysnake Why is the snake in the sky?
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