[Mac] 在 Mac 上使用 Wine 執行 VBScript

[Mac] 在 Mac 上使用 Wine 執行 VBScript

上一篇寫了 在 Mac 上使用 Wine 執行 Windows 程式

今天正好就遇到另一個需求:要如何用 Wine 執行 VBScript 呢?

 

舉例來說,我想將 VBScript 的 .vbs 程式編碼成 .vbe 檔案,

TechNet 這邊提供了一個 Encode.vbs 給我們作編碼的工作

要執行的話,很直覺地執行 wine cscript Encode.vbs test.vbs,結果就出錯了:

testuser@localhost ~ $ wine cscript JS_Encode.vbs test.vbs
fixme:cscript:wWinMain (0x40560000 0x0 L"JS_Encode.vbs test.vbs" 1) forwarding to wscript
fixme:vbscript:VBScript_SetScriptState unimplemented SCRIPTSTATE_INITIALIZED
fixme:scrrun:DllGetClassObject {32da2b15-cfed-11d1-b747-00c04fc2b085} {00000001-0000-0000-c000-000000000046} 0x33f970
err:ole:apartment_getclassobject DllGetClassObject returned error 0x80040111
err:ole:create_server class {32da2b15-cfed-11d1-b747-00c04fc2b085} not registered
err:ole:CoGetClassObject no class object {32da2b15-cfed-11d1-b747-00c04fc2b085} could be created for context 0x5

 

直接執行 cscript 也不行:

testuser@localhost ~ $ wine cscript
fixme:cscript:wWinMain (0x40440000 0x0 L"" 1) forwarding to wscript
fixme:wscript:wWinMain No file name specified

 

後來還是用 winetricks 來解決了問題~

winetricks 可以用來安裝一些輔助用的 DLL,讓 wine 可以正常的執行特定的程式~

 

參考資料:

stackoverflow: Is it possible to run a VBScript in UNIX environment?

 

1. 安裝 winetricks

用 Homebrew 來安裝 winetricks:

brew install winetricks
brew tap homebrew/x11
brew install zenity
brew untap homebrew/x11

 

2. 用 winetricks 安裝 Windows Scripting Host 的輔助 DLL

裝好 winetricks 後,可以執行 winetricks –help 看一下說明,

winetricks list-all 可以列出所有支援的動作,

因為我們要跑的是 VBScript,所以要找的是 Windows Scripting Host (wsh):

testuser@localhost ~ $ winetricks list-all | egrep -i wsh
wsh56js                  MS Windows scripting 5.6, jscript only, no cscript (Microsoft, 2006) [downloadable]
wsh56vb                  MS Windows scripting 5.6, vbscript only, no cscript (Microsoft, 2007) [downloadable]
wsh57                    MS Windows Scripting Host 5.7 (Microsoft, 2007) [downloadable,cached]

 

這邊我安裝的動作是 “wsh57″,直接用 winetricks wsh57 就能安裝:

winetricks wsh57

 

安裝好後,可以用 winetricks list-installed 看一下現在有安裝的東西~

這邊的 wsh56vb 應該是安裝 wsh57 時自動安裝的:

testuser@localhost ~ $ winetricks list-installed
wsh56vb
wsh57

 

3. 用 Wine 執行 VBScript

先測試一下 cscript 能不能執行… 這次看起來很正常:

testuser@localhost ~ $ wine cscript
fixme:ole:CoInitializeSecurity (0x0,-1,0x0,0x0,0,3,0x0,0,0x0) - stub!
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Usage: CScript scriptname.extension [option...] [arguments...]
Options:
//B         Batch mode: Suppresses script errors and prompts from displaying
//D         Enable Active Debugging
//E:engine  Use engine for executing script
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
//I         Interactive mode (default, opposite of //B)
//Job:xxxx  Execute a WSF job
//Logo      Display logo (default)
//Nologo    Prevent logo display: No banner will be shown at execution time
//S         Save current command line options for this user
//T:nn      Time out in seconds:  Maximum time a script is permitted to run
//X         Execute script in debugger
//U         Use Unicode for redirected I/O from the console

 

再來執行 Encode.vbs:

testuser@localhost ~ $ wine cscript JS_Encode.vbs test.vbs
fixme:ole:CoInitializeSecurity (0x0,-1,0x0,0x0,0,3,0x0,0,0x0) - stub!
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
err:ole:CoGetClassObject class {6c736db1-bd94-11d0-8a23-00aa00b58e10} not registered
err:ole:CoGetClassObject no class object {6c736db1-bd94-11d0-8a23-00aa00b58e10} could be created for context 0x1
fixme:ole:CLSIDFromProgIDEx L"Scripting.Encoder",0x32efc0: semi-stub
fixme:ole:CLSIDFromProgIDEx L"Scripting.FileSystemObject",0x32efc0: semi-stub

 

雖然有一些錯誤訊息,不過其實 Encode.vbs 已經正確執行完畢,產生出 test.vbe~

看來 winetricks 是可以幫忙解決一些在 wine 上執行程式的問題囉~

 

(本頁面已被瀏覽過 1,519 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料