2013-01-24 4 views
2

이 문제를 해결하는 데 어려움이 있습니다. 나는 사용자 이름과 암호를 묻는 vbscript가있다. 그런 다음 스크립트는 PSExec.exe를 실행하여 명령 줄에 이러한 스크립트를 전달합니다.VBScript를 사용하여 명령 줄에 캐럿 전달

strUser = Inputbox("Username:","Username") 
    strPassword = Inputbox("Password:","Password") 
    Set objShell = WScript.CreateObject("WScript.Shell") 
    objShell.Run "%comspec% /K psexec.exe \\workstation -u " & struser _ 
     & " -p " & strPassword & " -d calc.exe", 1, false 

암호에 암호가없는 경우 제대로 작동합니다. 그것은 하나가 않는 경우에, 예를 들어, 암호는 "* &^% $ # 1 @ 패스) (!"경우 내가 psexec에에서 다음과 같은 오류가 발생합니다.

'%$#@!' is not recognized as an internal or external command, 
operable program or batch file. 

캐럿은 명령 라인으로 읽고있는 공간으로는이 명령을 실행하려고 생각 때문에.

psexec.exe \\workstation64 -u User -p Pass)(*& %$#@! -d Calc.exe 

대신 이렇게 psexec에 참조의 %의 $의 # @! 명령한다.

나 '캐럿의 공간이 당신이 볼 수 있듯이 배치 파일을 사용할 때 전달 예제를 보았지만이 경우에는 작동하지 않습니다. xtra^like this ^^는 박쥐 파일에서 작동합니다.

어떻게 명령 줄에 캐럿을 전달할 수 있습니까?

UPDATE ......

나는 직장에서 오늘 약 45 분 동안이 근무하고 일을 가져올 수 없습니다. 내가 시도한 첫 번째 일은 암호에 따옴표를 추가하는 것이었지만 여전히 작동하지 않았습니다. 난 그냥 집에서 그것을 테스트하고 괜찮 았는데 ....... 직장에서의 운영 체제는 Windows XP이고 집에서 나는 Windows 7을 돌린다. 나는 실수로 무언가를 잘못 입력하지 않도록 아침에 다시 시도 할 것이다. 여기에 나는 그것이 윈도우 7

strUser = Inputbox("Username:","Username") 
    strPassword = Inputbox("Password:","Password") 

    strPassword = chr(34) & strPassword & chr(34) 

    Set objShell = WScript.CreateObject("WScript.Shell") 
    objShell.Run "%comspec% /K psexec.exe \\workstation -u " & struser _ 
     & " -p " & strPassword & " -d calc.exe", 1, false 
+1

이 주석 끝의 SO 대답 링크에서 4 회의 캐리지가 필요합니다. http://stackoverflow.com/a/5254713/1569434 – Lizz

답변

0
문제는 앰퍼샌드의 사용 낳는다

에 집에서 작동하도록 한 것입니다하지 캐럿 : 단일 앰퍼샌드 명령 구분 기호로 사용되므로되어 & 다음 줄의 나머지 - cmd 해석기에 의해 다음 명령으로 간주되는 기호.

다음 예에서는 PSExec을 실험하지 않으므로 PSExec 대신 SET 명령을 사용했습니다.

모든 문자를 이스케이프 처리해도 SET 명령으로 모두 잘됩니다. :) 그러나 백분율 기호에 대해서는 확실하지 않습니다. "백분율 기호"는 "글자 그대로 사용해야합니다."라고 말합니다.

Dim strPssw: strPssw = "/Pass"")=(*&^%$#@!" 
Dim ii, strChar, strEscape 
Dim strPassword: strPassword = "" 
For ii = 1 To Len(strPssw) 'cannot use Replace() function 
    strChar = Mid(strPssw, ii, 1) 
    Select Case strChar 
    Case "&", """", "^", "%", "=", _ 
     "@", "(", ")", "!", "*", "?", _ 
     ".", "\", "|", ">", "<", "/" 
    strEscape = "^" 
    Case Else 
    strEscape = "" 'all goes well even if strEscape = "^" here 
    End Select 
    strPassword = strPassword & strEscape & strChar 
Next 
Dim objShell: Set objShell = WScript.CreateObject("WScript.Shell") 
objShell.Run "%comspec% /C set varia=" & strPassword & "&set varia&pause&set varia=", 1, false 

' @ - At Symbol: be less verbose 
' & - Single Ampersand: used as a command separator 
'^- Caret: general escape character in batch 
' " - Double Quote: surrounding a string in double quotes escapes all of the characters contained within it 
'() - Parentheses: used to make "code blocks" of grouped commands 
' % - Percentage Sign: are used to mark some variables, must be doubled to use literally 
' ! - Exclamation Mark: to mark delayed expansion environment variables !variable! 
' * - Asterisk: wildcard matches any number or any characters 
' ? - Question Mark: matches any single character 
' . - Single dot: represents the current directory 
' \ - Backslash: represent the root directory of a drive dir ^\ 
' | - Single Pipe: redirects the std.output of one command into the std.input of another 
' > - Single Greater Than: redirects output to either a file or file like device 
' < - Less Than: redirect the contents of a file to the std.input of a command 
'' 
' && - Double Ampersand: conditional command separator (if errorlevel 0) 
' .. - Double dot: represents the parent directory of the current directory 
' || - Double Pipe: conditional command separator (if errorlevel > 0) 
' :: - Double Colon: alternative to "rem" for comments outside of code blocks 
' >> - Double Greater than: output will be added to the very end of the file 
' thanks to http://judago.webs.com/batchoperators.htm 
'