Hasher Posted November 12, 2006 Share Posted November 12, 2006 (edited) Hi Having trouble setting permissions to a folder , what I am trying to achieve is a hidden folder that cant be viewed even if you check "view hidden folders" . I have seen it done in another program and watching filemon the author uses Cacls to achieve this. I am finding Cacls very difficult to use,below is test code Dim $file, $Dir If FileExists(@ScriptDir & "\Appdata\") = False Then $Dir = DirCreate (@ScriptDir & "\Appdata\Scr") RunWait(@comspec & ' /c cacls ' & ' @ScriptDir & "\Appdata" ' & ' /D ' & @UserName & ":F") Endif If FileExists(@ScriptDir & "\Appdata\Test.txt") = False Then $file = FileOpen(@ScriptDir & "\Appdata\Test.txt", 1) FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") FileClose($file) EndIf I am sure its a syntax probelm and something very simple, Thanks in advance!!!!. Paul Edited November 12, 2006 by Hasher Firefox's secret is the same as Jessica Simpson's: its effortless, glamorous style is the result of shhh extensions! Link to comment Share on other sites More sharing options...
MHz Posted November 12, 2006 Share Posted November 12, 2006 Setting permissions will not make a folder super hidden. Attrib is used to change file or folder attributes and Cacls is used to set permissions. With that in mind, it is alittle confusing on your needs that you show so I would guess that you want to primarily wish to set the attribute. This example may help you reach your goal. I have tested and works to expectation for me. You can change the Run flag, uncomment the StdOutRead and MsgBox lines to simply see the command prompt Stdout information to help troubleshoot a problem if needed. Global $file If Not FileExists(@ScriptDir & "\Appdata\") Then If DirCreate (@ScriptDir & "\Appdata\Scr") Then ; Set super hidden attribute RunWait(@comspec & ' /c attrib +h +s "' & @ScriptDir & '\Appdata"', '', @SW_HIDE) ; Set permission if needed (use flag 3 if StdoutRead used also) $pid = Run(@comspec & ' /c cacls "' & @ScriptDir & '\Appdata" /G ' & @UserName & ':F', '', @SW_HIDE, 1) Sleep(1000) ; Respond yes to permission prompt StdInWrite($pid, 'y' & @CRLF) ; Check result ;$result = StdoutRead($pid) ;MsgBox(0x40000, Default, $result, 3) ProcessWaitClose($pid) EndIf Endif If Not FileExists(@ScriptDir & "\Appdata\Test.txt") Then $file = FileOpen(@ScriptDir & "\Appdata\Test.txt", 1) If $file <> -1 Then FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") FileClose($file) Else MsgBox(0x40030, Default, 'FileOpen error', 3) EndIf EndIf The above grants permission to @UserName. If you want to deny @Username permission, then you would use /D without the :F switch AFAIK with cacls /? used for help. Link to comment Share on other sites More sharing options...
Hasher Posted November 12, 2006 Author Share Posted November 12, 2006 Thank you that is excatly what I wanted to achieve Great work MHz Firefox's secret is the same as Jessica Simpson's: its effortless, glamorous style is the result of shhh extensions! Link to comment Share on other sites More sharing options...
macro4tw Posted November 12, 2006 Share Posted November 12, 2006 You could use NFTS permissions. Link to comment Share on other sites More sharing options...
Confuzzled Posted November 12, 2006 Share Posted November 12, 2006 You could use NFTS permissions. That's what CACLS (a command line utility) actually manipulates... 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