A Simple (Minded?) Windows sudo Substitute for Cygwin in Perl

With a little Win32::FileOp magic, it is easy to whip up a simple (minded?) Windows sudo(1) substitute for Cygwin:

#!/usr/bin/env perl

# ------ pragmas
use strict;
use warnings;
use Win32::FileOp;

Win32::FileOp::ShellExecute( runas => "cmd.exe", "/k " . join(' ', @ARGV) );

Apart from how you start it, a similar approach should work for Strawberry Perl once Win32::FileOp is installed.

The underlying idea is that usually (at least for *me*) I don't care whether I am actually executing as the Administrator account -- I just temporarily need the Administrator's account's permissions (like for netstat -ab under Windows).

Note that this creates a separate console window that stays open after your command has completed. (A *real* sudo(1) substitute would work in the current console window, but that would take more time than I have available now during this session of yak-shaving.)


"A simple 'su' substitute" might be more accurate.

Leave a comment

About Mark Leighton Fisher

user-pic Perl/CPAN user since 1992.