cacls Tip!

Author Message
lingk

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 1/20/2010
  • Status: offline
cacls Tip! Wednesday, January 20, 2010 8:31 AM (permalink)
0
Hello all!,

This is my first post on this forum. I am not new to coding, but still a beginner. I found this forum while looking for some help with everyone’s favorite cacls. Now I didn't find the answer I was looking for, in fact, most questions I found regarding cacls where never answered on here. That's normal for most support forums because people never go back to let people know how they fixed the issue.

What I was able to do is get some good ideas to try and in the end did some guessing to solve the issue I was having with cacls.

Because it seemed to me that the people having the issues that were never fully answered or solved where simulator to mine I thought I would share with all of you what I did to fix my issue.


Goal of the Script
the goal of the script was to check if a folder was in a network path, if it wasn't it was to create the folder with the name of the logged in user and set the ACL on the folder to Domain Admins full control and The logged in user full control. 

The Code
Be low is the code I got from Asking Mr. Google, it's about the same as everyone else had when I was searching around this forum for the answer to my question.
intRunError = objShell.Run("%COMSPEC% /C Echo Y| cacls " & strArcive & " /T /C /G ""Domain Admins"":F" & strUserName &":F", 2, True)  
               If intRunError <> 0 Then  
                               Wscript.Echo "Error assigning permissions for user " _  
                               & strUserName & " to home folder " & strArcive  
                End If  

Like everyone else I was getting an error while running the script.  It would give Domain Admins full rights but not the username.  so I Used the /K switch rather than the /C to see if I could see what the script was sending to cacls. all I got was Invalid argument than the help for cacls.

So I thought I would add in an echo to see if I could see what's going on. So I made the cacls string a variable and than echoed that variable
'For Debuging  
                 sCMD=("%COMSPEC% /K Echo Y| cacls " & strArcive & " /T /C /G ""Domain Admins"":F" & strUserName &":F")  
                 WScript.echo sCMD 
  

what I ended up getting was
sharename /T /C /G "domain Admins:Fusername:F

At first glance all is fine, but after looking closer I notice that there was no space between "Domain Admins:F and Username:F.  This made me think of Michale in office space when he said " It's always some mundane detail"

so I added the space in like this

intRunError = objShell.Run("%COMSPEC% /C Echo Y| cacls " & strArcive & " /T /C /G ""Domain Admins"":F" & Space(1) & strUserName &":F", 2, True)  
               If intRunError <> 0 Then  
                               Wscript.Echo "Error assigning permissions for user " _  
                               & strUserName & " to home folder " & strArcive  
                End If 

 
and wouldn't you know it, it worked perfectly. 
now I don't know if I over looked it or my google fu was off, but I never saw anyone on this forum or on the interwebs say to try add a space in regards to cacls.

I'm sure I'm not the only one that has racked there head on this, and probably wont be the last.

So I hope it helps someone out there.

Thanks for Reading!
lingk`

<message edited by lingk on Wednesday, January 20, 2010 12:48 PM>
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9