2) また「1)」のケースで、ローカルのファイルパスがurlencodeされている場合も考慮して、urldecodeしてから「関連付いたアプリケーションを起動する」というアクションに渡したいのですが、その方法も教えて下さい。 たとえば C%3A\hoge\%E3%82%A8%E3%82%B0%E3%82%B6%E3%83%B3%E3%83%97%E3%83%AB.pdf などとなっているケースです
こちらでいかがでしょうか?
Option Explicit Dim fileProtocol Dim url url = "C%3A\hoge\%E3%82%A8%E3%82%B0%E3%82%B6%E3%83%B3%E3%83%97%E3%83%AB.pdf" url = decodeUTF8(url) Dim WshShell Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run """" & url & """" Function decodeUTF8(ByVal buf) Dim code Dim code1 Dim code2 Dim code3 Dim k Dim sjis buf=UnEscape(buf) For k=1 To Len(buf) code=AscW(Mid(buf,k,1)) If fileProtocol Then If code=43 Then code=32 If 0<=code And code<128 Then sjis=sjis & ChrW(code) ElseIf 128+64<=code And code<128+64+32 Then code1=code k=k+1 code2=AscW(Mid(buf,k,1)) code=(code1 And &H1F) * 64 + (code2 And &H3F) If Chr(Asc(ChrW(code)))=ChrW(code) Then sjis=sjis & ChrW(code) Else sjis=sjis & Escape(ChrW(code)) error="Invalid UTF-8 Code : " & Escape(ChrW(code)) & " " & Right(Hex(code1+256),2) & Right(Hex(code2+256),2) End If ElseIf 128+64+32<=code And code<128+64+32+16 Then code1=code k=k+1 code2=AscW(Mid(buf,k,1)) k=k+1 code3=AscW(Mid(buf,k,1)) code=(code1 And &H0F) * 16 * 256 + (code2 And &H3F) * 64 + (code3 And &H3F) If Chr(Asc(ChrW(code)))=ChrW(code) Then sjis=sjis & ChrW(code) Else sjis=sjis & Escape(ChrW(code)) error="Invalid UTF-8 Code : " & Escape(ChrW(code)) & " " & Right(Hex(code1+256),2) & Right(Hex(code2+256),2) & Right(Hex(code3+256),2) End If Else sjis=sjis & Escape(ChrW(code)) error="Invalid UTF-8 Code : " & Escape(ChrW(code)) & " " & Right(Hex(code+256),2) End If Next decodeUTF8=sjis End Function
'参考:decodeURL.HTA 吉岡 照雄氏
コメント(0件)