답변:
Windows에는 Unix-y 시스템에서 sudo와 약간 비슷한 "runas"명령이 있습니다. "runas /?"를 입력 해보십시오. 명령 프롬프트에서.
나는 elevate라는 .cmd & .vbs 스크립트 듀오를 사용했는데, 그것은 내 요구에 잘 작동합니다. 입력 만하면됩니다
[명령]을 높이십시오시작> 실행 또는 명령 행에서 관리자 권한으로 명령을 실행합니다. 그것이 도움이되기를 바랍니다!
다음은 elevate.cmd입니다.
:: //***************************************************************************
:: // ***** Script Header *****
:: //
:: // File: Elevate.cmd
:: //
:: // Additional files required: Elevate.vbs
:: //
:: // Purpose: To provide a command line method of launching applications that
:: // prompt for elevation (Run as Administrator) on Windows Vista.
:: //
:: // Usage: elevate.cmd application <application arguments>
:: //
:: // Version: 1.0.0
:: // Date : 01/02/2007
:: //
:: // History:
:: // 1.0.0 01/02/2007 Created initial version.
:: //
:: // ***** End Header *****
:: //***************************************************************************
@echo off
:: Pass raw command line agruments and first argument to Elevate.vbs
:: through environment variables.
set ELEVATE_CMDLINE=%*
set ELEVATE_APP=%1
start wscript //nologo "%~dpn0.vbs" %*
및 elevate.vbs :
' //***************************************************************************
' // ***** Script Header *****
' //
' // File: Elevate.vbs
' //
' // Additional files required: Elevate.cmd
' //
' // Purpose: To provide a command line method of launching applications that
' // prompt for elevation (Run as Administrator) on Windows Vista.
' //
' // Usage: (Not used directly. Launched from Elevate.cmd.)
' //
' // Version: 1.0.1
' // Date : 01/03/2007
' //
' // History:
' // 1.0.0 01/02/2007 Created initial version.
' // 1.0.1 01/03/2007 Added detailed usage output.
' //
' // ***** End Header *****
' //***************************************************************************
Set objShell = CreateObject("Shell.Application")
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWshProcessEnv = objWshShell.Environment("PROCESS")
' Get raw command line agruments and first argument from Elevate.cmd passed
' in through environment variables.
strCommandLine = objWshProcessEnv("ELEVATE_CMDLINE")
strApplication = objWshProcessEnv("ELEVATE_APP")
strArguments = Right(strCommandLine, (Len(strCommandLine) - Len(strApplication)))
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
Else
objShell.ShellExecute strApplication, strArguments, "", "runas"
End If
Else
DisplayUsage
WScript.Quit
End If
Sub DisplayUsage
WScript.Echo "Elevate - Elevation Command Line Tool for Windows Vista" & vbCrLf & _
"" & vbCrLf & _
"Purpose:" & vbCrLf & _
"--------" & vbCrLf & _
"To launch applications that prompt for elevation (i.e. Run as Administrator)" & vbCrLf & _
"from the command line, a script, or the Run box." & vbCrLf & _
"" & vbCrLf & _
"Usage: " & vbCrLf & _
"" & vbCrLf & _
" elevate application <arguments>" & vbCrLf & _
"" & vbCrLf & _
"" & vbCrLf & _
"Sample usage:" & vbCrLf & _
"" & vbCrLf & _
" elevate notepad ""C:\Windows\win.ini""" & vbCrLf & _
"" & vbCrLf & _
" elevate cmd /k cd ""C:\Program Files""" & vbCrLf & _
"" & vbCrLf & _
" elevate powershell -NoExit -Command Set-Location 'C:\Windows'" & vbCrLf & _
"" & vbCrLf & _
"" & vbCrLf & _
"Usage with scripts: When using the elevate 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 & _
" elevate wscript ""C:\windows\system32\slmgr.vbs"" –dli" & vbCrLf & _
"" & vbCrLf & _
" elevate powershell -NoExit -Command & 'C:\Temp\Test.ps1'" & vbCrLf & _
"" & vbCrLf & _
"" & vbCrLf & _
"The elevate command consists of the following files:" & vbCrLf & _
"" & vbCrLf & _
" elevate.cmd" & vbCrLf & _
" elevate.vbs" & vbCrLf
End Sub
RunAs.exe 명령을 사용해야합니다.
다음은 몇 가지 지침입니다. http://www.softtreetech.com/24x7/archive/53.htm
누군가가 VBS에 해당하는 것을 게시 했으므로 다음은 PowerShell에 대한 Invoke-Admin 기능입니다.
function Invoke-Admin() {
param ( [string]$program = $(throw "Please specify a program" ),
[string]$argumentString = "",
[switch]$waitForExit )
$psi = new-object "Diagnostics.ProcessStartInfo"
$psi.FileName = $program
$psi.Arguments = $argumentString
$psi.Verb = "runas"
$proc = [Diagnostics.Process]::Start($psi)
if ( $waitForExit ) {
$proc.WaitForExit();
}
}
VBScript도 사용할 수 있습니다. .vbs
예를 들어 파일을 작성하십시오 ambika.vbs
.
Set objShell = CreateObject(“Shell.Application”)
Set objWshShell = WScript.CreateObject(“WScript.Shell”)
Set objWshProcessEnv = objWshShell.Environment(“PROCESS”)
objShell.ShellExecute “C:\Windows\system32\cmd.exe”, “/k”, “”, “runas”