JohnBailey Posted June 27, 2007 Share Posted June 27, 2007 I'm using FileSetAttrib to change the Attributes of a file on a NetWorkDrive, which is where the script is located. Any reasons why the following wouldn't change the attribute or at least say it doesn't? It's not even giving me the error msg that it didn't change it. Global $dbFile = @ScriptDir&"\FullListForDownloading.txt" ;Make file Writeable If Not FileSetAttrib($dbFile, "+R") Then MsgBox(0,'Error', $dbFile&' could not be made writeable. Save feature will not work.') Exit EndIf $attrib = FileGetAttrib($dbFile) If @error Then MsgBox(0,"Error", "Could not obtain attributes.") Exit Else If StringInStr($attrib, "R") Then MsgBox(0,"", "File is read-only.") Else MsgBox(0,"", "File is NOT read-only.") EndIf EndIf A decision is a powerful thing Link to comment Share on other sites More sharing options...
Siao Posted June 27, 2007 Share Posted June 27, 2007 You're setting the file to read-only, which contradicts with your error message... "be smart, drink your wine" Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 You're setting the file to read-only, which contradicts with your error message... thanks, it still isn't working though Global $dbFile = @ScriptDir&"\FullListForDownloading.txt" ;Make file Writeable If Not FileSetAttrib($dbFile, "-R") Then MsgBox(0,'Error', $dbFile&' could not be made writeable. Save feature will not work.') Exit EndIf $attrib = FileGetAttrib($dbFile) If @error Then MsgBox(0,"Error", "Could not obtain attributes.") Exit Else If StringInStr($attrib, "R") Then MsgBox(0,"", "File is read-only.") Else MsgBox(0,"", "File is NOT read-only.") EndIf EndIf If Not FileSetAttrib($dbFile, "+R") Then MsgBox(0,'Error', $dbFile&' could not be made read-only.') Exit EndIf $attrib = FileGetAttrib($dbFile) If @error Then MsgBox(0,"Error", "Could not obtain attributes.") Exit Else If StringInStr($attrib, "R") Then MsgBox(0,"", "File is read-only.") Else MsgBox(0,"", "File is NOT read-only.") EndIf EndIf A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 27, 2007 Author Share Posted June 27, 2007 Any ideas someone? A decision is a powerful thing Link to comment Share on other sites More sharing options...
MHz Posted June 28, 2007 Share Posted June 28, 2007 Try this test script. The extra If's may force testing in sequence before continuing on with the script. Global $dbFile = @ScriptDir&"\FullListForDownloading.txt" FileWriteLine($dbFile, '') If Not FileSetAttrib($dbFile, "-R") Then MsgBox(0,'Error1', $dbFile&' could not be made writeable. Save feature will not work.') Exit EndIf If Not FileGetAttrib($dbFile) And @error Then MsgBox(0,"Error2", "Could not obtain attributes.") Exit EndIf If Not FileSetAttrib($dbFile, "+R") Then MsgBox(0,'Error3', $dbFile&' could not be made read-only.') Exit EndIf If Not FileGetAttrib($dbFile) And @error Then MsgBox(0,"Error4", "Could not obtain attributes.") Exit EndIf If FileSetAttrib($dbFile, "-R") Then FileDelete($dbFile) EndIf Link to comment Share on other sites More sharing options...
JohnBailey Posted June 28, 2007 Author Share Posted June 28, 2007 Try this test script. The extra If's may force testing in sequence before continuing on with the script.Thanks, but that didn't do the trick. Could it be because it's a network drive? I can change it manually. I can do a FileExist and a FileWriteLine without problems, but FileSetAttrib won't set the attribs. A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 28, 2007 Author Share Posted June 28, 2007 FileSetAttrib will remove Attributes but will not add them. Odd! A decision is a powerful thing Link to comment Share on other sites More sharing options...
MHz Posted June 28, 2007 Share Posted June 28, 2007 Thanks, but that didn't do the trick. Could it be because it's a network drive?...If your using UNC paths then it maybe ok. If you are referring to mapping a network drive then your script may need to do the mapping before using further script functions else they may fail. Others have mentioned some issues with network drives using a cache for changes rather then updating immediately. Unfortunately, I cannot be further help to you as I have no network drive here to play with this. Link to comment Share on other sites More sharing options...
JohnBailey Posted June 28, 2007 Author Share Posted June 28, 2007 If your using UNC paths then it maybe ok. If you are referring to mapping a network drive then your script may need to do the mapping before using further script functions else they may fail. Others have mentioned some issues with network drives using a cache for changes rather then updating immediately. Unfortunately, I cannot be further help to you as I have no network drive here to play with this.MHz thank you though! This is indeed an odd issue. I have tried UNC paths and @ScriptDir and the mapping name, which none have made a difference. The odd thing is that the script will remove R but not add it. odd isn't it. -R works but +R doesn't A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 28, 2007 Author Share Posted June 28, 2007 Actually, any time FileSetAttrib runs it will set the file to A only no matter what! that's soooooooooo weird! A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted June 28, 2007 Author Share Posted June 28, 2007 MHz or anyone, do you know how FileSetAttrib works? Is the code somewhere in the base files for AutoIt. My guess is that it's using a DLL of some kind. A decision is a powerful thing Link to comment Share on other sites More sharing options...
Xander Posted February 28, 2011 Share Posted February 28, 2011 (edited) MHz or anyone, do you know how FileSetAttrib works? Is the code somewhere in the base files for AutoIt. My guess is that it's using a DLL of some kind. Digging this up as it's a good match to my question/needs. I'm working on a little script that will reset the HOSTS file on an infected system. I want it to work even if its security has been messed with. For testing puroses, I start by setting my Hosts to "Deny" Everyone, and to +RSH. When I run the script, resetting the permissions works fine but resetting the attributes fails consistenly. I've even got an extra command in for redundancy but neither work! Argh. RunWait(@ComSpec & ' /c ' & 'echo,Y|cacls "%WinDir%\system32\drivers\etc\hosts" /G everyone:f') ;Works RunWait(@ComSpec & ' /c ' & 'attrib -s -h -r "%WinDir%\system32\drivers\etc\hosts"') ; FileSetAttrib(@SystemDir & "\drivers\etc\hosts","-shr") ;should do the same as 2nd line but both seem to fail FileCopy(@SystemDir & "\drivers\etc\hosts", "C:\old_hosts.txt", 1) ;when working, change to a LOG folder on USB FileDelete(@SystemDir & "\drivers\etc\hosts") FileInstall("y:\disinfect\Default_Hosts", @SystemDir & "\drivers\etc\hosts", 1) ;reset to an MVPS Hosts file to limit reinfectionI've even tried it with a plain txt file in the same folder. It's the attributes that keep tripping it up. Edit: I changed the location of the file to c:\test.txt and it will work on that. So, it seems to be the ETC folder and it's permissions. The script runs with #requireAdmin but that doesn't seem to make a difference. I'm open to suggestions. Edited February 28, 2011 by Xander Link to comment Share on other sites More sharing options...
KaFu Posted February 28, 2011 Share Posted February 28, 2011 #requireAdmin is not enough, add this SciTE directive to the script before compiling: #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Xander Posted March 1, 2011 Share Posted March 1, 2011 #requireAdmin is not enough, add this SciTE directive to the script before compiling:#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministratorThanks but, unfortunately, it didn't make a difference. I'm really sure it has to do with the folder's permissions. If I do the exact same test on a file elsewhere, it works.Also noted, by running the command through CMD, that cacls has been put to pasture (I'm running Win7x64 Home Prem) but it still works. Odd, though, even when I make a blank/default TXT and rename it to Hosts, the permissions seem really plain-jane and I can manually delete it but, through the script, I can neither change attributes or even delete it(!) 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