Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Win32 Stuff

by vroom (Pope)
on May 25, 2000 at 21:51 UTC ( #14831=sourcecodesection: print w/ replies, xml ) Need Help??
Win32::ole and MSWord
on Sep 15, 2002 at 15:48 UTC
by Kenny
Using perl, of course, launch MSWord and build a complex word document. This shows off how to do page setup, headers and footers, insert text, insertsymbol, add a table, put text in the table. I think this is a great example if you just want to get going.
Find Home directories without User Accounts (NT4 and AD)
on Sep 11, 2002 at 15:48 UTC
by OzzyOsbourne

Compares directories on the servers against who is using them in user manager. If no one claims the directory as a home directory in user manager, it is dubbed an orphan and printed to orphans.txt. An e-mail is sent to when the script is complete. This will Get NT4 accounts, or Active Directory (AD) Accounts.

Win32::OLE Outlook and E-mail security update
on Jul 27, 2002 at 16:30 UTC
by Anonymous Monk
The Outlook E-mail Security Update provides additional levels of protection against malicious e-mail messages. The update changes the way that Outlook can be controlled programmatically (Microsoft knowledgebase Q262701). Sending mail and accessing the Adress book display a dialog box asking you to confirm the action Dmitry Streblechenko at http://www.dimastr.com as released Redemption (http://www.dimastr.com/redemption/), an OLE object that works around limitations imposed by the Outlook Security Patch. Here is an example of using Redemption with Perl for sending e-mails :
editd
on Jul 26, 2002 at 22:29 UTC
by tye

Works like pushd and popd but brings up an editor with the stack of directories and lets you edit them.

I have vi.bat that does "start c:\path\to\vim\gvim %*" so I can just type "vi file" at the command prompt and not have it wait for gvim to exit. I also have vim.bat which doesn't include "start" (just "c:\path\to\vim\gvim %*") so I can do SET VISUAL=vim and editd.bat will use vi to let me edit the directory stack. In fact, I call it vid.bat on my computers.

This probably requires WinNT/Win2K.

(code) Win32 disk monitor, email notify, event log
on Jul 16, 2002 at 00:38 UTC
by ybiC

Check free disk space on a Win32 localhost.   Automatically detects and checks all fixed disk drives (hard disks or partitions with assigned drive letters).   Optional email notification on alarum and Event Log entry on program run.   Intended to run as a periodically scheduled task.   Clearly not a replacement for expensive commercial monitoring packages, but potentially beneficial for small business with a single Win32 file/print server.

If you spot any signs of PERL-ly code here and let me know, I'll make sure to mention your help here and in pod credits
    Props to thunders for join() tip,
    Kanji for spotting 0-bytes-free bug,
    and to fsn for mondo SMTP info/tips/help,

Email alarum looks something like this:

Envelope-to: pastor@church.org
To: pastor@church.org
From: wdf.pl@myserver
Subject: ALERT - MYSERVER DISK SPACE GETTING LOW
Date: Mon, 15 Jul 2002 20:01:04 -0500

This message was automatically generated by the wdf.pl program.
pastor@church.org
officemgr@church.org

    MYSERVER
  D:\ less than 30% free space

      C:\
    57 percent used
    43 percent free

    5,132,570,624 bytes total
    2,909,786,112 bytes used
    2,222,784,512 bytes free

      D:\
    80 percent used
    20 percent free

    20,412,596,224 bytes total
    16,364,945,408 bytes used
    4,047,650,816 bytes free

Update:
Squashed Bugs:   no-alarum-on-0-bytes-free, non-functional email option
New Features:   Event Logging, argument for nearby SMTP server

Simple script to change win32 wallpaper
on Jul 12, 2002 at 01:54 UTC
by bbfu

Simple script to change the MS Windows wallpaper from the command-line. Really just a wrapper around the SetSystemParametersInfo() API call, via Win32::API.

I'm using it as part of another small app. I'm writing (for my GF) to pick random papers. :)

A killall for Windows
on Jun 04, 2002 at 13:55 UTC
by Dog and Pony
Plain and simple, it is a variant of the killall script that can be found on some *NIX flavours - basically, you give it one or several names of processes (like 'calc', 'wordpad' or whatever has gone south atm), and it kills them. (No, it is no exact clone).

I have only had the possibility to try this out on Windows 2000, so i don't know if it will work on other flavours. I kinda suspect that it relies a bit on features that is NT only, which would mean NT, 2k and XP. So feedback is appreciated. :)

