Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 918
  • Last Modified:

perl-getting installed application details from Remote windows machine

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
SathishkumarRaman
Asked:
SathishkumarRaman
  • 6
  • 5
1 Solution
 
APNFSSCCommented:
do you know the domain admin or local admin usernames and passwords on all machines in question?
0
 
SathishkumarRamanAuthor Commented:
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
 
APNFSSCCommented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
SathishkumarRamanAuthor Commented:
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
 
APNFSSCCommented:
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
 
SathishkumarRamanAuthor Commented:
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
 
APNFSSCCommented:
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
 
APNFSSCCommented:
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
 
SathishkumarRamanAuthor Commented:
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
 
APNFSSCCommented:
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
 
SathishkumarRamanAuthor Commented:
Thankyou so much for your guindance and help. :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now