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

lo monks I am using perl on windows 2000 for a lot of admin work. I am trying to automate the runas command to get a dos prompt with admin rights and use that to move some files etc. runas /user:administrator cmd in windows with will give you Enter password for administrator: Is there a way to get perl to send the password to the prompt and then ENTER this would leave me with a admin cmd which I would need to send further instructions to. I can do this in vbs but I want to make it an exe so the admin password is not clear text. I tried
system('runas /user:administrator cmd'); sleep2; system('thepassword'); sleep2; system('echo did it work?'); but naturally the system waits until runas has finished before going o +n. VBS handles it like this set WshShell = CreateObject("WScript.Shell") WshShell.Run "C:\Winnt\System32\Runas.exe /USER:administrator cmd" WScript.Sleep 2000 '1 Send keys to enter password. WshShell.SendKeys "thepassword" WScript.Sleep 580 '1 Send Enter key. WshShell.SendKeys "{Enter}" WScript.Sleep 500 '1 Send other keys. WshShell.SendKeys "echo commands here run in admin mode" WScript.Sleep 500
any ideas?

Edit by tye to replace password

Replies are listed 'Best First'.
Re: sending test to command prompt
by Mr. Muskrat (Canon) on Feb 18, 2003 at 21:46 UTC

    Win32::GUITest is able to do just that (there are other modules but I haven't used them).

    The documentation shows you exactly how to do it and it's easy to understand!

      That looks ideal! I had a good look unfortunatly it requires an install and this is planned for systems that I can't get an install to. Know anything native to do this?
        ... this is planned for systems that I can't get an install to...

        I sincerely apologize if I seem overly paranoid, but I'm not sure I'd want to see this sort of question answered in a public forum. (In fact, I would rather hope that there isn't anything like a simple answer to this sort of question -- woe unto windows sysadmins if there is...)

        For that matter, I wonder if anyone has raised any questions or complaints about possible security risks involved with having Win32::GUITest available for use on a networked system. That would be worth knowing. (Not that I'm curious, personally; I'm not in that boat.)

Re: sending test to command prompt
by Limbic~Region (Chancellor) on Feb 18, 2003 at 21:54 UTC
    I do not have personal knowledge that Mr. Muskrat's suggestion of Win32::GUITest will work, but I trust him.

    I would only suggest being very careful to the sample data you provide as it appears:

    system('ypcwd21o');

    may actually be your administrator password.

    Cheers - L~R

      hehe it was! and now it is not! dam you cut and paste... dam you to hell <G>. that'll keep me laughing for some time, by gum its been a while but it an't the first time. nice catch