"Why not use the taskmanager?", I hear you ask. Because when something has gone really bad (lots of CPU), it is a pain to bring it up, scroll the list and try to click on and kill the process gone bad. In at least my case I almost always have a few DOS windows up, and usually know the process gone bad. Or one could type it in the Run menu too, more easy at least. And, of course there are plenty other uses if one rips the code and modifys it. :)

nt2ldap
on May 21, 2002 at 14:07 UTC
by ZinMostaccho
With a user of windows NT, determine data information the server LDAP.
Crond
on May 21, 2002 at 12:57 UTC
by zeroquo
A Crond service, like Crond of Unix systems. its interpreted the crontab file. Enjoy !
Flexcopy
on May 21, 2002 at 12:48 UTC
by zeroquo
Flexcopy is a Cluster Service Script, for replicate a simple directory content to 2 recipient, enabling cascade arquitecture on network down.
if_info.pl
on May 17, 2002 at 12:02 UTC
by dada
this script exploits some system APIs to emulate Unix's ifconfig -a on a Win32 machine. should work for Windoze versions 98 and later or NT SP4 and later (2000/XP/...).

it's all fair to me except that the operational status seems to always report UNREACHABLE. go figure...

this was already posted in reply to List all network interfaces on the local machine?, but I think it deserves a mention in the Code Catacomb (sorry for the duplication :-).
Me in a loop with Win32::Clipboard
on Apr 07, 2002 at 16:42 UTC
by Rudif
I wanted to convert a large number (several hundred) of strings from mixed case to upper case. Strings were accessible one at a time, through a dialog belonging to a particular application.
So, I sat down to do the work:
repeat open the dialog on next item retype string in uppercase
Ugh. Retyping was the longest and most error-prone part of the operation. And easiest to mechanize, if I could hook Perl into my loop. I remembered Win32::Clipboard and quickly whipped up this script, ucclip.pl. Now the slog became bearable (almost pleasant, in a cyborg sort of way):
start the script repeat open the dialog on next item copy string to clipboard (select, ^C) - script uppercases it paste back into the dialog (^V)
Deleting Microsoft's hidden web caches created by IE5
on Feb 15, 2002 at 05:09 UTC
by cLive ;-)
Finds and removes those nasty "index.dat" files that IE hide on your Windows machine. For more information, see this article.
perlcaller.pl
on Jan 21, 2002 at 17:20 UTC
by DaveRoberts
This script is intended to be called by sysmon.pl - and manages the log file associated with this service.
sysmon.pl
on Jan 21, 2002 at 17:17 UTC
by DaveRoberts
This script controls the System Monitoring Service (SysMon). SysMon is an NT service that executes various perl scripts and command files using a non-deterministic schedule. SysMon allows scripts to be added and removed as it executes, and creates a log of each scripts execution, as well as a history of previous executions. I use this to distribute scripts to, and to manage, around 30 NT based servers on a relativly thin network. see POD for more info. Note that this script requires the perlcaller script to operate succesfully....
ppminst.pl
on Jan 21, 2002 at 16:41 UTC
by DaveRoberts
This script is used to install and update a number of perl packages using the Perl Package Manager (PPM). The perl packages to be managed, and their repositaries, are defined within the script. When executed the script will report on the status of packages, and attempt to install any that are missing. If any packages have already been installed using the PPM a check will be made and these updated if a later revision is available. Packages not installed by PPM will not be upgraded. The script is useful for ensuring several perl installations have a base set of modules installed.
Refresh ActivePerl Documentation (New Windows Help Format)
on Dec 21, 2001 at 21:31 UTC
by $code or die

As JMD noted in ActiveState Perl build 630, the latest versions of Active Perl no longer install the HTML document set that they used to. It is now bundled with a compiled Windows Help file that is not updated when you install a module with PPM.

There has also been discussion and criticism of this change in the ActiveState mailing lists. One solution is to install the ActivePerl HTML documents with "PPM install ActivePerl-HTML" While this restores the old functionality, one might miss the searchable index that the new help format provides.

This script combines both methods. It will update the compiled Windows Help File with the changes made to the old HTML documents.

It requires Microsoft's HTML Help Workshop, and it requires you to install ActivePerl-HTML with PPM.

Running this script should scan your ActivePerl HTML folder and create a new Windows Help file. Since the compilation of the help file takes 2-3 minutes, I have not written this as a PPM extension, but rather a standalone script to synchronise the documentation periodically.

To run the script, install ActivePerl-HTML, the MS HTML Help Workshop, and make sure that $HTML_Compiler matches the path to HHC.exe.

