Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Win32::Process::Create with elevated privileges on Windows 7

by stringZ (Acolyte)
on Oct 20, 2011 at 22:48 UTC ( #932777=perlquestion: print w/ replies, xml ) Need Help??
stringZ has asked for the wisdom of the Perl Monks concerning the following question:

Hey there, I would like to start an executable (test.exe) that has been set to start with administrator privileges. This means I set it up manually by right clicking on it (Properties), going to Compatibility tab, and checking the bottom checkbox (run as administrator).
use Win32::Process; Win32::Process::Create($proc, 'C:\test.exe', 'test.exe', 0, NORMAL_PRI +ORITY_CLASS, '.')
I'm running my perl script as a normal user, and it can't start this executable mentioned above, because it can't get admin rights. This makes sense, but when I start test.exe manually (from Total Commander or Windows Explorer) it blanks out the screen and asks for approval of giving it elevated privileges. I want Win32::Process::Create do the same, because now it doesn't ask anything, it just fails to start the application.

Is there a workaround using Win32::Process?
Alternatively, is there a way or a special parameter that would ask for administrator privileges before trying to create a process out of this application?

My Win32::Process version is 0.14 and I'm running Windows 7 with UAC enabled.

Thanks in advance,
stringZ

Comment on Win32::Process::Create with elevated privileges on Windows 7
Download Code
Re: Win32::Process::Create with elevated privileges on Windows 7
by BrowserUk (Pope) on Oct 20, 2011 at 22:56 UTC

    Try Win32::FileOp::ShellExecute( open => 'theProgram.exe' )


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.
      Thank you. This one works, helped a lot :)

      And if you want to run-as-administrator a program that's not set to run only with admin rights, try

      Win32::FileOp::ShellExecute( runas => 'theProgram.exe' )

      To run it as a different user use "runasuser" instead of "runas".

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

        Another good one, thanks. Other people who read this should note that this solution only works on Windows 7 (or Vista - haven't tested). On XP it won't start anything with "runas".
Reaped: Re: Win32::Process::Create with elevated privileges on Windows 7
by NodeReaper (Curate) on Oct 22, 2011 at 12:34 UTC
Reaped: Re: Win32::Process::Create with elevated privileges on Windows 7
by NodeReaper (Curate) on Oct 24, 2011 at 12:57 UTC
Re: Win32::Process::Create with elevated privileges on Windows 7
by Anonymous Monk on Oct 25, 2011 at 10:40 UTC
    your problem is with "windows 7 UAC enabled". The fact is you can have the admin rights its just windows 7 needs to know "Windows Explorer" is open so UAC can link up with your admin rights to make it run.

    But there are big problems with using UAC in windows 7 with Perl and one thing is if your program spits out a file it made and your in another folder with "Windows Explorer" the file will be copy'ed to the folder your currently viewing instead.

    Pure Fact: Perl works best on *nix systems!!!!!!!!!!!!!!!!

      If find it ironic that the same people who espouse that the unix shells (which one?) is what makes *nix superior to Windows, also tend to be the ones that claim that Perl works best on *nix.

      Ironic because Perl's original raison d'etre was to work around the complexities and deficiencies of those *nix shells.

      Which means that if the Windows shells are even more limited than the *nix ones, Perl is even more useful there.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://932777]
Approved by BrowserUk
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-09-03 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls