Nice programing

Windows에서 'sudo'명령을 실행하는 방법

nicepro 2020. 10. 24. 11:43
반응형

Windows에서 'sudo'명령을 실행하는 방법


Windows에서 다음 명령을 어떻게 실행합니까?

$ sudo django-admin.py startproject NEW

?


sudoWindows 에는 명령 이 없습니다 . 가장 가까운 것은 "관리자 권한으로 실행"입니다.

runas관리자 신뢰 수준 명령을 사용 하거나 UI에서 프로그램을 마우스 오른쪽 단추로 클릭하고 "관리자 권한으로 실행"을 선택 하여이 작업을 수행 할 수 있습니다 .


메모장을 열고 다음 코드를 붙여 넣습니다.

@echo off
powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c %*'"
@echo on

그런 다음 파일을 sudo.cmd. 이 파일을 복사 하여 PATH 환경 변수에 붙여 넣거나 C:\Windows\System32경로를 추가하십시오 sudo.cmd.

명령 프롬프트를 열면 이제 sudo start ..

명령을 실행할 때 관리자 명령 프롬프트 창을 열어 두려면 메모장의 코드를 다음과 같이 변경하십시오.

@echo off
powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/k %*'"
@echo on

설명:

powershell -Command powershell 명령을 실행합니다.

Start-Process 프로세스 (이 경우 명령 프롬프트)를 시작하는 powershell 명령입니다.

-Verb RunAs 관리자로 명령을 실행합니다.

-Argument-List 인수를 사용하여 명령을 실행합니다.

우리의 주장은 '/c %*'. %*당신이 한 경우 그래서, 모든 인수를 의미 sudo foo bar, 그것은 명령 프롬프트에서 실행됩니다 foo bar매개 변수가 foo는, 바, 그리고 있기 때문에 %*반환 foo bar.

/c명령이 완료된 후 창을 닫는 cmd를 매개 변수이며,이 /k창을 열어 유지하는 cmd를 매개 변수입니다.


* nix에 관계없이 실행하지 않기 때문에 일반적으로 그렇지 않습니다. 사용자 디렉터리에서 개발하고 나중에 시스템 디렉터리에 배포합니다.


runas명령을 사용하려면 사용자가 암호를 입력해야합니다. 암호를 입력하지 않고 UAC 대화 상자 만 클릭하려면 명령 Start-Process -Verb runas대신 PowerShell 에서 사용하십시오 runas.

참조 : http://satob.hatenablog.com/entry/2017/06/17/013217


당신은에서 runas 명령을 사용할 수 있습니다 - http://technet.microsoft.com/en-us/library/bb490994.aspx 또는 sudowin - http://sourceforge.net/projects/sudowin/


Windows에서는 runas 명령을 사용할 수 있습니다. Linux 사용자의 경우 Windows에 sudo에 대한 몇 가지 대안이 있습니다.

http://helpdeskgeek.com/free-tools-review/5-windows-alternatives-linux-sudo-command/


다음 vbs 스크립트는 나를 위해 트릭을 수행합니다. 나는 그것을 입었다C:\Windows\System32

Set objArgs = WScript.Arguments
exe = objArgs(0)
args = ""
IF objArgs.Count >= 2 Then
   args = args & objArgs(1)
End If
For it = 2 to objArgs.Count - 1
   args = args & " " & objArgs(it)
Next
Set objShell = CreateObject( "WScript.Shell")
windir=objShell.ExpandEnvironmentStrings("%WINDIR%")
Set objShellApp = CreateObject("Shell.Application")
objShellApp.ShellExecute exe, args, "", "runas", 1
set objShellApp = nothing

명령 프롬프트에서의 사용 예 sudo net start service


종류가 있습니다. 2007 년에 Windows 용 Sudo를 만들었습니까? 08? 여기에 내가 작성한 보안 문서가 있습니다-https: //www.sans.org/reading-room/whitepapers/bestprac/sudo-windows-sudowin-1726 . 확신 http://sudowin.sf.net는 여전히 너무 작동합니다.


저는 현재 디렉토리의 컨텍스트에서 상승 된 권한으로 프로그램이나 명령을 실행하기위한 Windows 용 wsudo오픈 소스 sudo와 유사한 CLI 도구 인을 만들었습니다 . Chocolatey 패키지 로 제공됩니다 .

나는 빌드 에이전트, 관리자 같은 것들을 구성과 같은 물건이 많이 사용 sfc /scannow, dism /online /cleanup-image /restorehealth또는 간단하게 설치 / 내 로컬 Chocolatey 패키지를 업데이트합니다. 자신의 책임하에 사용하십시오.

설치

choco install wsudo

Chocolatey 가 이미 설치되어 있어야합니다.

목적

wsudo is a Linux sudo-like tool for Windows to invoke a program with elevated rights (as Administrator) from a non-admin shell command prompt and keeping its current directory.

This implementation doesn't depend on the legacy Windows Script Host (CScript). Instead, it uses a helper PowerShell 5.1 script that invokes "Start-Process -Wait -Verb runAs ..." cmdlet. Your system most likely already has PowerShell 5.x installed, otherwise you'll be offered to install it as a dependency.

Usage

wsudo runs a program or an inline command with elevated rights in the current directory. Examples:

wsudo .\myAdminScript.bat 
wsudox "del C:\Windows\Temp\*.* && pause"
wasudo cup all -y
wasudox start notepad C:\Windows\System32\drivers\etc\hosts 

For more details, visit the GitHub repro.


I think I tried steps below after doing some research & succeeded

1.Install scoop using powershell 3 (iex (new-object net.webclient).downloadstring('https://get.scoop.sh')) 2. do scoop install --global sudo 3. make sure paths (C:\Users\\scoop\shims & C:\ProgramData\scoop\shims) added in environmental path variable.


There is no sudo command in case of windows and also there is no need to put any $. For installing Angular CLI through node.js command prompt in windows, I just wrote npm install -g @angular/cli and then pressed Enter. It worked fine.


open the console as a administrator. Right Click on the command prompt or bash -> more and select "run as administrator"

참고URL : https://stackoverflow.com/questions/9652720/how-to-run-sudo-command-in-windows

반응형