There are some crufty bits of code that I will remove soon, but it works.

Note: the Help compiler will report several errors. Those errors are within the html documents themselves rather than the project files we write to compile the help file. It should be safe to ignore those errors, unless you want to clean up the module documentation.

Extracting memos from an Outlook Inbox
on Dec 21, 2001 at 19:39 UTC
by grinder
Someone in the chatter box asked whether anybody had any Perl code to deal with Outlook on Windows.

I used Outlook at my previous job, and when I left I wrote the following code to extract all the messages and dump them out into files.

The code is rather exploratory and not really well-written. For a start, it consumes a horrendous amount of RAM, directly proportional to the size of your Inbox (because in instantiates all the objects in an array that unfortunately is not evaluated lazily). A lot of the magic numbers come from MSDN documentation, but the accompanying notes I wrote at the time appear to have drifted away.

Oh well, it's a starting point.

Win32-API-Guid
on Dec 21, 2001 at 02:51 UTC
by Rudif
If you are Windoze COM programmer, you may find use for this guid generator, perhaps when you clone an existing MSVC project and you need to change the guids therein.

Requires Win32-API.

Update: generate() now returns one guid in scalar context, array of one or more guids in array context.

Update 2: Thank you $code or die for pointing out the GuidGen() function in libwin32-018.
I just installed ActivePerl build 630 and tried GuidGen() - after some searching. I could not find it mentioned in the new chm documentation. Attempt to call Win32::GuidGen() as you suggested produces an error "Undefined subroutine &Win32::GuidGen called at ...". Text search for GuidGen in C:\Perl produced a few examples of calls via package Win32::Resource, which does not seem to be documented either, but following these examples worked for me:

#!perl -w use strict; #my $guid = Win32::GuidGen(); #Undefined subroutine &Win32::GuidGen called at Noname1.pl line 3. use Win32::Resource; my $guid2 = Win32::Resource::GuidGen(); print "$guid2\n"; __END__ {A8D7B8DA-1AA8-4575-A51F-8EA05E93D032}
However, Win32::Resource::GuidGen() does not seem to support an optional argument for generating a list of several guids at a time.

'h' - a Win32 command-line history
on Nov 11, 2001 at 17:53 UTC
by osfameron

A command line history recall for Win32. Tries to emulate some of the functionality of Unix versions. I'm quite pleased with the use of Win32::Console to emulate Term::Readline's (non-functional) addhistory method. (but happy to get suggestions of better ways to do this!!)

Note: If this can be done better, safer etc. please let me know - I will welcome review, criticism etc.!

Update: Replaced the batch wrapper (which is redundant since I'm just writing to STDIN...). On the other hand, this also means that we lose the ability to recall a numbered item. hmmm.

Win32: Shell extension for viewing POD (proof of concept)
on Oct 31, 2001 at 16:06 UTC
by osfameron
We had an interesting chat about Shell extensions in WinNT in the Thread "Windows Drag and Drop".

I think that viewing POD from the Explorer window would be a useful use of Windows Shell extensions.

So this code is a) a wrapper around pod2html, and b) some instructions on how to create the Shell extensions.

As per Drag and Drop thread, I'd appreciate any clarification from a WinNT guru, but it works for me.

Proof of concept: please note all warnings in documentation

Update:v 0.002: Added an option to create a hyperlink to the source code the POD is taken from. You can switch this off by setting constant SOURCE=>0

Wild - Perl extension for improved program interface. Wild-card expansion for @ARGV.
on Sep 27, 2001 at 22:37 UTC
by hsmyers
Will handle DOS-style wild-card expansion of '*' and '?'. Additionally it introduces '@', '!', and '~' as filename prefixes with the following effects: '@' -- treat each line of the file as though it were a command line, '!' -- directory recursion operator, '~' -- exclusion operator creates an exclusionary list, a sort of negative @ARGV. As a last step in WildARGV(), the union of the two is removed from @ARGV. '!' forces lookups to be recursive.
SysEnvAdd.pl
on Jul 19, 2001 at 19:52 UTC
by RayRay459
This program will add a System Environment Variable. It will require a reboot to take effect.
CD-RW or Zip disk backup program
on Jun 20, 2001 at 02:36 UTC
by bikeNomad
This is a backup script suitable for running from a scheduler or interactively. It backs up one or more directory trees to a removable disk (CD-RW, Zip, floppy) or to a directory, perhaps on a network. You can specify files to include or exclude, as well as the destination, handling of deleted files, and size quotas using a configuration file. It will prompt the user to insert a disk if necessary; otherwise, it's not interactive. Win32 only (had to make it for my girlfriend's computer).

