Unpacking Software Livestream

Join our monthly Unpacking Software livestream to hear about the latest news, chat and opinion on packaging, software deployment and lifecycle management!

Learn More

Chocolatey Product Spotlight

Join the Chocolatey Team on our regular monthly stream where we put a spotlight on the most recent Chocolatey product releases. You'll have a chance to have your questions answered in a live Ask Me Anything format.

Learn More

Chocolatey Coding Livestream

Join us for the Chocolatey Coding Livestream, where members of our team dive into the heart of open source development by coding live on various Chocolatey projects. Tune in to witness real-time coding, ask questions, and gain insights into the world of package management. Don't miss this opportunity to engage with our team and contribute to the future of Chocolatey!

Learn More

Calling All Chocolatiers! Whipping Up Windows Automation with Chocolatey Central Management

Webinar from
Wednesday, 17 January 2024

We are delighted to announce the release of Chocolatey Central Management v0.12.0, featuring seamless Deployment Plan creation, time-saving duplications, insightful Group Details, an upgraded Dashboard, bug fixes, user interface polishing, and refined documentation. As an added bonus we'll have members of our Solutions Engineering team on-hand to dive into some interesting ways you can leverage the new features available!

Watch On-Demand
Chocolatey Community Coffee Break

Join the Chocolatey Team as we discuss all things Community, what we do, how you can get involved and answer your Chocolatey questions.

Watch The Replays
Chocolatey and Intune Overview

Webinar Replay from
Wednesday, 30 March 2022

At Chocolatey Software we strive for simple, and teaching others. Let us teach you just how simple it could be to keep your 3rd party applications updated across your devices, all with Intune!

Watch On-Demand
Chocolatey For Business. In Azure. In One Click.

Livestream from
Thursday, 9 June 2022

Join James and Josh to show you how you can get the Chocolatey For Business recommended infrastructure and workflow, created, in Azure, in around 20 minutes.

Watch On-Demand
The Future of Chocolatey CLI

Livestream from
Thursday, 04 August 2022

Join Paul and Gary to hear more about the plans for the Chocolatey CLI in the not so distant future. We'll talk about some cool new features, long term asks from Customers and Community and how you can get involved!

Watch On-Demand
Hacktoberfest Tuesdays 2022

Livestreams from
October 2022

For Hacktoberfest, Chocolatey ran a livestream every Tuesday! Re-watch Cory, James, Gary, and Rain as they share knowledge on how to contribute to open-source projects such as Chocolatey CLI.

Watch On-Demand

Downloads:

140,000

Downloads of v 1.1.3:

37,231

Last Update:

21 Dec 2022

Package Maintainer(s):

Software Author(s):

  • Jan Hebnes

Tags:

sudo console cmd command elevate administrator

Sudo

  • 1
  • 2
  • 3

1.1.3 | Updated: 21 Dec 2022

Downloads:

140,000

Downloads of v 1.1.3:

37,231

Maintainer(s):

Software Author(s):

  • Jan Hebnes

Sudo 1.1.3

Legal Disclaimer: Neither this package nor Chocolatey Software, Inc. are affiliated with or endorsed by Jan Hebnes. The inclusion of Jan Hebnes trademark(s), if any, upon this webpage is solely to identify Jan Hebnes goods or services and not for commercial purposes.

  • 1
  • 2
  • 3

All Checks are Passing

3 Passing Tests


Validation Testing Passed


Verification Testing Passed

Details

Scan Testing Successful:

No detections found in any package files

Details
Learn More

Deployment Method: Individual Install, Upgrade, & Uninstall

To install Sudo, run the following command from the command line or from PowerShell:

>

To upgrade Sudo, run the following command from the command line or from PowerShell:

>

To uninstall Sudo, run the following command from the command line or from PowerShell:

>

Deployment Method:

NOTE

This applies to both open source and commercial editions of Chocolatey.

