TABLE OF CONTENTS
ABOUT THE AUTHOR............................................................................................................................................... 4
About the Technical Reviewers........................................................................................................................... 4
Acknowledgments............................................................................................................................................... 5
TELL US WHAT YOU THINK! ................................................................................................................................... 5
INTRODUCTION ....................................................................................................................................................... 6
Why This Book?................................................................................................................................................. 6
Who Will Benefit from This Book?...................................................................................................................... 8
How This Book Is Structured.............................................................................................................................10
Coding Style......................................................................................................................................................12
Hungarian Notation..........................................................................................................................................13
Formatting........................................................................................................................................................13
Brackets............................................................................................................................................................14
Last Thoughts ...................................................................................................................................................14
CHAPTER 1. WHY PERL ON YOUR WIN32 MACHINE?............................................................................................15
History of Win32 Perl .......................................................................................................................................15
ActiveState's ActivePerl.....................................................................................................................................16
Perl Modules and Extensions.............................................................................................................................17
Win32 Perl Extensions......................................................................................................................................21
Different Perl Libraries.....................................................................................................................................23
Installing Extensions.........................................................................................................................................24
Installing Perl...................................................................................................................................................28
Parse Exceptions...............................................................................................................................................31
Error Handling.................................................................................................................................................31
Summary...........................................................................................................................................................39
CHAPTER 2. NETWORK ADMINISTRATION ..............................................................................................................39
Discovering Servers on the Network..................................................................................................................40
Finding Domain Controllers .............................................................................................................................47
Resolving DNS Names.......................................................................................................................................50
Shared Network Resources................................................................................................................................56
Managing RAS Servers......................................................................................................................................82
Windows Terminal Server .................................................................................................................................88
Summary: Perl and Win32 Networks ...............................................................................................................105
CHAPTER 3. ADMINISTRATION OF MACHINES.......................................................................................................106
User Account Management..............................................................................................................................106
Group Account Management...........................................................................................................................124
Removing a Group..........................................................................................................................................128
Machine Management.....................................................................................................................................133
Summary.........................................................................................................................................................173
CHAPTER 4. FILE MANAGEMENT..........................................................................................................................173
File Attributes.................................................................................................................................................174
File Information..............................................................................................................................................179
Shortcuts.........................................................................................................................................................182
Monitoring Directory Changes........................................................................................................................196
Summary.........................................................................................................................................................202
CHAPTER 5. AUTOMATION ...................................................................................................................................203
Understanding OLE........................................................................................................................................203
Creating COM Objects....................................................................................................................................208
Interacting with COM Objects.........................................................................................................................217
Destroying COM Objects................................................................................................................................230
OLE Errors.....................................................................................................................................................230
Miscellaneous OLE Items................................................................................................................................231
Summary.........................................................................................................................................................258
CHAPTER 6. COMMUNICATION.............................................................................................................................259
Sending Messages...........................................................................................................................................259
Named Pipes...................................................................................................................................................272
Summary.........................................................................................................................................................288
CHAPTER 7. DATA ACCESS .................................................................................................................................288
What Is ODBC?..............................................................................................................................................288
Create PDF with GO2PDF for free, if you wish to remove this line, click here to buy Virtual PDF Printer
SQL................................................................................................................................................................290
USING SQL KEYWORDS......................................................................................................................................291
OLDER VERSIONS OF WIN32::ODBC..................................................................................................................292
Escape Sequences ...........................................................................................................................................301
How to Use Win32::ODBC .............................................................................................................................305
The Win32::ODBC API...................................................................................................................................314
GETTYPEINFO() AVAILABILITY .............................................................................................................................330
Advanced Features of Win32::ODBC..............................................................................................................334
Summary.........................................................................................................................................................343
CHAPTER 8. PROCESSES ....................................................................................................................................343
The STD Handles............................................................................................................................................344
Process Management......................................................................................................................................345
Case Study: Running Applications as Another User.........................................................................................364
Summary.........................................................................................................................................................366
CHAPTER 9. CONSOLE, SOUND, AND ADMINISTRATIVE WIN32 EXTENSIONS .......................................................366
Console Windows............................................................................................................................................366
BUG REPORT ......................................................................................................................................................374
BUG REPORT ......................................................................................................................................................382
MAX SIZE AFTER A MANUAL RESIZE....................................................................................................................385
Sound..............................................................................................................................................................394
CONSEQUENCES OF PLAYING SOUNDS ...............................................................................................................396
THE VOLUME BUG ...............................................................................................................................................398
Win32 API......................................................................................................................................................399
SPECIFYING A NULL POINTER ............................................................................................................................402
Impersonating a User......................................................................................................................................407
Miscellaneous Win32 Functions......................................................................................................................409
Summary.........................................................................................................................................................429
CHAPTER 10. WRITING YOUR OWN EXTENSION..................................................................................................429
What Is an Extension?.....................................................................................................................................430
What Is a DLL?...............................................................................................................................................431
How to Write a Perl Extension ........................................................................................................................431
Beginning Your Extension...............................................................................................................................452
Writing Extension Functions ...........................................................................................................................455
PERL V5.006 AND PERL_OBJECT....................................................................................................................466
A Practical Example .......................................................................................................................................471
Summary.........................................................................................................................................................479
CHAPTER 11. SECURITY......................................................................................................................................479
Security Concepts............................................................................................................................................479
How Does Win32 Security Work?....................................................................................................................488
LIMITATIONS OF RECURSING WITH WILDCARDS ...................................................................................................516
Using Win32::FileSecurity..............................................................................................................................521
LSA Functions.................................................................................................................................................527
Summary.........................................................................................................................................................554
CHAPTER 12. COMMON MISTAKES AND TROUBLESHOOTING ...............................................................................554
General Win32-Specific Mistakes....................................................................................................................554
Windows Scripting..........................................................................................................................................556
CGI Script Problems.......................................................................................................................................563
Win32::NetAdmin ...........................................................................................................................................570
Win32::Registry..............................................................................................................................................571
Win32::ODBC ................................................................................................................................................571
Win32::OLE ...................................................................................................................................................572
Summary.........................................................................................................................................................573
APPENDIX A. WIN32 PERL RESOURCES..............................................................................................................574
Book Resources...............................................................................................................................................574
Web Resources................................................................................................................................................574
The Official Perl Web Site...............................................................................................................................574
CPAN .............................................................................................................................................................575
Usenet Resources............................................................................................................................................576
Electronic Magazines and Journals.................................................................................................................577
Win32 Extensions............................................................................................................................................578
Create PDF with GO2PDF for free, if you wish to remove this line, click here to buy Virtual PDF Printer
About the Author
Dave Roth is a published writer, columnist, and the author of several popular Win32 Perl
extensions including Win32::AdminMisc, Win32::Perms, Win32::Daemon and Win32::ODBC. As a
leader in the Perl community, Dave has been featured at several conferences, including the O'Reilly
Perl conferences and the Usenix LISA-NT conferences. In addition to the first and second editions
of this book, he is also the author of Win32 Perl Scripting: The Administrator's Handbook (New
Riders). Dave also has contributed to The Perl Journal and writes a monthly column for the
Windows Scripting Solutions journal.
Dave has been programming since 1981 using various languages from Assembler to C++ and VB to
Perl. His code is used by such organizations as Microsoft, the U.S. Department of Defense,
Industrial Light and Magic, Hewlett-Packard, and various colleges and universities. Formerly, Dave
helped assemble and administer a statewide WAN for the state of Michigan, and he has designed
and administered LANs for Ameritech and Michigan State University.
About the Technical Reviewers
These reviewers contributed their considerable hands-on expertise to the entire development
process for Win32 Perl Programming: The Standard Extensions. As the book was being written,
these dedicated professionals reviewed all the material for technical content, organization, and flow.
Their feedback was critical to ensuring that Win32 Perl Programming: The Standard Extensions fits
our readers' need for the highest quality technical information.
Cameron Laird is vice president of Phaseit, Inc., where he has responsibility for several projects
involving both Perl and system administration. Along with everything else that he writes, he
maintains the authoritative Perl/Tk FAQ.
Denis Scherbakov is one of the system administrators of Belarus National Academy of Science
(BNAS). He already has eight years of progressively responsible experience in software
development using C/C++, Perl, Java, and management of corporate networks within UNIX, Linux,
and Windows. He has held positions that range from designer and software developer to Internet
security specialist to system administrator. Denis is currently working on an ozone-aerosol
measurement system for lidar stations of the Institute of Physics of BNAS and a European Aerosol
Research Lidar Network (EARLINET) to establish an aerosol climatology. He actively cooperates
Create PDF with GO2PDF for free, if you wish to remove this line, click here to buy Virtual PDF Printer
with international scientific projects such as Aerosol Robotic Network (AERONET) of the NASA
Goddard Space Flight Center. Denis lives in Minsk, Belarus, and likes dogs, cats, and his bike.
Acknowledgments
An unbelievable amount of patience went into this work. My editors, bless their souls, who have
weathered through my numerous bouts of mind melt, writer's block, and deadline missing deserve a
huge thank you! I can only hope that their management reads this and understands that they went
beyond the call of duty to make sure this project finished. Management should be told that the
delays were not their fault! Big thanks go out to my editors, Karen Wachs, Ann Quinn, and Lisa
Thibault. It was their patience, fancy footwork, and empathy that enabled me to finishing this work.
The "patience of Job" award for this book goes to my wife, who gracefully handled another season
of "Dave working on his book" again. Even as we discovered the new addition to our family, she
continued to be my backbone. My total love and appreciation goes out to Nazli and our yet-to-be-
named baby.
Thanks go out to my family and friends who have managed to nag me enough to get the book done.
Now that it is all over, we can go hiking again and fly back to Michigan to see the clan!
And finally, a thank you goes out to everyone who provided support and encouragement for the
book. The feedback everyone provided has been tremendous. The community needs good resources
like this, so keep writing that code and spreading the word about Perl!
Tell Us What You Think!
As the reader of this book, you are the most important critic and commentator. We value your
opinion and want to know what we're doing right, what we could do better, what areas you'd like to
see us publish in, and any other words of wisdom you're willing to pass our way.
As an Executive Editor at New Riders Publishing, I welcome your comments. You can fax, email,
or write me directly to let me know what you did or didn't like about this book—as well as what we
can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book, and that
due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book's title and author as well as your name and
phone or fax number. I will carefully review your comments and share them with the author and
editors who worked on the book.
Fax: 317-581-4663
Email: stephanie.wall@newriders.com
Mail: Stephanie Wall
Executive Editor
New Riders Publishing
201 West 103rd Street
Indianapolis, IN 46290 USA
Create PDF with GO2PDF for free, if you wish to remove this line, click here to buy Virtual PDF Printer
评论0