update: added support for wildcards in includes and excludes.

Compare Directories/Permissions across all servers
on Mar 23, 2001 at 22:16 UTC
by OzzyOsbourne

Uses File::Find and Win32::FileSecurity to dump file permissions to a text file on shares that you specify.

Usage code.pl {share} {outputlog}

Output:server(tab)share(tab)account(tab)permission1(tab)permission2(tab)...(enter)

If the account does not have a permission, the script double tabs, for easy visual inspection.

By importing the resultant tab-delimited log into a spreadsheet program, you can sort by account(colC), then share(colB), then server(colA), to very simply compare directory rights across your file and prints.

Thanks to Tyke.

bootlog.txt shrinker
on Mar 09, 2001 at 00:59 UTC
by dmckee
Parses C:\bootlog.txt on Windows 98 machines to extract 'important' lines - ie: the ones where it's all gone wrong. Dead simple
multi.pl
on Mar 06, 2001 at 21:47 UTC
by premchai21
A short script that simply takes a program and runs it with a few different sets of arguments.
Extract Outlook Telephone Numbers
on Mar 02, 2001 at 19:10 UTC
by Corion
This is a small example on how to use the MS Outlook object model from within Perl (under Win32 of course) to extract contacts data. If you have the Outlook object model chart at hand, it's easy to automate other tasks such as sending mail or creating contacs as well. This snippet needs Outlook to be open and the Contacts view must be active, because I was too lazy to drill my way down from Outlook->Application to the Contacts view.

Update:I added the missing <code> tags myself. Even more stupid I am ...

Update 2:Some documentation - the 069 is my local area code.

XEmacs printing script
on Feb 10, 2001 at 04:06 UTC
by macguges
Got XEmacs? Got Windows NT (or its evil twin, Windows 2000?) Got a line printer daemon (somewhere, lurking near a printer)?

Then this script is for you. Explore the wonders of printing from your favorite editor, even under Windows.

