?
Solved

setting folder permissions & Running dos command

Posted on 2004-11-24
11
Medium Priority
?
554 Views
Last Modified: 2012-06-27
I have this function that executes a dos command, and returns the result :
-------------------------------------------------------
Function runShell(strDosCmd)
      Dim objShell, objScriptExec
      On Error Resume Next
      Set objShell = CreateObject("WScript.Shell")
      Set objScriptExec = objShell.Exec(strDosCmd)
      runShell = objScriptExec.StdOut.ReadAll
      Set objShell = nothing
      Set objScriptExec = nothing
End Function
-------------------------------------------------------

I'm trying to set some permissions on some new profile & home directories (for a new AD user) that I've created.
This call fails (no error - null returned):

runShell("%comspec% /c cacls \\server\profiles$\user1 /E /G Domain\Admin:F")

-- but this one works :

runShell("%comspec% /c cacls c:\temp /E /G Domain\Admin:F")

It seems that any UNC paths I pass, cause the command to return null.   What's up ?

This is the only way I know to set permissions in my new user creation script.  If anyone's got a better way to set permissions, I NEED IT !   thanks ...
0
Comment
Question by:Gitcho
11 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 12670793
If you take the "On Error" line out of the function and call it with a UNC path, what error do you get?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12671218
This might help too.  http://setacl.sourceforge.net/
0
 
LVL 5

Author Comment

by:Gitcho
ID: 12671639
vinnyd79:   no error ... command executes with a null response, but doesn't do anything. I know this, because if I append " > output.txt" to the command, it will create the file

blue : that's a last resort ... don't really want to install & configure activex controls ...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 12674231
What is this path?

\\server\profiles$\user1

can you access from explorer?


should it be just
\\server\profiles\user1


or if you are admin user, you can

\\server\c$\user1
0
 
LVL 5

Author Comment

by:Gitcho
ID: 12676967
???  $ = hidden share - but that's kind of irrelevant.  The command i'm passing works when I enter it manually in dos
0
 
LVL 5

Author Comment

by:Gitcho
ID: 12682872
Blue : haven't messed with loading activeX controls ( http://setacl.sourceforge.net/ ) ...

Do I have to re-configure IIS ? or can I copy the file to a local directory and instatiate it from the page ?  If I can get this to work, i'll go with it.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12683355
Hi, Gitcho.

I thought you were running this process from a script.  Do I understand instead that you're running it from a web page?  If you're running it from a script, then all you should need to do is register the ocx (i.e. regsvr32 setacl.ocx) and then use it in the script.  The same would generally apply to using it from a web page, but of course your browser would need to be configured to allow the use of activex controls.  I don't believer there'd need to be any changes made to IIS.  
0
 
LVL 5

Author Comment

by:Gitcho
ID: 12683766
Yes, this is all from a webpage ... would you mind providing sample code to include, instantiate & use ?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 12692668
Gitcho,

Here's the web page code.  This is for an ASP web page.  I cannibalized the code from the sample code that came with the OCX.  It works fine in my testing.  I created two pages, one containing a form where I entered the path to the folder, the account I wanted to grant rights to, and the rights I wanted to grant.  Clicking the Submit button on the first page sends me to the second page where I retrieve the values from the form fields on the first page and execute the code below.  

Hope this helps.

<%
dim objSetACL, intError, strUsername
Set objSetACL = Server.CreateObject("SetACL.SetACLCtrl.1")
intError = objSetACL.SetObject(Request.Form("txtFolder"), 1)
If intError <> 0 Then
    Response.Write("SetObject failed: " & objSetACL.GetResourceString(intError) & "<br>OS error: " & objSetACL.GetLastAPIErrorMessage())
End If
intError = objSetACL.SetAction(1)
If intError <> 0 Then
    Response.Write("SetAction failed: " & objSetACL.GetResourceString(intError) & "<br>OS error: " & objSetACL.GetLastAPIErrorMessage())
End If
intError = objSetACL.AddACE(Request.Form("txtUsername"), False, Request.Form("txtRights"), 0, False, 1, 1)      
If intError <> 0 Then
    Response.Write("AddACE failed: " & objSetACL.GetResourceString(intError) & "<br>OS error: " & objSetACL.GetLastAPIErrorMessage())
End If
intError = objSetACL.Run
If intError <> 0 Then
    Response.Write("Run failed: " & objSetACL.GetResourceString(intError) & "<br>OS error: " & objSetACL.GetLastAPIErrorMessage())
End If
%>
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12692680
Oh, one other point.  To be able to set the permissions I had to turn on authentication for the web site.  Otherwise the page uses the IUSR account and the permissions don't get set.
0
 
LVL 5

Author Comment

by:Gitcho
ID: 13019182
sorry for the delay on this one, but that's what I was looking for.  Thx.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question