Chapter 4. Files, Folders, and Shares

Introduction

This chapter covers some of the common tasks facing administrators when it comes to managing the Windows file system. I'll not only touch on the really basic tasks such as creating, deleting, renaming, and moving files and folders, but more advanced topics such as viewing a list of all open files and identifying the process that has a file locked.

Using a Graphical User Interface

You are undoubtedly familiar with the all-purpose file, folder, and shared folder management tool, Windows Explorer. With it you can create, move, rename, and delete files and folders as well as hide, encrypt, and make them read-only. As you'll see, this is the most used graphical tool in this chapter.

You are also probably familiar with the Shared Folder MMC snap-in, which is commonly seen as a part of the Computer Management tool. This snap-in allows you to do just about anything with shares (i.e., create, delete, see who is using them, etc.).

Sysinternals produces several graphical tools that are also very helpful. These include File Monitor (Recipe 4.19), Fundelete (Recipe 4.3), and Shareenum (Recipe 4.24).

Using a Command-Line Interface

Table 4-1 lists command-line tools used in this chapter and the recipes they are used in.

Table 4-1. Command-line tools used in this chapter

Tool

Windows Server 2003

Windows 2000 Server

Recipes

attrib

%SystemRoot%\system32

%SystemRoot%\system32

4.12, 4.13

auditpol

Windows 2000 Resource Kit

Windows 2000 Resource Kit

4.18

cipher

%SystemRoot%\system32

%SystemRoot%\system32

4.15

compress

Windows 2003 Resource Kit

Windows 2000 Resource Kit

4.14

copy

CMD shell

CMD shell

4.10

creatfil

Windows 2003 Resource Kit

Windows 2000 Resource Kit

4.1

del

CMD shell

CMD shell

4.1

dir

CMD shell

CMD shell

4.5

fc

%SystemRoot%\system32

%SystemRoot%\system32

4.11

findstr

%SystemRoot%\system32

%SystemRoot%\system32

4.9

forfiles

%SystemRoot%\system32

Windows 2000 Resource Kit

4.22

handle

http://sysinternals.com/

http://sysinternals.com/

4.20

inuse

%SystemRoot%\system32

Windows 2000 Resource Kit

4.16

junction

http://sysinternals.com/

http://sysinternals.com/

4.7

linkd

Windows 2003 Resource Kit

Windows 2000 Resource Kit

4.7

mkdir

CMD shell

CMD shell

4.2

move

CMD shell

CMD shell

4.10

net file

%SystemRoot%\system32

%SystemRoot%\system32

4.19

net share

%SystemRoot%\system32

%SystemRoot%\system32

4.23, 4.24

openfiles

%SystemRoot%\system32

N/A

4.19

ren

CMD shell

CMD shell

4.10

rmdir

CMD shell

CMD shell

4.2

sdelete

http://sysinternals.com/

http://sysinternals.com/

4.4

setacl

http://setacl.sourceforge.net/

http://setacl.sourceforge.net/

4.18

shortcut

MKS Toolkit

MKS Toolkit

4.6

strings

http://sysinternals.com/

http://sysinternals.com/

4.9

subinacl

Windows 2003 Resource Kit

Windows 2000 Resource Kit

4.17, 4.25

takeown

%SystemRoot%\system32

Windows 2000 Resource Kit

4.17

where

%SystemRoot%\system32

Windows 2000 Resource Kit

4.9

Using VBScript

Between WMI and WSH, you have the ability to automate reading, writing, and searching files and folders. Unfortunately, the WMI file and folder classes don't provide the capability to do basic manipulation, which is where WSH comes in. Table 4-2 lists all of the WSH and WMI classes used in this chapter.

Table 4-2. WMI and WSH classes used in this chapter

WMI class

Description

Recipes

Cim_DataFile

WMI class that represents files

4.1, 4.5, 4.10, 4.14, 4.17, 4.22

Scripting.FileSystemObject

WSH interface for reading, writing, and manipulating files and folders

4.1, 4.2, 4.11, 4.12, 4.13

Win32_Directory

WMI class that represents folders

4.5, 4.14

Win32_ShortcutFile

WMI class that represents shortcut files (.lnk)

4.6

Win32_Share

WMI class that represents shared folders

4.23, 4.24

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.