Re: Win32::OLE on MS Word using Selection.Find.Execute

2010-09-13 Thread Mark Leighton
Peter,

OLE needs Variant values.  Perl and the OLE modules will convert most of 
these on he fly for you, but sometimes I find I have a need to convert 
booleans explicitly.

my $false = Win32::OLE::Variant->new(VT_VARIANT, 0);
my $true = Win32::OLE::Variant->new(VT_VARIANT, 1);

Mark

On 9/12/2010 4:43 PM, Peter Buck wrote:
>Does anyone have an example of a perl script acting on MS Word
> documents using Win32::OLE and Selection.Find.Execute?  I have read the
> Win32 man page but its examples for Excel and Access don't help.  I
> found a Powershell script that does what I want but can't translate.
> The parts I'm confused on are (1) setting the parameters used in the
> Selection.Find.Execute() invocation (particularly the boolean values,
> since perl doesn't do booleans) and the actual invocation of
> Selection.Find.Execute().
>
> I did find an example using $search->  Execute() but this doesn't appear
> to allow setting all the parameters that Selection.Find.Execute() does.
> Also, it operates on $doc->  Content->Find while Selection.Find.Execute()
> operates on $doc->Selection (if I'm right).  And I'm using Homekey(6) to
> take me to the top of the document, which is linked to Selection and
> doesn't seem to work in my $doc->Content->Find attempts.
>
> Any help or direction to documentation much appreciated.
>
> Thanks - Toolsmith
>
> # ExpandAcronyms.ps1
> # read acronym list, expand acronyms in target MS Word document
> # syntax: ExpandAcronyms wordDocument
>
> function make-change {
>   $FindText = $args[0]
>   $FullText = $args[1]
>   $ReplaceText = "$FullText ($FindText)"
>
>   $ReplaceAll = 1
>   $FindContinue = 1
>   $MatchCase = $True
>   $MatchWholeWord = $True
>   $MatchWildcards = $False
>   $MatchSoundsLike = $False
>   $MatchAllWordForms = $False
>   $Forward = $True
>   $Wrap = $FindContinue# don't want it wrapping, wish I knew
> what this meant
>   $Format = $False
>
>   $objWord.Selection.HomeKey(6)>  Null
>   $result = $objSelection.Find.Execute($FindText,$MatchCase,
>   $MatchWholeWord,$MatchWildcards,$MatchSoundsLike,
>   $MatchAllWordForms,$Forward,$Wrap,$Format,
>   $ReplaceText,$ReplaceAll)
>if ( $result -eq $true ) {
>"$Findtext|$FullText"
>   }
>
> }
>
> if ( $args.count -lt 1 ) {
>   cd $env:temp
>   $strWordFile = [string](resolve-path(Read-Host "Enter Path of Word
> file to be processed"))
> } else {
>   $strWordFile = [string](resolve-path($args[0]))
> }
>
>
> $objWord = New-Object -ComObject word.application
> $objWord.Visible = $True
> $objDoc = $objWord.Documents.Open($strWordFile)
>
> $objSelection = $objWord.Selection
>
> $d = get-content "d:/temp/acronyms.txt"# read file of acronym |
> definition
> foreach ( $l in $d ) {
>   ($acro, $def) = $l.split('|')# build array
> of acronym, definition
>   make-change $acro $def
> }
> "Finished"
> $objWord.Selection.HomeKey(6)>  Null
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Displaying Hash key/values if you don't know what they are

2009-11-18 Thread Mark Leighton
 From what I see here, $rows is a hash reference, therefore:

use strict;
use warnings;

my $mySQL = SQLfunctions->new;
$mySQL->createSQLConnection("localhost\\Company", "Import");

my @results = $mySQL->runQuery("Select A,B from tablename;");

foreach my $row ( @results ) {
 foreach my $column ( keys %{$row} ) {
 printf "%s: %s\n", $column, $row->{$column};
 }
}


Sorry, don't have Win32::SqlServer on a box so the code is untested.

Cheers,
Mark


 Original Message  
Subject: Displaying Hash key/values if you don't know what they are
From: Jason Lowder 
To: perl-win32-users@listserv.ActiveState.com
Date: Tuesday, November 17, 2009 3:15:44 PM

> Hello,
> 
> I'm using the Win32::SqlServer module to execute queries against my 
> database.
> 
> Normally a query might look like:
> 
> our $mySQL = SQLfunctions->new;
> $mySQL->createSQLConnection("localhost\\Company", "Import");
> 
> @results = $mySQL->runQuery("Select A,B from tablename;");
> 
> foreach my $rows (@results)
> {
>  print $$rows{A}."\n";
>  print $$rows{B}."\n";
> }
> 
> All values from columns A and B will be printed.
> 
> But now I want to use a query that will show me the difference between 
> two tables, Table1 and Table2.  This query is:
> 
> select 'table1' as tblName, *  from
>(select * from table1
> except
> select * from table2) x
> union all
> select 'table2' as tblName, *  from
>(select * from table2
> except select *
> from table1) x
> 
> Based on the return from this query, any of the columns in the table 
> could be represented.  How do I determine which keys are present so I 
> can view the results?
> 
> Thanks,
> 
> Jason
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Advice requested, porting unix perl app to windows

2009-06-03 Thread Mark Leighton
If running on Windows, the best practice for transferring files would simply 
be through the native SMB filesystem.

The script should run under a user context (domain is easiest) that has 
inherent rights to copy files to the second machine (because maintaining 
username and password credentials in the script would be a security 
vulnerability).

If these are the case, then transferring the file is as simple as:

use File::Copy;
copy( 'file.dat', '//SERVER2/SHARENAME/file.dat' );


Otherwise, you can use:
system( 'net.exe use ...' );

or:
Win32::NetResource::AddConnection()

to map a drive first.

Cheers,
Mark

---
Mark Leighton
CLIC LAN Supervisor, Information Commons, University of Toronto
E-mail: mark{DOT}leighton{AT}utoronto.ca



 Original Message  
Subject: Advice requested, porting unix perl app to windows
From: Dennis Daupert 
To: perl-win32-users@listserv.ActiveState.com
Date: Wednesday, June 03, 2009 10:42:03 AM

> Hello group,
> 
> Most of my perl programming is on unix; my windows knowledge is limited.
> So, please be gentle ;-)
> 
> I have an app that produces data files on one unix machine, then uses
> scp to move those over to another machine for further processing. The
> system architecture dictates the two-machine arrangement. Management
> has asked me to port that app to a windows-based system with the same
> two-machine architecture.
> 
> I don't know of a free (as in both beer and non-beer) windows equivalent
> to scp OR sftp. I'm seeking advice on a solid, dependable, and secure way
> to move
> files between machines without incurring additional expense. I've wondered
> whether
> there may be Perl modules that will map drives and copy files across that
> would
> do so on an automated schedule, and I've been searching CPAN. But before
> heading too far down that path, I thought I'd ask the list for advice.
> 
> best,
> 
>  /dennis
> 
> 
> Dennis Daupert, PhD
> Senior Systems Development Professional -- CSC Account
> CSC
> 
> GOS | o: 1.317.298.9499 | ddaup...@csc.com | www.csc.com
> 
> This is a PRIVATE message. If you are not the intended recipient, please
> delete without copying and kindly advise us by e-mail of the mistake in
> delivery.
> NOTE: Regardless of content, this e-mail shall not operate to bind CSC to
> any order or other contract unless pursuant to explicit written agreement
> or government initiative expressly permitting the use of e-mail for such
> purpose.
> 
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: trouble understanding unicode

2009-03-27 Thread Mark Leighton

Hi Greg et al,

Attached is my boilerplate routines for dealing with Unicode on Win32 and a 
couple of samples.


Cheers,
Mark

---
Mark Leighton
CLIC LAN Supervisor, Information Commons, University of Toronto
E-mail: mark{DOT}leighton{AT}utoronto.ca



 Original Message  
Subject: Re: trouble understanding unicode
From: Gaurav Vaidya 
To: gai...@visioninfosoft.com
Cc: perl-win32-users@listserv.activestate.com
Date: Thursday, March 26, 2009 11:14:04 PM


Hi Greg,

On Mar 27, 2009, at 6:47 AM, Greg Aiken wrote:
the problem here is that the ‘msinfo.txt’ file is not written in  
(single byte per character, ascii) format.  instead the first two  
bytes of the file happen to be (hexFF)(hexFE).  Beyond the first two  
bytes, each human readable ascii character is represented with TWO  
BYTES, (hex-ascii character value)(hex00)
(hexFF) (hexFE) is the Byte-Order Mark (http://en.wikipedia.org/wiki/Byte-order_mark 
), so yes, definitely Unicode, and - if I'm reading the Wikipedia  
article correctly - definitely either UTF-16 or UTF-32.


in addition, if anyone knows how to modify the following block so  
that I can effectively, read the records of this file, and convert  
the read record into ‘plain old ascii’ encoding – I would be most  
appreciative.


open (IN, ‘infile.txt’);
while ($rec = ) {
convert_$rec_from_its_current_encoding? 
_to_simple_ascii_encoding; <<<<<<<<<< the magic code would go here

print $rec;
}


Okay, here's my understanding of what's going on: Perl 5.8 and above  
will try to load the file up in UTF-8, Perl's native string format.  
But the file you're trying to open appears to be in UTF-16 or UTF-32  
(You can use the table in the Wikipedia article above to figure out  
which one it is). Searching at http://perldoc.perl.org/ brought me to http://perldoc.perl.org/Encode/Unicode.html 
, which seems to be Perl's way of handling Unicode which isn't UTF-8.  
Since it's part of the Encode method, you should be able to use:
	open(IN, '<:encoding(utf-32)', 'infile.txt') or die "Could not open  
'infile.txt': $!";
to tell Perl to translate that file from UTF-32 into Perl's native  
UTF-8 while reading. Similarly, to write out to this file without  
changing its UTF-16/32ishness, you can use:
	open(OUT, '>:encoding(utf-32)', 'outfile.txt') or die "Could not open  
'outfile.txt' for writing: $!";

so Perl converts its native UTF-8 into UTF-32 on output.

The Perl Cookbook backs me up on this [1] :-).

Once you've figured this out, let us know how you did it - I think  
it'll make a nice page for the Perl Win32 wiki (http://win32.perl.org/).


cheers,
Gaurav

[1] 
http://books.google.com/books?id=IzdJIax6J5oC&pg=PA335&lpg=PA335&dq=perl+opening+UTF-32&source=bl&ots=z6zl7q9efS&sig=HdQeMKL8NHjc5pi6gE5jAonqdCw&hl=en&ei=dEHMSeyOEZCw6wPtodCbBw&sa=X&oi=book_result&resnum=7&ct=result
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
use strict;
use warnings;

use Encode;
use Carp;

# Get encoding filter for writing a utf8 file (with no Byte-Order-Marker).
my $ex1_encoding = SetFileEncoding( format => 'utf8' );
open( my $ex1_fh, '>' . $ex1_encoding, 'test-utf8.txt' ) or die;

print( $ex1_fh "Hello World with utf-8\n" );

close( $ex1_fh );


# Get encoding filter for writing a UTF-8 file with a Byte-Order-Marker.
my ( $ex2_encoding, $ex2_bom ) = SetFileEncoding( format => 'utf8' );
open( my $ex2_fh, '>' . $ex2_encoding, 'test-utf8-bom.txt' ) or die;

print( $ex2_fh $ex2_bom );   # Write the correct BOM
print( $ex2_fh "Hello World with utf-8 and BOM\n" );

close( $ex2_fh );


# Get encoding filter for writing a UTF-16 file with a Byte-Order-Marker.
my ( $ex3_encoding, $ex3_bom ) = SetFileEncoding( format => 'UTF-16' );
open( my $ex3_fh, '>' . $ex3_encoding, 'test-utf16.txt' ) or die;

print( $ex3_fh $ex3_bom );   # Write the correct BOM
print( $ex3_fh "Hello World with UTF-16\n" );

close( $ex3_fh );


# Get encoding filter for reading a utf8 file.

my $ex4_path = 'test-utf8.txt';

my ( $ex4_encoding, $ex4_bom ) = GetFileEncoding( path => $ex4_path );
open( my $ex4_fh, '<' . $ex4_encoding, $ex4_path ) or die;
SkipBOM( $ex4_fh, $ex4_bom );

while ( <$ex4_fh> ) { print };

close( $ex4_fh );

exit;




sub GetFileEncoding {
my %arg = ( @_ );

# Process minimally required arguments
grep { croak message_req_param( 'parameter' => $_ ) unless exists $arg{$_} 
} qw( path );

my $encoding = '';
my $bom = &#x

Re: WMI remote querying

2009-03-24 Thread Mark Leighton
You may want to ensure that you are using fully qualified credentials. 
Sometimes see issues with that, especially when local or remote machines have 
trust relationships.

ie.
my $dbh = DBI->connect('dbi:WMI:'.$machine,$machine.'\admin','admin');

Other than that, haven't used the DBD interfaces before - usually just use the 
OLE methods directly and they haven't given problems.

You may want to confirm passwords, etc. using the wmic utility before worrying 
about the underlying Perl code.

eg.
wmic /NODE:machine /USER:machine\admin OS LIST BRIEF

Mark

---
Mark Leighton
CLIC LAN Supervisor, Information Commons, University of Toronto
E-mail: mark{DOT}leighton{AT}utoronto.ca



 Original Message  
Subject: WMI remote querying
From: David Evans 
To: perl-win32-users@listserv.ActiveState.com
Date: Tuesday, March 24, 2009 8:21:27 AM

> Hi wonderful people
>  
> I hope one of you can help me.  I need to access WMI on a remote Win XP 
> desktops and I am getting permission errors when using the local admin 
> account on the remote box.  Any ideas?
>  
> CODE:
>  
> use DBI;
> my $machine = 'server';
> my $dbh = DBI->connect('dbi:WMI:'.$machine,'admin','admin');
>   print "$dbh\n";
> my $sth = $dbh->prepare('SELECT * FROM Win32_OperatingSystem');
> $sth->execute;
> while (my @row = $sth->fetchrow) {
> my $printer = $row[0];
> printf "ServicePackMajorVersion is %s\n", 
> $printer->{ServicePackMajorVersion}, $machine;
> printf "ServicePackMinorVersion is %s\n", 
> $printer->{ServicePackMinorVersion}, $machine;
> };
> ERROR:
>  
> C:\Scripting\toys>wmi.pl
> Win32::OLE(0.1707) error 0x80070005: "Access is denied"
> after character 0 in "winmgmts:\\server\root\cimV2" at 
> C:/Perl/site/lib/DBD/
> WMI.pm line 95
> Any help greatly appreciated.
>  
> Thanks
>  
> Dave
>  
> PS
> My system is...
> Host: WinXP SP2
> Perl: 5.8.8 Build 822
> DBD::WMI 0.06
> DBI 1.607
> 
> 
> 
> 
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Perl Net::LDAP question

2006-12-08 Thread Mark Leighton
Hadn't seen a reply to the post yet, but if you are still looking for the 
answer:

...

foreach $entry ($mesg->all_entries) {
print "dn: " . $entry->dn() . "";
foreach $attr ($entry->attributes()) {
   foreach $val ($entry->get_value($attr)) {
  printf("%s: %s", $attr, $val);
   }
}
}

Mark

Mark Funk wrote the following at 12/1/2006 6:12 PM:
> Folks,
> 
> I am trying to do an LDAP lookup to see if a user belongs to a certain group.
> I connect ok and LDAP only sends me the first member of the attribute group.
> Is there a way to list all members of an attribute group?
> 
> Code snippet:
>  use NET::LDAP;
>  $ldap = Net::LDAP->new( 'tcpauthprd' ) or die "$@";
>   
>  @mesg = $ldap->bind;# an anonymous bind
>   
>  @mesg = $ldap->search( base =>"ou=groups,o=xxx",
>   filter =>"(cn=reboot_rts)",
>   attrs => ['member']
> );
> 
> # If there is a result code (indicating an error),
> # display an error message
> if ($mesg->code) {
>   print "An error occurred during the LDAP search attempt:\n";
>   die $mesg->error;
> }
>  my $countOfEntriesReturned = $mesg->count;
>  print "Search returned $countOfEntriesReturned entries ...\n\n";
> 
> 
>  foreach $entry ($mesg->all_entries) {
> print "dn: " . $entry->dn() . "";
> @attrs = $entry->attributes();
> foreach $attr (@attrs) {
>printf("%s: %s", $attr, $entry->get_value($attr));
> }
>  }
> 
> 
> Results:
> User->tivplacenet 
> IP-->10.2.0.81 
> Search returned 1 entries ... 
> dn: cn=reboot_rts,ou=groups,o=xxx
> member: secAuthority=default
> 
> 
> In LDAP however, the member attribute holds the following multiple lines...
> 
> cn=reboot_rts,ou=groups,o=xxx
> member=secAuthority=default
> member=cn=ssanchez,ou=employees,o=childrensplace
> member=cn=eayala,ou=employees,o=childrensplace
> member=cn=rdaniel,ou=employees,o=childrensplace
> member=cn=amugnone,ou=employees,o=childrensplace
> member=cn=arivier,ou=employees,o=childrensplace
> member=cn=dlevitt,ou=employees,o=childrensplace
> member=cn=aginart,ou=employees,o=childrensplace
> member=cn=bsilletti,ou=employees,o=childrensplace
> member=cn=rgiambertone,ou=employees,o=childrensplace
> 
> TIA,
> David M. Funk
> President/CEO
> Tivoli Certified Enterprise Consultant
> Specializing in Network and Systems Management Solutions
> Trinity Solutions   
> 604 Cassandra Dr.
> Cranberry Twp., PA 16066
>  Phone: 724-316-0721
> Fax: 724-772-7889 
> email: [EMAIL PROTECTED]
> 
> 
---
Mark Leighton
CLIC Lan Supervisor, Information Commons, University of Toronto
Phone: (416) 946-7094   Fax: (416) 978-0440
E-mail: mark{DOT}leighton{AT}utoronto.ca

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Win32::TieRegistry Problem (no html this time)

2004-04-27 Thread Mark Leighton


steve silvers wrote:

I'm trying to run my script locally and trying to get all the exclusion 
lists from remote
computers. It runs great for my local machine or any machine I have 
remoted into, but the rest
just come back with:
Overlapped I/O operation is in progress
and returns nothing?
Is this a permission problem, and/or is this able to be done? My snippet 
is below
Thanks in advance
Steve

$ReadSettings  = 
$Registry->{"//$comp_name/CUser/Software/Microsoft/Windows/CurrentVersion/Internet 
Settings/ProxyOverride"}
 or  die "\t Problem reading Internet Settings - 
ProxyOverride \n\t $^E\n";

if($ReadSettings) {
print "\t SUCCESS: Gathered current Settings: - $comp_name 
\n\n\t $ReadSettings \n\n";
}

if(!($ReadSettings)) {
print "\t FAILURE: Can't get current Settings: - $comp_name 
\n\n\t $ReadSettings \n\n";
}

Hi Steve,

The problem is the 'CUser' part.  HKEY_CURRENT_USER is a link (just like a filesystem soft 
link) to the User hive owned by the session's current user.  Unless you have initiated a 
remote session, you don't have a session, and therefore there is no CUser for you, and 
hence your problem connecting to it.

Try enumerating through the subkeys of HKEY_USERS which is probably what you really want 
to do anyways.

Use Regedt32 to check a remote machine to see an example of this.

If you are looking to check the values on all user accounts, you may have to load the 
various hives under HKEY_USERS first.  Don't forget to unload them when you are finished 
or else you will be in for a world of pain.

Cheers,
Mark
--
Mark Leighton
CLIC Lan Supervisor, Information Commons, University of Toronto
E-mail: mark{DOT}leighton{AT}utoronto.ca
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Unattended perl installation

2001-01-22 Thread Mark Leighton

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> Martin
> Sent: Friday, January 19, 2001 6:18 PM
> To: [EMAIL PROTECTED]
> Subject: Unattended perl installation
>
>
> Hello,
>
> do you know by change how to do an unattended setup for perl (esp.
> Activestate Perl Built 521 or 623)?
>
> Have a nice weekend,
>
> Martin Fabiani

Hi Martin,

I have attached an unattended response file for the InstallShield installer for
ActiveState build 522.

This can be invoked with the command line:
APi522e.exe -a /s /f1APi522e.iss

You will want to add the Perl bin directory to your path and to install
additional modules you can download the tar'ed and gzip'ed ppm packages and the
.ppm definition files and invoke ppm for each.

This can be invoked as follows:
cmd /c ppm install Win32-AdminMisc.ppd

Inside the .ppd file there will be a CODEBASE tag with a relative path
eg. 

Therefore, there should be an x86 directory in the same directory as the
Win32-AdminMisc.ppd file.


Good luck,
Mark

-+--
Mark Leighton|Mark's Message Factory
CLIC Lan Administrator   |
Information Commons  |   One Hundred Monkeys on
University of Toronto|  One Hundred Typewriters -
 |  Serving YOU Daily.
E-mail: [EMAIL PROTECTED]| Please call for BULK rates.
-+--

 APi522e.iss