2

これを理解するのに苦労しています。ユーザー名とパスワードを要求する vbscript があります。次に、スクリプトは PSExec.exe を実行し、これらを次のようにコマンド ラインに渡します。

    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

パスワードにキャレットが含まれていない場合、これは正常に機能します。しかし、パスワードが「Pass)(*&^%$#@!」の場合など、パスワードがある場合は、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 は %$#@! を参照します。コマンドとして。

バッチ ファイルを使用するときにそれを渡す例を見てきましたが、この場合は機能しません。エクストラ ^ を追加すると、このように ^^ バットファイルで機能します。

コマンドラインにキャレットを渡すにはどうすればよいですか????

アップデート......

今日、職場で約 45 分間これに取り組みましたが、うまくいきませんでした。最初に試したのは、パスワードに引用符を追加することでしたが、それでも機能しませんでした。ここの家でテストしたところ、問題なく動作しました.......職場のOSはWindows XPで、家ではWindows 7を実行しています。Windows 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
4

1 に答える 1

0

問題は、キャレットではなくアンパサンドの使用にあります。単一のアンパサンドがコマンド区切りとして使用されるため、&-sign の後の行の残りは、cmd インタープリターによって次のコマンドと見なされます。

次の例では、PSExec の実験を行わないため、PSExec の代わりに SET コマンドを使用しました。

すべての文字をエスケープしたとしても、SETコマンドですべてうまくいきます:)が、「文字通り使用するには2倍にする必要がある」と言われているパーセント記号についてはわかりません。

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
'
于 2014-05-01T20:34:43.997 に答える