Hi Monks,

I have a problem that I cant seem to get around that I'm hoping someone can help with.

I'm writing a little app that will allow users to administer their own applications on a weekly basis (i.e we dont want to keep dealing with user requests for Visio but we dont want to give it to everyone either!)

I have the front end for the app done but my problem comes with the addition of the user to the required group in Active Directory.

The application runs via Citrix (compiled as an exe) and thus runs under the users own profile. We doont want to give the user rights to update AD (for obvious reasons) so the part of the script that does the group add has to run under an admin user banner.

So far, heres the addgroup sub I've come up with:

sub add2Grp { my $group = $_[0]; my $user = $_[1]; print "Adding: $group to: $user\n"; my $win32 = Win32::OLE->new('WScript.Shell') || die "Can not creat +e WScript Shell; $!\n"; my $result = $win32->Run('runas /noprofile /user:DOMAIN\\USER Net +Group $group $user /ADD /DOMAIN'); sleep(3); $win32->SendKeys('password~'); return "$result"; }

$group and $user are passed in correctly and the testing I've done so far with wscript (making it launch a cmd prompt under the elevated credentials) has worked.

However, I cant figure out how to get the data back from the NET ADD command? Basically, I want to return whatever the feedback is from the command line (which will either be "the command completed successfully" or some error) so that I can check within the program whether or not its worked.

At the minute, that return just gives me an OLE hashref and I cant figure out what value within that hash will give me what I want.

Can anyone help?

Also, feel free to tell me theres a better way to do this if there is one (running a certain part of the script as someoene else)


In reply to Win32::OLE and Wscript Shell -> Getting data back by Gaz5

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.