3
A
回答
0
如果你想創建使用VBScript關聯腳本當你寫點擊一個文件,並用一定的程序打開它要做到這一點,例如,你可以使用這個腳本我有創建歸途:
'Run Script
InsertContextMenu
Sub InsertContextMenu()
Dim sText
Dim sExePath
'For executable-only context menu, the key should be created here
'HKEY_CLASSES_ROOT\exefile\shell
sText = InputBox ("Enter the Text for the context menu." & vbNewLine & vbNewLine & "Example" & vbNewLine & "Open with Notepad")
If Len(Trim(sText)) > 0 Then
sExePath = InputBox ("Enter the path of the executable file for the context menu." & vbNewLine & vbNewLine & "Example" & vbNewLine & "C:\Windows\Notepad.exe")
If Len(Trim(sExePath)) > 0 Then
Set SHL = CreateObject ("WScript.Shell")
SHL.RegWrite "HKCR\*\Shell\" & sText & "\",sText
SHL.RegWrite "HKCR\*\Shell\" & sText & "\Command\", sExePath & " %1"
If Len(SHL.RegRead ("HKCR\*\Shell\" & sText & "\Command\")) > 0 Then
MsgBox "The Context Menu successfully created !.",vbInformation
Else
MsgBox "An unknown error has occured !!",vbCritical
End If
End If
End If
Set SHL = Nothing
End Sub
只需複製上面的代碼,並粘貼到文件中,並給該文件.vbs
擴展。
7
要使用特定應用程序打開文件,請使用methood來運行該應用程序並將文件名作爲參數傳遞。
下面是打開記事本,Internet Explorer和Microsoft Word中的同一個文本文件的例子:
strFileName = "c:\myfile.txt"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "notepad " & strFileName
oShell.Run "iexplore " & strFileName
oShell.Run "winword " & strFileName
請注意,如果文件名包含空格,則需要enslose它在引號,像這樣:
oShell.Run "winword ""c:\my file.txt"""
+0
海倫..你的代碼工作第一次..它被拋出爲「Microsoft VBScript運行時錯誤'800a0046' - 權限被拒絕「但我沒有更改代碼,也沒有更改文件或文件權限的路徑 – Ramesh 2010-08-10 12:14:06
相關問題
- 1. Like Open with Open圖
- 2. VBScript字典項通過byref
- 3. SendTo/Open With
- 4. CameraCalibration with Open CV
- 5. SyntaxError using`with open ...`
- 6. Enums with vbscript
- 7. 找到Finder中的「Open With」菜單項
- 8. emacs如何爲文件選擇「open-with」?
- 9. Rails:使用「Open With」選項下載文件
- 10. 使用時with..open
- 11. Nav with JS(double open)
- 12. Python - with open()except(FileNotFoundError)?
- 13. 使用「open()」vs「with open()」讀取文件「
- 14. VBScript來通過SMTP
- 15. 顯示Open Ticket,通過OsTicket中的打開選項卡過期票據
- 16. option_groups_from_collection_for_select with include_blank選項
- 17. SSDT ColumnStoreIndex WITH選項
- 18. iOS「Open With ...」ZIP文件
- 19. Ruby Open-URI with Dynamic Website
- 20. 通過MacPorts安裝Open MPI
- 21. form_for with has_many:通過
- 22. belongs_to with has_many通過
- 23. 刪除通過VBScript中
- 24. 通過VBScript自定義Excel
- 25. 的VBScript - 通過功能
- 26. 通過vbscript打開outlook 2010
- 27. 通過VBScript連接到Oracle
- 28. GetModuleFilename返回通過VBScript中
- 29. 通過vbscript轉置Excel
- 30. 右鍵單擊「open with」選項如何在大多數Linux GUI中運行?
我不清楚你要求的是 - 你要求a)你的VBScript是「打開方式」菜單中的選項之一,或b)給定一個文件,檢索可用的「Open With」項目列表,並可能調用其中的一個(通過VBScript),或者c)通過VBScript給出一個文件,以導致「打開方式」對話框出現? – 2010-08-10 10:54:03
我必須用其原始文件類型以外的其他格式打開文件。 例如:如果一個文件是通過VBScript的文字格式,我必須 以NOTpad格式打開它 – Ramesh 2010-08-10 11:41:04
你的意思是,使用不同的應用程序打開一個文件,默認的文件? – Helen 2010-08-10 11:59:42