1. Enter Your Internal Repository Url

(this should look similar to https://community.chocolatey.org/api/v2/)


2. Setup Your Environment

1. Ensure you are set for organizational deployment

Please see the organizational deployment guide

2. Get the package into your environment

  • Open Source or Commercial:
    • Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://community.chocolatey.org/api/v2/. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
    • You can also just download the package and push it to a repository Download

3. Copy Your Script

choco upgrade sudo -y --source="'INTERNAL REPO URL'" [other options]

See options you can pass to upgrade.

See best practices for scripting.

Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.

If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:


choco upgrade sudo -y --source="'INTERNAL REPO URL'" 
$exitCode = $LASTEXITCODE

Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
  Exit 0
}

Exit $exitCode

- name: Install sudo
  win_chocolatey:
    name: sudo
    version: '1.1.3'
    source: INTERNAL REPO URL
    state: present

See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.


chocolatey_package 'sudo' do
  action    :install
  source   'INTERNAL REPO URL'
  version  '1.1.3'
end

See docs at https://docs.chef.io/resource_chocolatey_package.html.


cChocoPackageInstaller sudo
{
    Name     = "sudo"
    Version  = "1.1.3"
    Source   = "INTERNAL REPO URL"
}

Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.


package { 'sudo':
  ensure   => '1.1.3',
  provider => 'chocolatey',
  source   => 'INTERNAL REPO URL',
}

Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.


4. If applicable - Chocolatey configuration/installation

See infrastructure management matrix for Chocolatey configuration elements and examples.

Package Approved

This package was approved as a trusted package on 24 Oct 2024.

Description

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"


bin\sudo.cmd
@echo off

:: Pass execution context information through environment variables.
set SUDO_CMDLINE=%*
set SUDO_ARG1=%1
set SUDO_ARG2=%2
set SUDO_CD="%CD%"
set SUDO_DRIVE=%CD:~0,2%

:: %~dpn0 is refering to this files name and %* sends along the full commandline  
cscript //nologo "%~dpn0.vbs" %*
bin\sudo.vbs
' //***************************************************************************
' // ***** Script Header *****
' //
' // File:      Sudo.vbs
' // Additional files required:  Sudo.cmd
' //
' // Purpose:   To provide a command line method of launching applications that
' //            prompt for elevation (Run as Administrator).
' //
' // Usage:     (Not used directly.  Launched from Sudo.cmd)
' //
' // Version:   1.1.3
' // Date :     21-dec-2022
' //
' // History:
' // 1.0.0   01-Feb-2007  Created initial version used internally.
' // 1.0.1   01-Mar-2007  Added detailed usage output.
' // 1.0.0	 23-Oct-2013  Released on chocolatey
' // 1.0.1   08-Sep-2014  chocolatey framework changes required new version
' // 1.0.2   12-Jun-2015  chocolatey framework changes required new version
' // 1.1.0   20-Apr-2018  Added the option of keeping current directory 
' //                      context by using the inserted . or _ as first command argument 
' //                      when used a context cmd shell window is opened for setting 
' //                      current directory context using _ hides this window 
' // 1.1.1   04-Feb-2019  Added the -V or -version option to query the version of sudo
' // 1.1.2   27-dec-2019  Retain current directory even with special chars (janusblack)
' // 1.1.3   21-dec-2022  Fix choco uninstall sudo not deleting sudo.exe shim (gerardog)
' // ***** End Header *****
' //***************************************************************************

Set objShell = CreateObject("Shell.Application")
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWshProcessEnv = objWshShell.Environment("PROCESS")

' Get execution context information from sudo.cmd passed in through environment variables.
strCommandLine = objWshProcessEnv("SUDO_CMDLINE")
strApplicationArgument1 = objWshProcessEnv("SUDO_ARG1")
strApplicationArgument2 = objWshProcessEnv("SUDO_ARG2")
strCurrentDirectory = objWshProcessEnv("SUDO_CD")
strCurrentDrive = objWshProcessEnv("SUDO_DRIVE")

