MSFN Forum: Folder/File auditing - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Folder/File auditing Not sure where to begin Rate Topic: -----

#1 User is offline   sentinel1705 

  • Newbie
  • Group: Members
  • Posts: 11
  • Joined: 13-May 08

Posted 27 January 2012 - 01:44 PM

I'm trying to figure out the best way to recursive search through one file (profile.ini) nested in each user's profile directory and compare an entry to the parent folder. If they match, move on, if they don't match, write that parent folder info to an updating text file.

I got a lot of help here last time and was hoping for the same again, or at least get pointed in the right direction. See below for a crude example of what the process would be.

Working Directory: D:\TSProfiles\
Full path: D:\TSProfiles\sentinel1705\windows\profile.ini

Within Profile.ini, 

If CurrentWorkstation=Sentinel1705, 

Goto Next folder

Else if

Write Sentinel1705 to Badfile.txt
Next



#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 27 January 2012 - 02:54 PM

Does TSProfiles contain only directories named with UserNames?

Is it likely that UserNames will be found elsewhere within the .ini file or that more than one UserName may appear in the same file?

Is the script being run locally/per machine or is this intended to be ran from a Network?

Which Operating System(s) is this aimed at?

#3 User is offline   sentinel1705 

  • Newbie
  • Group: Members
  • Posts: 11
  • Joined: 13-May 08

Posted 27 January 2012 - 06:10 PM

The TSProfiles directory hosts just the user profile directories, of which they are all just user names. So no random 'default user' or 'administrator' folders. All pair up to an actual end-user. The entry I highlighted would be the only entry in the .ini file as well as the only entry that needs comparison against the parent folder for that user's profile. All of this would run locally on the server hosting the TSProfiles directory, which is a Windows Server 2003 box.

View PostYzöwl, on 27 January 2012 - 02:54 PM, said:

Does TSProfiles contain only directories named with UserNames?

Is it likely that UserNames will be found elsewhere within the .ini file or that more than one UserName may appear in the same file?

Is the script being run locally/per machine or is this intended to be ran from a Network?

Which Operating System(s) is this aimed at?


#4 User is online   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,020
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 27 January 2012 - 06:49 PM

Here try this script it a Recursive script that looks for the ini
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Col, Obj
'-> Script In Same Folder You Want To Recursive
 Recursive(Fso.GetFolder("."))
'-> Path To Recursive Folder UnComment To Make Active
' Recursive(Fso.GetFolder("PLACE_PATH_TO_FOLDER"))

   Function Recursive(Folder)
     For Each Col In Folder.Files
      If LCase(Right(Col.Name,3)) = "ini" Then
        WScript.Echo Col.Path
      End If 
    Next
    For Each Obj In Folder.SubFolders
     Recursive(Obj)
    Next
   End Function


Rename Recursive.vbs.txt to Recursive.vbs to make active
Attached File  Recursive.vbs.txt (522bytes)
Number of downloads: 0

#5 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,195
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 29 January 2012 - 03:19 PM

Here's a 'batch' script I've thrown together possibly a little too quickly (I have been unable to test this as today I'm logged into a Linux Operating System):
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
(SET PD=D:\TSProfiles)
(SET PF=profile.ini)
IF /I "%CD%" NEQ "%PD%" (
	SET "_=T"
	2>NUL PUSHD %PD%||(
		ECHO=Cannot find profile directory %PD%
		>NUL PING -n 6 127.0.0.1
	)
)
FOR /D %%# IN (*) DO CALL :SON %%#
IF DEFINED $ (
	IF EXIST Badfile.txt (
		DEL Badfile.txt
	)
	IF NOT EXIST _n$.txt (
		REN _b$.txt Badfile.txt
	) ELSE (
		IF NOT EXIST _b$.txt (
			REN _n$.txt Badfile.txt
		) ELSE (
			>NUL COPY _n$.txt + _b$.txt Badfile.txt
			DEL _n$.txt _b$.txt
		)
	)
)
IF DEFINED _ POPD
GOTO :EOF

:SON
	SET "UN=%*"
	PUSHD %UN%
	FOR /F "TOKENS=*" %%# IN ('2^>NUL DIR/B/S %PF%') DO (
		SET "FP=%%#"
		CALL SET "LP=%%FP:%PD%\=%%"
	)
	POPD
	IF NOT DEFINED FP (
		SET "$=T"
		IF NOT EXIST _n$.txt (
			>_n$.txt (
				ECHO=No profile.ini found in the following directories:
				ECHO=
			)
		)
		>>_n$.txt ECHO=	%UN%
	) ELSE (
		FIND /I "%UN%"<"%FP%">NUL 2>&1||(
			SET "$=T"
			IF NOT EXIST _b$.txt (
				>_b$.txt (
					ECHO=
					ECHO=Profile mismatch found in the following files:
					ECHO=
				)
			)
			>>_b$.txt ECHO=   %LP%
		)
	)
	FOR %%# IN (UN FP LP) DO SET "%%#="
It looks a little long, but that's the price I paid for trying to have a neater looking output file.

#6 User is offline   sentinel1705 

  • Newbie
  • Group: Members
  • Posts: 11
  • Joined: 13-May 08

Posted 31 January 2012 - 10:25 AM

View PostYzöwl, on 29 January 2012 - 03:19 PM, said:

Here's a 'batch' script I've thrown together possibly a little too quickly [i](I have been unable to test this as today I'm logged into a Linux Operating System)


Yzöwl, that worked against a small test batch of users. I am going to make a full backup copy of our user profiles and run it against that to see what might fall out.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy