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

Hi, i try to get the name of the shared printers that user's from our domain installed . when i run it under my machine name it work great but when run it under other users machine name i get no output. any idea why? thanks.
use Win32::OLE qw(in with); use Win32::Registry; use Win32::OLE('in'); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my $WMI = Win32::OLE->new('WbemScripting.SWbemLocator') || die "Cannot access WMI on local machine: ", Win32::OLE->LastError; $host = "COMPUTER"; my $Services = $WMI->ConnectServer($host) || die "Cannot access WMI on remote machine: ", Win32::OLE->LastError; my $sys_set = $Services->InstancesOf("Win32_Printer"); foreach my $sys (in($sys_set)) { my $share = $sys->{Shared}; if ($share eq 1) { print $sys->{ShareName}; } }

Replies are listed 'Best First'.
Re: Mapped Printer
by BrowserUk (Patriarch) on Aug 11, 2011 at 13:11 UTC
    when run it under other users machine name i get no output. any idea why?

    Perhaps because the userid you are running it under on your machine, does not have permissions on the remote machine, to access that information.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      No, i have Administrator account plus i can get alot of other data from wmi just the shared printer i cant

        Are the printers mapped to the machine, or the userid?

        That is, Windows allows some resources to only be visible to individual users, not to anyone who uses the machine. If the Administrator id you are using has never had those printer mappings assigned to it, then they will be invisible to it.

        Also, for an Administrator id to have privileges on other machines, it needs to be a Domain Administrator account, not a local Administrator account.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.