[PATCH cygutils 1/1] cygstart: add 'runas' as option to elevate privileges like UAC

"Vadim \(vadcx\) via Cygwin-apps" <[email protected]>
Newsgroups gmane.os.cygwin.applications
Message-ID <eaa953eec8878b5b02f640072bc712c6c27b9cdd.1754488649.git.vad.git@vad.cx>
From: "Vadim (vadcx)" <[email protected]>

Inspired by https://stackoverflow.com/q/4090301

If other known actions have easy aliases, runas should have one too and hint at
its existence.
---
 src/cygstart/cygstart.1 |  4 ++++
 src/cygstart/cygstart.c | 14 ++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/cygstart/cygstart.1 b/src/cygstart/cygstart.1
index c641a4c..7701115 100644
--- a/src/cygstart/cygstart.1
+++ b/src/cygstart/cygstart.1
@@ -56,6 +56,10 @@ Short for: \fB\-\-action\fP \fIfind\fP
 \fB\-p\fP, \fB\-\-print\fP
 Short for: \fB\-\-action\fP \fIprint\fP
 
+.TP
+\fB\-r\fP, \fB\-\-runas\fP
+Short for: \fB\-\-action\fP \fIrunas\fP
+
 .TP
 \fIDirectory options\fP
 
diff --git a/src/cygstart/cygstart.c b/src/cygstart/cygstart.c
index 7e5bf3a..d995d9b 100644
--- a/src/cygstart/cygstart.c
+++ b/src/cygstart/cygstart.c
@@ -41,6 +41,7 @@
 #define ACTION_EDIT "edit"
 #define ACTION_FIND "find"
 #define ACTION_PRINT "print"
+#define ACTION_RUNAS "runas"
 
 /* MSDN reference URL */
 #define MSDN_URL "http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx"
@@ -150,6 +151,8 @@ main (int argc, const char **argv)
      "Short for: --action find", NULL},
     {"print", 'p', POPT_ARG_NONE, NULL, 'p',
      "Short for: --action print", NULL},
+    {"runas", 'r', POPT_ARG_NONE, NULL, 'r',
+     "Short for: --action runas", NULL},
     {NULL, '\0', 0, NULL, 0, NULL, NULL}
   };
 
@@ -223,7 +226,7 @@ main (int argc, const char **argv)
      "Display version information", NULL},
     {"license", '\0', POPT_ARG_NONE, NULL, 'l',
      "Display licensing information", NULL},
-    {"reference", '\0', POPT_ARG_NONE, NULL, 'r',
+    {"reference", '\0', POPT_ARG_NONE, NULL, 'W',
      "Open MSDN reference for ShellExecute", NULL},
     {NULL, '\0', 0, NULL, 0, NULL, NULL}
   };
@@ -294,7 +297,7 @@ main (int argc, const char **argv)
           if (workDir)
             free (workDir);
           return (0);
-        case 'r':
+        case 'W':
           cygStart (MSDN_URL, NULL, NULL, NULL, SW_NORMAL, startFlags);
           poptFreeContext (optCon);
           free (program_name);
@@ -350,6 +353,13 @@ main (int argc, const char **argv)
               exit (1);
             }
           break;
+        case 'r':
+          if ((action = mbstowcs_dup (ACTION_RUNAS)) == NULL)
+            {
+              fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+              exit (1);
+            }
+          break;
 
           /* Directory options */
         case 'd':
-- 
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.