Solved

perl-getting installed application details from Remote windows machine

Posted on 2008-06-24
11
907 Views
Last Modified: 2010-04-28
Hi,
I have a Perl script to fecth installed applications from a remote windows machine.

This script gets the installed applications from the registry.

This script works fine when I connect my machine to the same domain as the remote host. But it does not fecth any results if my machine is removed from the domain. Which means if  I want to fecth the installed applications of a remote machine, I have to connect my machine to that domain first. This does not solve my purpose as i want to use this script to fecth installed applications from different domains simultaneously.

Please Help!
my %Software;

GetSoftwareInfo ($ip,\%Software);

sub GetSoftwareInfo

{

    my ( $ip, $SoftwareInfo ) = @_;

    my ( @Var, %Uninstall );

   %Uninstall = %{ $Registry->{"//$ip/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall"} };

        undef ( @Var );

        foreach my $Key ( keys %Uninstall )

        {

            next if ( $Key =~ m/^\//i );

            next if ( $Uninstall{$Key}->{'/DisplayName'} eq '' );

            $version=$Var[++$#Var]{Version}   = $Uninstall{$Key}->{'/DisplayVersion'};

            $Var[$#Var]{DisplayName} = $Uninstall{$Key}->{'/DisplayName'};

            $Var[$#Var]{InstallDate} = $Uninstall{$Key}->{'/InstallDate'};

            $Var[$#Var]{Publisher}   = $Uninstall{$Key}->{'/Publisher'};

            $Key                     =~ s/\///ig;

            $Var[$#Var]{ProdID}      = $Key;

}    

    }

Open in new window

0
Comment
Question by:SathishkumarRaman
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:APNFSSC
Comment Utility
do you know the domain admin or local admin usernames and passwords on all machines in question?
0
 

Author Comment

by:SathishkumarRaman
Comment Utility
Yes i know the user name and password for all the remote systems.i can able to get the application details when the server and the remote system having the same password.But when  the server system having the different password its not collecting.
Example: Remote system -->user name:test ; pswd:test@123   Monitoring system -->User name:admin; Pswd:win@123


 
0
 
LVL 10

Expert Comment

by:APNFSSC
Comment Utility
The Win32::Registry module wont do the authentication as you know.

is your monitoring system a windows server?

If it is you could use psexec

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

you can call that from inside your perl script and pass the username and password to it.

Using psexec you could execute something like this and then open the file up and read in the data.

regedit.exe /e \\someserver\share\hostname.reg HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

Also if it is windows then maybe you could do a "net use" and map the c$ on the remote machine to establish the authentication between the two machines. Then your above code may work as the two machines are already authenticated. Once your code is run then disconnect the mapped driver. This is obviously slower.

Hope this helps
0
 

Author Comment

by:SathishkumarRaman
Comment Utility
Hi
Thank you. Is it possible to pass the credentials along with the remote server name.Because my script is an automated script there should not be an intaractive session between user and system.So have to pass the credentials for the remote windows servers by the program itself.Please guide.
0
 
LVL 10

Expert Comment

by:APNFSSC
Comment Utility
Yes it is possible.

Have a look at the link I provided above it has all this information.

-u    Specifies optional user name for login to remote computer. this can be remotecomputername\username or domain\username
-p    Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.

psexec \\remotecomputername -u remotecomputername\administrator -p adminpass ipconfig

Usage: psexec [\\computer[,computer2[,...] | @file][-u user [-p psswd]][-n s][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,... ] cmd [arguments]

computer	Direct PsExec to run the application on the computer or computers specified. If you omit the computer name PsExec runs the application on the local system and if you enter a computer name of "\\*" PsExec runs the applications on all computers in the current domain.

@file	Directs PsExec to run the command on each computer listed in the text file specified.

-a	Separate processors on which the application can run with commas where 1 is the lowest numbered CPU. For example, to run the application on CPU 2 and CPU 4, enter: "-a 2,4"

-c	Copy the specified program to the remote system for execution. If you omit this option then the application must be in the system's path on the remote system.

-d	Don't wait for application to terminate. Only use this option for non-interactive applications.

-e	Does not load the specified account's profile.

-f	Copy the specified program to the remote system even if the file already exists on the remote system.

-i	Run the program so that it interacts with the desktop of the specified session on the remote system. If no session is specified the process runs in the console session.

-l	Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity.

-n	Specifies timeout in seconds connecting to remote computers.

-p	Specifies optional password for user name. If you omit this you will be prompted to enter a hidden password.

-s	Run remote process in the System account.

-u	Specifies optional user name for login to remote computer.

-v	Copy the specified file only if it has a higher version number or is newer on than the one on the remote system.

-w	Set the working directory of the process (relative to the remote computer).

-x	Display the UI on the Winlogon desktop (local system only).

-priority	Specifies -low, -belownormal, -abovenormal, -high or -realtime to run the process at a different priority. Use -background to run at low memory and I/O priority on Vista.

program	Name of the program to execute.

arguments	Arguments to pass (note that file paths must be absolute paths on the target system)
 

 

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:SathishkumarRaman
Comment Utility
Hi
I have used the same method u have mentioned with credentials.Its working good.The thing is when i am giving a list of ips to use psexec, if the ips is not pingable or it is not an windows sytem the script getting stopped.Though its an automated script it should run without any struggle.If the selected ip is not in use it should automatically go for the next ip to use with psexec.Please help. I have attached my code part here.


system("start c:\\psexec.exe \\\\$ip -u $user -p $psd cmd");

SendKeys ("{ENTER}");

sleep(3);

SendKeys("regedit.exe /e \\\\$ip\\c\$\\windows\\system32\\hostname.txt HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");

SendKeys("{ENTER}");

sleep(5);

SendKeys("exit");

SendKeys("{ENTER}");

sleep(1);

system("start cmd");

sleep(1);

SendKeys("cd\\");

SendKeys("{ENTER}");

sleep(1);

SendKeys("type \\\\$ip\\c\$\\windows\\system32\\hostname.txt >c:\\apps.txt");

SendKeys("{ENTER}");

sleep(2);

SendKeys("exit");

SendKeys("{ENTER}");

sleep(1);

Open in new window

0
 
LVL 10

Expert Comment

by:APNFSSC
Comment Utility
will this not work?
system("c:\\psexec.exe \\\\$ip -u $user -p $psd regedit.exe /e \\\\monitoringstation\\applists\\hostname.txt HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");

Open in new window

0
 
LVL 10

Expert Comment

by:APNFSSC
Comment Utility
please note

you need to make a share on your monitoring stations called applists and make it writable to everyone
also replace the name monitoringstation with the hostname or ip address of the host the share is on.

\\\\monitoringstation\\applists
0
 

Author Comment

by:SathishkumarRaman
Comment Utility
Hi
Yes i did the same.Let me clear about what exactly the problem is.That command is working with the windows system.The script is automatically executing this command for a list of given ip.When any of the ip is not pingable from the monitoring system from where the script is running, the script gets struck in that stage itself  and not moving to the next ip to execute with the psexec command or the script gets closed completely.

Example:
If the IP range is 192.168.10.50 to 192.168.10.55
consider the IP 192.168.10.53 is down or it is a non windows system.
The script is running good upto 192.168.10.52 when its starting to execute the psexec command for that 53 IP the script is getting struck. In this case what i need  to do is the script should skip the error and go for the next IP to execute the command.Please guide me further.
0
 
LVL 10

Accepted Solution

by:
APNFSSC earned 500 total points
Comment Utility
Hi

Try putting a -n in the command and setting it to 5 then it will exit after trying for 5 seconds.

-n      Specifies timeout in seconds connecting to remote computers.
0
 

Author Closing Comment

by:SathishkumarRaman
Comment Utility
Thankyou so much for your guindance and help. :-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now