Solved

Batch FIle: Scan for Access Denied

Posted on 2010-08-27
6
353 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 52

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 52

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

How important is it to take extra precautions to protect your online business? These are some steps you can take to make sure you're free of any cyber crime.
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now