Solved

Batch FIle: Scan for Access Denied

Posted on 2010-08-27
6
350 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 51

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 51

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

708 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

10 Experts available now in Live!

Get 1:1 Help Now