Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

software inventory

by grashoper (Monk)
on May 12, 2008 at 20:09 UTC ( #686140=perlquestion: print w/replies, xml ) Need Help??

grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I tried to output version of windoze into my inventory file but it still does not work am I doing something wrong with my system() call here? I get the process cannot access the file because it is being used by another process..
#!Perl use strict; use Win32::TieRegistry(Delimiter=>"/"); # I have an environmental variable set with computernames # so I utilize that... # my $PC = "MYPC"; my $PC = $ENV{COMPUTERNAME}; # Get the Installed software my %Uninstall = %{ $Registry->{"//$PC/HKEY_LOCAL_MACHINE/SOFTWARE/Micr +osoft/Windows/CurrentVersion/Uninstall"} }; my $version; my $Outfile; my $fh2; open $Outfile, ">$PC.csv" or die "Unable to open $PC.csv\n"; system ( "ver > $PC.CSV"); foreach my $Keys ( sort keys %Uninstall ) { print $Outfile join(',', &escape($Uninstall{$Keys}->{'/Publisher'} +), &escape($Uninstall{$Keys}->{'/DisplayVers +ion'}), &escape($Uninstall{$Keys}->{'/InstallDate +'}), &escape($Uninstall{$Keys}->{'/DisplayName +'}), &escape($Keys))."\n"; } sub escape { my $entry = shift; $entry =~ s/,//g; $entry =~ s/\///g; return $entry; }

Replies are listed 'Best First'.
Re: software inventory
by moritz (Cardinal) on May 12, 2008 at 20:21 UTC
    The first step is to describe your problem, but it still does not work doesn't tell us what's going wrong.

    The system call looks suspicious indeed, you need to quote all of the arguments into one string.

Re: software inventory
by toolic (Bishop) on May 12, 2008 at 20:30 UTC
    am I doing something wrong with my system() call here?
    Good question. You should check the status of your system call to find out if you are doing something wrong:
    system ("your command here") and die "command failed\n";
Re: software inventory
by Old_Gray_Bear (Bishop) on May 12, 2008 at 21:52 UTC
    Are you sure that the ver() command is what you want?
    C:\Documents and Settings\ogb> ver /c The syntax of the command is incorrect.
    This is on Windows XP, SP2 plus security patches.

    Update:

    C:\Documents and Settings\ogb> help ver Displays the Windows XP version. VER
    It looks like /c isn't valid

    ----
    I Go Back to Sleep, Now.

    OGB

      Yeah I thought the /c would create a seperate instance of the command prompt guess not..whoops.. that may be all I need to fix, thanks, it does create the file, it just doesn't have the os in it, that explains why.
        Actually its cause perl doesn't release the filehandle, it locks it and it won't let me modify, not sure how to get around this problem, I just made up another filename, I do want to fix but may be using netwallah suggestion instead as I think they want more than just software in their inventory. thanks to all of you for your input and suggestions.
Re: software inventory
by NetWallah (Canon) on May 12, 2008 at 21:21 UTC
    Have you considered using the free and powerful OCS Inventory tool ?

         "How many times do I have to tell you again and again .. not to be repetitive?"

      Thanks NetWallah, that may indeed do what I need, I will have to check with my netadmin to see if I can get a pc for it. looks awesome though! Thanks
Re: software inventory
by chromatic (Archbishop) on May 13, 2008 at 03:20 UTC
    I get the process cannot access the file because it is being used by another process...

    I'm not terribly surprised:

    open $Outfile, ">$PC.csv" or die "Unable to open $PC.csv\n"; system ( "ver > $PC.CSV");

    What do you intend this code to do?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://686140]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2021-10-22 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?