If (WScript.Arguments.Count >= 1) Then
    strFlag = WScript.Arguments(0)
    If (strFlag = "") OR (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
        OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "-?") OR (strFlag="h") _
        OR (strFlag = "?") Then
        DisplayUsage
		WScript.Quit
    ElseIf (strFlag="-V") OR (strFlag="--version") Then
        DisplayVersion
		WScript.Quit
    Else

        boolKeepCurrentDirectoryContext = ((strApplicationArgument1 = ".") OR (strApplicationArgument1 = "_"))
        boolHideCurrentDirectoryContextCommandWindow = (strApplicationArgument1 = "_")

        If (boolKeepCurrentDirectoryContext = True) Then
            
            If (Len(strApplicationArgument2) > 0) Then  
                strApplication = strApplicationArgument2
                strArguments = Right(strCommandLine, (Len(strCommandLine) - (Len(strApplicationArgument1) + Len(strApplicationArgument2) + 1)))
            Else
                strApplication = "cmd"
                strArguments = ""
            End If

            'Shell.ShellExecute method https://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx

            If (boolHideCurrentDirectoryContextCommandWindow) Then            
                vShow = 0 'Open the application with a hidden window
                'vShow = 2 'Open the application with a minimized window
                'vShow = 7 'Open the application with a minimized window. The active window remains active.
            Else
                '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.
                vShow = 10 'Open the application with its window in the default state specified by the application.
            End If

            'WScript.Echo "objShell.ShellExecute ""cmd"",""/C """ & strCurrentDrive & " && cd " & strCurrentDirectory & " && " & strApplication & " " & strArguments & """, """ & strCurrentDirectory & """, ""runas"", " & vShow
            objShell.ShellExecute "cmd","/C """ & strCurrentDrive & " && cd " & strCurrentDirectory & " && " & strApplication & " " & strArguments & """", strCurrentDirectory, "runas", vShow

        Else
            strApplication = strApplicationArgument1
            strArguments = Right(strCommandLine, (Len(strCommandLine) - Len(strApplication)))
        
            'WScript.Echo "objShell.ShellExecute """ & strApplication & """, """ & strArguments & """, """ & strCurrentDirectory & """, ""runas"" "
            objShell.ShellExecute strApplication, strArguments, strCurrentDirectory, "runas"

            'Note that strCurrentDirectory is not respected when runas is used, why the piped commands on a command shell is in use above 

        End if
         
    End If
Else
    DisplayUsage
    WScript.Quit
End If

Sub DisplayVersion

    WScript.Echo "Sudo version 1.1.3" & vbCrLf & _
        "https://chocolatey.org/packages/Sudo" & vbCrLf & _
        "https://github.com/janhebnes/chocolatey-packages/tree/master/Sudo" & vbCrLf

End Sub

Sub DisplayUsage

    WScript.Echo "Start application that prompt for elevation (Run as Administrator)." & vbCrLf & _
                 "" & vbCrLf & _
                "SUDO command" & vbCrLf & _
				"" & vbCrLf & _
				"    elevate command" & vbCrLf & _
				"" & vbCrLf & _
				"SUDO . command" & vbCrLf & _
				"" & vbCrLf & _
				"    elevate and preserve current directory" & vbCrLf & _
				"" & vbCrLf & _
				"SUDO _ command" & vbCrLf & _
				"" & vbCrLf & _
				"    elevate and preserve current directory but hide context window used to set context" & vbCrLf & _
				"" & vbCrLf & _
				"SUDO notepad %cd%\hosts" & vbCrLf & _
				"" & vbCrLf & _
				"    Note also the option of getting the current directory using %CD%\ where you would have used .\" & vbCrLf & _
				 "" & vbCrLf & _
                 "SUDO -V " & vbCrLf & _
                 "SUDO --version" & vbCrLf & _
                 "" & vbCrLf & _
				"    Prints the sudo version as well as the chocolatey package source" & vbCrLf & _
                 "" & vbCrLf & _
                 "Examples:" & vbCrLf & _
                 "" & vbCrLf & _
                 "    sudo cmd /k cd ""C:\Program Files""" & vbCrLf & _
                 "    or       sudo . cmd" & vbCrLf & _
                 "    or       sudo . " & vbCrLf & _
                 "" & vbCrLf & _
                 "    sudo powershell -NoExit -Command Set-Location 'C:\Windows'" & vbCrLf & _
                 "    or       sudo . powershell" & vbCrLf & _
                 "" & vbCrLf & _
                 "    sudo notepad ""c:\Windows\System32\drivers\etc\hosts""" & vbCrLf & _
                 "    or       sudo _ notepad hosts" & vbCrLf & _
                 "    or       sudo notepad %cd%\hosts" & vbCrLf & _
                 "" & vbCrLf & _
                 "" & vbCrLf & _
                 "Note that keeping current directory requires an elevated cmd shell " & vbCrLf & _
                 "that sets directory context before executing your command. " & vbCrLf & _ 
                 "" & vbCrLf & _
                 "You can also keep context by working with %CD%\ on file locations." & vbCrLf & _
                 "" & vbCrLf & _
                 "Usage with scripts: When using the sudo command with scripts such as" & vbCrLf & _
                 "Windows Script Host or Windows PowerShell scripts, you should specify" & vbCrLf & _
                 "the script host executable (i.e., wscript, cscript, powershell) as the " & vbCrLf & _
                 "application." & vbCrLf & _
                 "" & vbCrLf & _
                 "Sample usage with scripts:" & vbCrLf & _
                 "" & vbCrLf & _
                 "    sudo cscript ""C:\windows\system32\slmgr.vbs"" " & vbCrLf & _
                 "    sudo powershell -NoExit -Command & 'C:\Temp\Test.ps1'" & vbCrLf & _
                 "" & vbCrLf & _
                 "" & vbCrLf & _
                 "The sudo command consists of sudo.cmd and sudo.vbs" & vbCrLf

