visualstudio.vbs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ' Copyright (c) 2016, Evgeny Panasyuk
  2. ' Permission is hereby granted, free of charge, to any person or organization
  3. ' obtaining a copy of the software and accompanying documentation covered by
  4. ' this license (the "Software") to use, reproduce, display, distribute,
  5. ' execute, and transmit the Software, and to prepare derivative works of the
  6. ' Software, and to permit third-parties to whom the Software is furnished to
  7. ' do so, all subject to the following:
  8. '
  9. ' The copyright notices in the Software and this entire statement, including
  10. ' the above license grant, this restriction and the following disclaimer,
  11. ' must be included in all copies of the Software, in whole or in part, and
  12. ' all derivative works of the Software, unless such copies or derivative
  13. ' works are solely in the form of machine-executable object code generated by
  14. ' a source language processor.
  15. '
  16. ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. ' FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  19. ' SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  20. ' FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  21. ' ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. ' DEALINGS IN THE SOFTWARE.
  23. ' e-mail: E?????[dot]P???????[at]gmail.???
  24. Option Explicit
  25. Dim filename, line, column
  26. Dim MSVS_versions, version
  27. Dim dte, fso, wshShell
  28. Dim fullpath
  29. filename = WScript.Arguments(0)
  30. line = WScript.Arguments(1)
  31. column = WScript.Arguments(2)
  32. MSVS_versions = Array _
  33. ( _
  34. "VisualStudio.DTE.7", _
  35. "VisualStudio.DTE.7.1", _
  36. "VisualStudio.DTE.8.0", _
  37. "VisualStudio.DTE.9.0", _
  38. "VisualStudio.DTE.10.0", _
  39. "VisualStudio.DTE.11.0", _
  40. "VisualStudio.DTE.12.0", _
  41. "VisualStudio.DTE.14.0", _
  42. "VisualStudio.DTE.15.0" _
  43. )
  44. On Error Resume Next
  45. For each version in MSVS_versions
  46. Err.Clear
  47. Set dte = getObject(,version)
  48. If Err.Number = 0 Then
  49. Exit For
  50. End If
  51. Next
  52. If Err.Number <> 0 Then
  53. Set dte = WScript.CreateObject("VisualStudio.DTE")
  54. Err.Clear
  55. End If
  56. Set wshShell = WScript.CreateObject("WScript.Shell")
  57. Set fso = WScript.CreateObject("Scripting.FileSystemObject")
  58. fullpath = fso.GetAbsolutePathName(filename)
  59. dte.MainWindow.Activate()
  60. dte.MainWindow.Visible = True
  61. dte.UserControl = True
  62. wshShell.AppActivate dte.MainWindow.Caption
  63. dte.ItemOperations.OpenFile fullpath
  64. dte.ActiveDocument.Selection.MoveToLineAndOffset line, column + 1
  65. if Err.Number <> 0 Then
  66. WScript.Quit Err.Number
  67. End If
  68. On Error Goto 0