(Cygwin environment may be necessary, and is a nifty idea anyway. Your lpd's IP & printer queue name may differ.)

Auto prepare code for production
on Jan 24, 2001 at 22:44 UTC
by Ovid
We had a situation at work where programs running in our test environment behave differently than programs in our production environment. Specifically, when copying programs to our production environment, we wanted to automatically comment out use warnings, debugging code, or anything else that was merely being used for development.

To use this code, append a "#//" at the end of every line that should not be in production. If you have a block of code that shouldn't be in production, wrap the code in #/* and #*/ tags. Then, run this code, specifying source and destination directories, and it will automatically comment out the appropriate code. It will skip itself and all programs that do not end with the extensions in $extensions

Further, it can process files that you specify, all files in the current directory, all directories or subdirectories, make the target directory if it doesn't exist, and more. It needs some work, but it's fairly flexible.

It uses some Windows specific code, but I'm sure it can easily be ported to a *nix environment.

Handy wrapper for Spreadsheet::WriteExcel
on Dec 02, 2000 at 00:02 UTC
by nop
This is a small wrapper around Spreadsheet::WriteExcel. It lets you quickly open a workbook, and spit data into it by row by column (analogous to writing a tab delim text file, or using write and writeln in Pascal). Sometimes it is easier to think of generating a report by row by column, rather than popping all around the sheet.

The package also supports multiple tabs (sheets) nicely, setting them up automatically the first time a new tab is referenced. The package also supports common formats, and allows you to create "metaformats" (ala cascading style sheets).

Here's a example that shows the module in action:
use strict; use warnings; use diagnostics; use Excel; my $excel = Excel->new("test_excel1.xls"); $excel->writeln('tab1', "Header"); $excel->writeln('tab1'); $excel->writeln('tab1', qw(1 3 4 5 6)); $excel->writeln('tab1', qw(A B C D E F)); $excel->writeln('tab1'); $excel->writeln('tab1', qw(1.1 1000 101011.33 -14 -14.555 .000001)); $excel->writeln('tab1', map {[$_, 'money']} qw(1.1 1000 101011.33 -14 +-14.555 .000001)); $excel->writeln('tab1', map {[$_, 'bigmoney']} qw(1.1 1000 101011.33 - +14 -14.555 .000001)); $excel->writeln('tab1', map {[$_, 'pct']} qw(1.1 1000 101011.33 -14 -1 +4.555 .000001)); $excel->writeln('tab1', "VErrry long striiiiiiiiiiiiiiiiiiiiiiiiiiing" +); $excel->writeln('tab1', ['hello', 'bold'], [.003, 'pct','bold']); foreach (qw(1 2 3 4 5)) { $excel->write('tab2', [$_, 'money', 'bold']); } $excel->writeln('tab2', 'hello', [.003, 'pct','bold'], 'goodbye', 9999 +9999999999); foreach (qw(red blue yellow green orange)) { $excel->writeln('tab3', 'hello', [$_, $_, 'bold']); } $excel->writeln('tab4', ['i am a header', 'header']); $excel->writeln('tab4', ['i am a header', 'header', 'sumline']); $excel->writeln('tab4', ['i am a header', 'header', 'size20']);
SecureTrading COM
on Nov 02, 2000 at 18:38 UTC
by $code or die
Repost - I thought that the code tags would be added automatically because the box below is expecting code! My mistake.

A example script to use SecureTrading in Perl on Win32 systems. SecureTrading does online credit card authorization. The perl scripts on their site only run on *nix systems. They didn't reply to my offer of them putting this example on their website :(

It uses Win32::OLE, so you will need to download the ASP COM object from securetrading.com for this script to work.

Before you flame me - I don't work for securetrading and this is NOT an advert :-). I worked ALL last night getting this to work because I refused to use ASP instead of Perl, and I had no option about the platform unfortunately.
Win32::SystemInfo
on Sep 07, 2000 at 20:21 UTC
by Guildenstern
Updated version of my Win32::MemoryInfo that returns information on available/installed RAM/page file. Now renamed SystemInfo, this module also returns Processor info for Windows9x, Windows NT and Windows 2000.
This has not been tested on very many processor/OS variations, so any feedback/bugs will be appreciated.
Includes POD
Win32::MemoryInfo
on Aug 31, 2000 at 01:19 UTC
by Guildenstern
Memory information for Win32. Total and available physical, page, and virtual memory.
This is my first ever module, so any constructive criticism will be eagerly welcomed!
Update (1 Sept 00): Completely reworked the after tye's comments. This module is very different from the original.

This module has been superceded by Win32::SystemInfo.
Win32/Outlook Mail Forwarder
on Aug 24, 2000 at 23:50 UTC
by Guildenstern
Forwards email messages saved to text from MS Outlook (requires 3rd party DLL, unfortunately) to my web phone so I can be in touch when out of cube.
Win32SnapWalk
on Jul 10, 2000 at 17:16 UTC
by t0mas
A package to list the currently running processes on a Win32 box. It uses Win32::API.
winsane.pl
on Jul 02, 2000 at 19:47 UTC
by Intrepid

I have updated this code today (22 July, 2000)

This lib is an overkill approach to dealing with vagaries of paths on Win32.

Please see the POD below the code itself, it explains it more clearly (I think) than the previous lengthy description did.

OS.pl
on Jun 28, 2000 at 21:37 UTC
by Intrepid
A work-around for the absence of a defined value in the built-in special variable $^O (platform, Operating System) in some Perls on Win 95/98. In present form, simply determines if the platform is Win32 or not. The usual `require "OS.pl";' statement is all that's needed.
Retrieve Win32 Executable Version information
on Jun 01, 2000 at 22:08 UTC
by Corion
versioninfo.pl - This small program reads the version information of a Win32 PE/COFF executable and dumps the embedded version string.
finddata.pl with comments
on Jun 15, 2000 at 23:18 UTC
by Hydro
This is a Perl script that makes use of the Win32:GUI module. Hopefully this will be a good example of the many features that can be used in GUI. This is the updated version of my finddata.pl program with comments added. I still haven't got the Stop button to work or been able to read the data based on an item of data that is clicked. You will need a data file named "datafile.txt" in the same directory and must run the program with a -t parameter like:

perl finddata.pl -t

The datafile needs to be in the format:

id,firstname,lastname,building,room,adapteraddress,ipaddress

I would appreciate any insight.
finddata.pl
on May 31, 2000 at 20:45 UTC
by perlcgi
This cool utility is included as a mini-demonstation of
what is possible with Perl on Win32 using Win32::GUI.
This code, the associated database and bitmap may be downloaded from here
If anyone can figure out why the "Stop" button does not
work properly or how to read the individual items of each
column based on the index item clicked on then Jonathan would appreciate the input.
Also Jonathan will be happy to answer anybody's questions
about the code if he can.
"It was done on a trial and error basis ... definitely not written off the cuff and then worked properly.
It required some rewrites of course. ;] Anyway, have fun with the code and any experimenting you want to do on it."
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-07-30 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls