Solved

Batch FIle: Scan for Access Denied

Posted on 2010-08-27
6
356 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
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
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…
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…

740 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