Solved

Batch FIle: Scan for Access Denied

Posted on 2010-08-27
6
358 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 56

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 56

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

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

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

627 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