End Sub
tools\chocolateyInstall.ps1
Remove-BinFile 'Sudo' '..\lib\Sudo.1.0\bin\sudo.cmd'
Remove-BinFile 'Sudo' '..\lib\Sudo.1.0\bin\sudo.vbs'
Remove-BinFile 'Sudo' '..\lib\Sudo.1.0.1\bin\sudo.cmd'
Remove-BinFile 'Sudo' '..\lib\Sudo.1.0.1\bin\sudo.vbs'
Remove-BinFile 'Sudo' '..\lib\Sudo.1.1.0\bin\sudo.cmd'
Remove-BinFile 'Sudo' '..\lib\Sudo.1.1.0\bin\sudo.vbs'
Generate-BinFile 'Sudo' '..\lib\Sudo\bin\sudo.cmd'
tools\chocolateyUninstall.ps1
Remove-BinFile 'Sudo' 'sudo.exe'

Log in or click on link to see number of positives.

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Add to Builder Version Downloads Last Updated Status
Sudo 1.1.2 63853 Friday, December 27, 2019 Approved
Sudo 1.1.1 12456 Monday, February 4, 2019 Approved
Sudo 1.1.0 7704 Friday, April 20, 2018 Approved
Sudo 1.0.2 12659 Friday, June 12, 2015 Approved
Sudo 1.0.1 4244 Monday, September 8, 2014 Approved
Sudo 1.0 1853 Wednesday, October 23, 2013 Approved

(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


This package has no dependencies.

Discussion for the Sudo Package

Ground Rules:

  • This discussion is only about Sudo and the Sudo package. If you have feedback for Chocolatey, please contact the Google Group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or Sudo, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.
comments powered by Disqus