#!/usr/local/bin/perl
# 
# $Header: wintools.pl 05-dec-2006.22:29:56 manosing Exp $
#
# wintools.pl
# 
# Copyright (c) 2006, Oracle. All rights reserved.  
#
#    NAME
#      wintools.pl - <one-line expansion of the name>
#
#    DESCRIPTION
#      <short description of component this file declares/defines>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    manosing    11/28/06 - Creation
#
#
#
#


require "$ENV{EMDROOT}/sysman/admin/scripts/db/esaUtils.pl";

if($^O ne "MSWin32"){
    exit(0);
}

my $maxRow=$ENV{"WINTOOL"};

if($maxRow==0){
   exit(0);
}
  
  my $oracleHome = $ENV{EM_TARGET_ORACLE_HOME};
  
  my $limit=0;

  my $p="$ENV{'systemroot'}"."\\system32";
  my $arrRef;
  my %hash;

  opendir(DIRHANDLE,$p)||exit(1);
  @cont = grep /^.*\.exe$/,readdir(DIRHANDLE);
  close DIRHANDLE; 

  my $owner = win32_file_owner($oracleHome);
  if($owner ==-1){
      exit(0);
  }
  foreach $ele ( @cont){
      my $t = "$p\\$ele";
      my ($res, $numRows) =  getACLs($t,9000); #we want all entries. Hoping 9000 is enough.
      
      if($res == -1){
          exit(0);
      }
      %hash = %$res;      
      $arrRef = $hash{$owner};
      if($arrRef ne ""){
          print "em_result=win_tools|$ele\n";
          $limit++;
          if($limit>=$maxRow && $maxRow!=-1){
              exit(0);
          }
      }
  }
  
 
