#!/usr/bin/perl

$True = 1;
$False = 0;

$WinDir = $ENV{'WINDIR'};

$InFile = = $WinDir . "\\NT43rdParty.txt";   
$OutFile = = $WinDir . "\\NT43rdApplist.txt";

open IN, "<$InFile", or die "Cannot open $InFile for Reading :$!";
open OUT, ">$OutFile", or die "Cannot open $OutFile for Writing :$!";
open COPY, ">$CopyInFile", or die "Cannot open $CopyInFile for Writing :$!";

#foreach $key (keys %ENV){printf OUT "%s = %s \n", $key, $ENV{$key};}
#print OUT "WINDIR = "; printf OUT "%s \n", $ENV{'WINDIR'};
#$Windir = printf OUT "%s", $ENV{'WINDIR'};

LINE: while (<IN>) {
    print COPY ;
      chomp($_);      

      if($_ =~/Extra Services/i){
          $Services = $True;
          next LINE;         
      }             

      if($_ =~/Extra Application links on the Start Menu/i){
          $StartMenu = $True;        
          next LINE;         
      }             

      if($_ =~/Extra Anything on the Desktop/i){
          $Desktop = $True;
          next LINE;         
      }

      if($_ =~/Extra Control Panel items/i){
          $ControlPanel = $True;
          next LINE;         
      }

      if($_ =~/\.txt|\.bmp|\.jpg|\.gif|\.pcx/i){
          $textFileFound = $True;
          next LINE;         
      }

      if($_ =~/\.(exe|com|bat|cmd|lnk)/i){

          s/((^.*:)(Application Links:))|((^.*:)(Desktop Links:))//;
          
          printf OUT "%s", $ENV{'WINDIR'}; 
          print OUT "\\Profiles\\", $_, "\n";
          next LINE;         
      }

      if($_ =~/\.(cpl)/i){

          s/((^.*:)(Control Panel:))//;
          
          printf OUT "%s", $ENV{'WINDIR'}; 
          print OUT "\\System32\\", $_, "\n";
          next LINE;         
      }
                                              

}
