Solved

Batch FIle: Scan for Access Denied

Posted on 2010-08-27
6
357 Views
Last Modified: 2012-05-10
Hi there,

I need to make a batch file that will navigate through folders and report the root folders that I get an Access Denied.

@echo off
setlocal enabledelayedexpansion
FOR /R "S:" %%A IN (*.*) DO (
  IF "ACCESS DENIED" ECHO %%A >>AccessDenied.log
)
EXIT


So if in C:\temp\folder1\folder2 I have an access denied at folder1, the output should only be:

C:\temp\folder1

NOT:

C:\temp\folder1
C:\temp\folder1\folder2


Thanks for your help,
Rene

0
Comment
Question by:ReneGe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:dave4dl
dave4dl earned 50 total points
ID: 33547496
In your "FOR" loop, attempt to "CD" to each directory and pipe (append) all output from these operations to a file.  Next use a grep-like utility for windows to pull out those lines with errors (here is a link to one of them: http://www.wingrep.com/).
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33547726
You have an example of the command line?

Thanks,
Rene
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 33549110
Are you sure these show up in the file list of that FOR command?  On my Win7 system, many of the "access is denied" folders do not, like \msocache, \recovery, etc.

~bp
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 54

Accepted Solution

by:
Bill Prew earned 450 total points
ID: 33549179
Rene,

Short on time this morning, but try this in a bat file, it starts to get you close.  The basic idea is to walk the directory tree from the current directory (or as you know a starting dir can be specified on the FOR /R) and do a CD to each.  If the CD throws an error then echo the full path name.

@echo off
for /R %%A in (.) do cd %%~fA 2>NUL || echo %%~fA

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33549228
Thanks bp,

Works like a charm!

Cheers,
Rene
0
 
LVL 10

Author Closing Comment

by:ReneGe
ID: 33549236
Thanks dave for contributing.
Rene
0

Featured Post

Create Professional Looking Email Signatures

Create "Professional HTML Email Signatures" with ease.
7 Day Money Back Guarantee if not 100% Satisfied.
Affordable - Try it out for 7 Days Totally Risk Free.
Installers provided for over 45 Email clients.
Both Windows & MAC Supported.
Highly Recommended!

Question has a verified solution.

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

Suggested Solutions

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
A hard and fast method for reducing Active Directory Administrators members.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

732 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