Re: scripting elevated privilege on Windows 7

2010-04-17 Thread Robert Pendell
On Fri, Apr 16, 2010 at 12:33 PM wrote:
 Thank you Robert Pendell! I wrote this shell script. Any suggestions
 for optimization?

 #!/bin/bash
 if [ $# -eq 1 ]
 then
        echo Usage: elev program arg1 arg2 ...
        exit 1
 fi
 prog=$1
 shift
 exec cygstart --action=runas `which $prog` $@



It looks fine (beyond the quoting) but there is an error.

In your if test you check the number of parameters and check to see if
there is exactly one then throw the message.  It should be zero rather
than one because it doesn't count the current process name.

On that note I might suggest replacing 'elev' in the Usage text with
$0 so it can reflect the file it was called as.

On and while quoting works there are better ways as Eric had already
suggested.  I didn't bother changing it but the following script works
well and is tested.

#!/bin/bash
if [ $# -eq 0 ]
then
 echo Usage: $0 program arg1 arg2 ...
 exit 1
fi
prog=$1
shift
exec cygstart --action=runas `which $prog` $@

On that note if you plan on reusing the script on xp or older (for
portability) then you might want to check the platform os so that you
don't use that action setting on them.  The runas action is only valid
on Windows Vista and Windows 7 since that is when it was added.

Robert Pendell
shi...@elite-systems.org
CAcert Assurer
A perfect world is one of chaos.

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: scripting elevated privilege on Windows 7

2010-04-16 Thread DavidArnstein
Thank you Robert Pendell! I wrote this shell script. Any suggestions
for optimization?

#!/bin/bash
if [ $# -eq 1 ]
then
echo Usage: elev program arg1 arg2 ...
exit 1
fi
prog=$1
shift
exec cygstart --action=runas `which $prog` $@


--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: scripting elevated privilege on Windows 7

2010-04-16 Thread Eric Blake
On 04/16/2010 10:33 AM, davidarnst...@panix.com wrote:
 Thank you Robert Pendell! I wrote this shell script. Any suggestions
 for optimization?
 
 #!/bin/bash
 if [ $# -eq 1 ]
 then
 echo Usage: elev program arg1 arg2 ...
 exit 1
 fi
 prog=$1

In assignment, there is no field splitting, so  is redundant; this is
equivalent:

prog=$1

 shift
 exec cygstart --action=runas `which $prog` $@

You are missing some quotes, and might as well use nicer quoting styles:

exec cygstart --action=runas $(which $prog) $@

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: scripting elevated privilege on Windows 7

2010-04-16 Thread Eric Blake
On 04/16/2010 11:37 AM, Eric Blake wrote:
 You are missing some quotes, and might as well use nicer quoting styles:
   ^^^
command substitution styles

 
 exec cygstart --action=runas $(which $prog) $@

And I'm missing quotes, too.

exec cygstart --action=runas $(which $prog) $@

I'll go back and hide in my hole now :(

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


scripting elevated privilege on Windows 7

2010-04-15 Thread DavidArnstein
I am dealing with Windows UAC for the first time. From a script, I would
like to launch a process with elevated (administrative) privilege. I
can accept that Windows will pop up a modal dialog box confirming the
elevated privilege.

Is there an existing utility in Cygwin or elsewhere.

An example of what I would like: I have a program named backall that 
I want to execute with administrative privelege. I am looking for some
command xxx that I could invoke from a shell script as
xxx backall

Does such a utility exist? If I wanted to enhance cygstart to support
this feature, which Microsoft API should I use?

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: scripting elevated privilege on Windows 7

2010-04-15 Thread Robert Pendell
On Thu, Apr 15, 2010 at 9:43 PM wrote:

 I am dealing with Windows UAC for the first time. From a script, I would
 like to launch a process with elevated (administrative) privilege. I
 can accept that Windows will pop up a modal dialog box confirming the
 elevated privilege.

 Is there an existing utility in Cygwin or elsewhere.

 An example of what I would like: I have a program named backall that
 I want to execute with administrative privelege. I am looking for some
 command xxx that I could invoke from a shell script as
        xxx backall

 Does such a utility exist? If I wanted to enhance cygstart to support
 this feature, which Microsoft API should I use?



I took a look at the source code as well as did some research and
luckily ShellExecuteEx already has a provision for this.  Cygstart
also has a parameter that will allow for this although there is no
quick option for it.  I have tested and verified.  It will not path
search so you must specify the file location or be in the folder where
the program resides.

Run the following command and it will prompt for elevation.

cygstart --action=runas command

Replace command with the actual command.  This is an example and it
does prompt and elevate.

cygstart --action=runas /cygdrive/c/windows/system32/cmd.exe

Robert Pendell
shi...@elite-systems.org
CAcert Assurer
A perfect world is one of chaos.

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple