├── Sudo ├── tools │ ├── chocolateyUninstall.ps1 │ └── chocolateyInstall.ps1 ├── Sudo.1.1.3.nupkg ├── bin │ ├── sudo.cmd │ └── sudo.vbs ├── Sudo.1.1.3.nuspec └── Readme.md ├── README.md └── LICENSE /Sudo/tools/chocolateyUninstall.ps1: -------------------------------------------------------------------------------- 1 | Remove-BinFile 'Sudo' 'sudo.exe' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | chocolatey-packages 2 | =================== 3 | 4 | Packages for Chocolatey.org 5 | -------------------------------------------------------------------------------- /Sudo/Sudo.1.1.3.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/janhebnes/chocolatey-packages/HEAD/Sudo/Sudo.1.1.3.nupkg -------------------------------------------------------------------------------- /Sudo/bin/sudo.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: Pass execution context information through environment variables. 4 | set SUDO_CMDLINE=%* 5 | set SUDO_ARG1=%1 6 | set SUDO_ARG2=%2 7 | set SUDO_CD="%CD%" 8 | set SUDO_DRIVE=%CD:~0,2% 9 | 10 | :: %~dpn0 is refering to this files name and %* sends along the full commandline 11 | cscript //nologo "%~dpn0.vbs" %* 12 | -------------------------------------------------------------------------------- /Sudo/tools/chocolateyInstall.ps1: -------------------------------------------------------------------------------- 1 | Remove-BinFile 'Sudo' '..\lib\Sudo.1.0\bin\sudo.cmd' 2 | Remove-BinFile 'Sudo' '..\lib\Sudo.1.0\bin\sudo.vbs' 3 | Remove-BinFile 'Sudo' '..\lib\Sudo.1.0.1\bin\sudo.cmd' 4 | Remove-BinFile 'Sudo' '..\lib\Sudo.1.0.1\bin\sudo.vbs' 5 | Remove-BinFile 'Sudo' '..\lib\Sudo.1.1.0\bin\sudo.cmd' 6 | Remove-BinFile 'Sudo' '..\lib\Sudo.1.1.0\bin\sudo.vbs' 7 | Generate-BinFile 'Sudo' '..\lib\Sudo\bin\sudo.cmd' 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Jan Hebnes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Sudo/Sudo.1.1.3.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Sudo 5 | 1.1.3 6 | Sudo 7 | Jan Hebnes 8 | Jan Hebnes 9 | 10 | http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html 11 | https://github.com/janhebnes/chocolatey-packages/tree/master/Sudo 12 | false 13 | Used from a command line as e.g. "sudo cmd" or "sudo notepad" to elevate directly from the shell, can preserve current directory using e.g "sudo . cmd" 14 | Sudo is used to elevate to administrator from the command line. 15 | (Version 1.1) Introduces option for preserving current directory. e.g. "sudo . cmd" or just "sudo ." (Version 1.1.1) Added -V and --version parameters for checking version (Version 1.1.2) Retain current directory even with special chars (Version 1.1.3) Fix choco uninstall sudo not deleting sudo.exe shim 16 | sudo console cmd command elevate administrator 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Sudo/Readme.md: -------------------------------------------------------------------------------- 1 | ### [https://chocolatey.org/packages/Sudo](https://chocolatey.org/packages/Sudo) 2 | 3 | λ choco install sudo 4 | or 5 | λ choco upgrade sudo 6 | 7 | 8 | # sudo /? 9 | 10 | Start application that prompt for elevation (Run as Administrator). 11 | 12 | SUDO command 13 | >elevate command 14 | 15 | SUDO . command 16 | >elevate and preserve current directory 17 | 18 | SUDO _ command 19 | >elevate and preserve current directory but hide context window used to set context 20 | 21 | SUDO notepad %cd%\hosts 22 | > *Note also the option of getting the current directory using %CD%\ where you would have used .\ on file path arguments* 23 | 24 | SUDO -V 25 | >returns the version and source 26 | 27 | Examples: 28 | 29 | sudo cmd /k cd "C:\Program Files" 30 | or sudo . cmd 31 | or sudo . 32 | 33 | sudo powershell -NoExit -Command Set-Location 'C:\Windows' 34 | or sudo . powershell 35 | 36 | sudo notepad "c:\Windows\System32\drivers\etc\hosts" 37 | or sudo _ notepad hosts 38 | or sudo notepad %cd%\hosts 39 | 40 | sudo -V 41 | sudo --version 42 | 43 | Sudo version 1.1.3 44 | https://chocolatey.org/packages/Sudo 45 | https://github.com/janhebnes/chocolatey-packages/tree/master/Sudo 46 | 47 | 48 | 49 | Note that keeping current directory requires an elevated cmd shell 50 | that sets directory context before executing your command. 51 | 52 | You can also keep context by working with %CD%\ on file locations. 53 | 54 | Usage with scripts: When using the sudo command with scripts such as 55 | Windows Script Host or Windows PowerShell scripts, you should specify 56 | the script host executable (i.e., wscript, cscript, powershell) as the 57 | application. 58 | 59 | Sample usage with scripts: 60 | 61 | sudo cscript "C:\windows\system32\slmgr.vbs" 62 | sudo powershell -NoExit -Command & 'C:\Temp\Test.ps1' 63 | 64 | 65 | The sudo command consists of sudo.cmd and sudo.vbs 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Sudo/bin/sudo.vbs: -------------------------------------------------------------------------------- 1 | ' //*************************************************************************** 2 | ' // ***** Script Header ***** 3 | ' // 4 | ' // File: Sudo.vbs 5 | ' // Additional files required: Sudo.cmd 6 | ' // 7 | ' // Purpose: To provide a command line method of launching applications that 8 | ' // prompt for elevation (Run as Administrator). 9 | ' // 10 | ' // Usage: (Not used directly. Launched from Sudo.cmd) 11 | ' // 12 | ' // Version: 1.1.3 13 | ' // Date : 21-dec-2022 14 | ' // 15 | ' // History: 16 | ' // 1.0.0 01-Feb-2007 Created initial version used internally. 17 | ' // 1.0.1 01-Mar-2007 Added detailed usage output. 18 | ' // 1.0.0 23-Oct-2013 Released on chocolatey 19 | ' // 1.0.1 08-Sep-2014 chocolatey framework changes required new version 20 | ' // 1.0.2 12-Jun-2015 chocolatey framework changes required new version 21 | ' // 1.1.0 20-Apr-2018 Added the option of keeping current directory 22 | ' // context by using the inserted . or _ as first command argument 23 | ' // when used a context cmd shell window is opened for setting 24 | ' // current directory context using _ hides this window 25 | ' // 1.1.1 04-Feb-2019 Added the -V or -version option to query the version of sudo 26 | ' // 1.1.2 27-dec-2019 Retain current directory even with special chars (janusblack) 27 | ' // 1.1.3 21-dec-2022 Fix choco uninstall sudo not deleting sudo.exe shim (gerardog) 28 | ' // ***** End Header ***** 29 | ' //*************************************************************************** 30 | 31 | Set objShell = CreateObject("Shell.Application") 32 | Set objWshShell = WScript.CreateObject("WScript.Shell") 33 | Set objWshProcessEnv = objWshShell.Environment("PROCESS") 34 | 35 | ' Get execution context information from sudo.cmd passed in through environment variables. 36 | strCommandLine = objWshProcessEnv("SUDO_CMDLINE") 37 | strApplicationArgument1 = objWshProcessEnv("SUDO_ARG1") 38 | strApplicationArgument2 = objWshProcessEnv("SUDO_ARG2") 39 | strCurrentDirectory = objWshProcessEnv("SUDO_CD") 40 | strCurrentDrive = objWshProcessEnv("SUDO_DRIVE") 41 | 42 | If (WScript.Arguments.Count >= 1) Then 43 | strFlag = WScript.Arguments(0) 44 | If (strFlag = "") OR (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _ 45 | OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "-?") OR (strFlag="h") _ 46 | OR (strFlag = "?") Then 47 | DisplayUsage 48 | WScript.Quit 49 | ElseIf (strFlag="-V") OR (strFlag="--version") Then 50 | DisplayVersion 51 | WScript.Quit 52 | Else 53 | 54 | boolKeepCurrentDirectoryContext = ((strApplicationArgument1 = ".") OR (strApplicationArgument1 = "_")) 55 | boolHideCurrentDirectoryContextCommandWindow = (strApplicationArgument1 = "_") 56 | 57 | If (boolKeepCurrentDirectoryContext = True) Then 58 | 59 | If (Len(strApplicationArgument2) > 0) Then 60 | strApplication = strApplicationArgument2 61 | strArguments = Right(strCommandLine, (Len(strCommandLine) - (Len(strApplicationArgument1) + Len(strApplicationArgument2) + 1))) 62 | Else 63 | strApplication = "cmd" 64 | strArguments = "" 65 | End If 66 | 67 | 'Shell.ShellExecute method https://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx 68 | 69 | If (boolHideCurrentDirectoryContextCommandWindow) Then 70 | vShow = 0 'Open the application with a hidden window 71 | 'vShow = 2 'Open the application with a minimized window 72 | 'vShow = 7 'Open the application with a minimized window. The active window remains active. 73 | Else 74 | 'vShow = 1 'Open the application with a normal window. If the window is minimized or maximized, the system restores it to its original size and position. 75 | vShow = 10 'Open the application with its window in the default state specified by the application. 76 | End If 77 | 78 | 'WScript.Echo "objShell.ShellExecute ""cmd"",""/C """ & strCurrentDrive & " && cd " & strCurrentDirectory & " && " & strApplication & " " & strArguments & """, """ & strCurrentDirectory & """, ""runas"", " & vShow 79 | objShell.ShellExecute "cmd","/C """ & strCurrentDrive & " && cd " & strCurrentDirectory & " && " & strApplication & " " & strArguments & """", strCurrentDirectory, "runas", vShow 80 | 81 | Else 82 | strApplication = strApplicationArgument1 83 | strArguments = Right(strCommandLine, (Len(strCommandLine) - Len(strApplication))) 84 | 85 | 'WScript.Echo "objShell.ShellExecute """ & strApplication & """, """ & strArguments & """, """ & strCurrentDirectory & """, ""runas"" " 86 | objShell.ShellExecute strApplication, strArguments, strCurrentDirectory, "runas" 87 | 88 | 'Note that strCurrentDirectory is not respected when runas is used, why the piped commands on a command shell is in use above 89 | 90 | End if 91 | 92 | End If 93 | Else 94 | DisplayUsage 95 | WScript.Quit 96 | End If 97 | 98 | Sub DisplayVersion 99 | 100 | WScript.Echo "Sudo version 1.1.3" & vbCrLf & _ 101 | "https://chocolatey.org/packages/Sudo" & vbCrLf & _ 102 | "https://github.com/janhebnes/chocolatey-packages/tree/master/Sudo" & vbCrLf 103 | 104 | End Sub 105 | 106 | Sub DisplayUsage 107 | 108 | WScript.Echo "Start application that prompt for elevation (Run as Administrator)." & vbCrLf & _ 109 | "" & vbCrLf & _ 110 | "SUDO command" & vbCrLf & _ 111 | "" & vbCrLf & _ 112 | " elevate command" & vbCrLf & _ 113 | "" & vbCrLf & _ 114 | "SUDO . command" & vbCrLf & _ 115 | "" & vbCrLf & _ 116 | " elevate and preserve current directory" & vbCrLf & _ 117 | "" & vbCrLf & _ 118 | "SUDO _ command" & vbCrLf & _ 119 | "" & vbCrLf & _ 120 | " elevate and preserve current directory but hide context window used to set context" & vbCrLf & _ 121 | "" & vbCrLf & _ 122 | "SUDO notepad %cd%\hosts" & vbCrLf & _ 123 | "" & vbCrLf & _ 124 | " Note also the option of getting the current directory using %CD%\ where you would have used .\" & vbCrLf & _ 125 | "" & vbCrLf & _ 126 | "SUDO -V " & vbCrLf & _ 127 | "SUDO --version" & vbCrLf & _ 128 | "" & vbCrLf & _ 129 | " Prints the sudo version as well as the chocolatey package source" & vbCrLf & _ 130 | "" & vbCrLf & _ 131 | "Examples:" & vbCrLf & _ 132 | "" & vbCrLf & _ 133 | " sudo cmd /k cd ""C:\Program Files""" & vbCrLf & _ 134 | " or sudo . cmd" & vbCrLf & _ 135 | " or sudo . " & vbCrLf & _ 136 | "" & vbCrLf & _ 137 | " sudo powershell -NoExit -Command Set-Location 'C:\Windows'" & vbCrLf & _ 138 | " or sudo . powershell" & vbCrLf & _ 139 | "" & vbCrLf & _ 140 | " sudo notepad ""c:\Windows\System32\drivers\etc\hosts""" & vbCrLf & _ 141 | " or sudo _ notepad hosts" & vbCrLf & _ 142 | " or sudo notepad %cd%\hosts" & vbCrLf & _ 143 | "" & vbCrLf & _ 144 | "" & vbCrLf & _ 145 | "Note that keeping current directory requires an elevated cmd shell " & vbCrLf & _ 146 | "that sets directory context before executing your command. " & vbCrLf & _ 147 | "" & vbCrLf & _ 148 | "You can also keep context by working with %CD%\ on file locations." & vbCrLf & _ 149 | "" & vbCrLf & _ 150 | "Usage with scripts: When using the sudo command with scripts such as" & vbCrLf & _ 151 | "Windows Script Host or Windows PowerShell scripts, you should specify" & vbCrLf & _ 152 | "the script host executable (i.e., wscript, cscript, powershell) as the " & vbCrLf & _ 153 | "application." & vbCrLf & _ 154 | "" & vbCrLf & _ 155 | "Sample usage with scripts:" & vbCrLf & _ 156 | "" & vbCrLf & _ 157 | " sudo cscript ""C:\windows\system32\slmgr.vbs"" " & vbCrLf & _ 158 | " sudo powershell -NoExit -Command & 'C:\Temp\Test.ps1'" & vbCrLf & _ 159 | "" & vbCrLf & _ 160 | "" & vbCrLf & _ 161 | "The sudo command consists of sudo.cmd and sudo.vbs" & vbCrLf 162 | 163 | End Sub 164 | --------------------------------------------------------------------------------