How can I convert a VBScript to an executable (EXE) file? [closed]

There is no way to convert a VBScript (.vbs file) into an executable (.exe file) because VBScript is not a compiled language. The process of converting source code into native executable code is called “compilation”, and it’s not supported by scripting languages like VBScript. Certainly you can add your script to a self-extracting archive using … Read more

How to use GetObject in VBScript

VBScript GetObject documentation can be found here. Here is a VBScript sample: Set objExcelFile = GetObject(“C:\Scripts\Test.xls”) WScript.Echo objExcelFile.Name objExcelFile.Close This code will get you the Excel Workbook object contained in C:\Scripts\Test.xls. You can use TypeName() to confirm that: Set objExcelFile = GetObject(“C:\Scripts\Test.xls”) WScript.Echo objExcelFile.Name WScript.Echo TypeName(objExcelFile) objExcelFile.Close The output will be: test.xls Workbook If the … Read more

WScript.Shell.Exec – read output from stdout

WScript.Shell.Exec() returns immediately, even though the process it starts does not. If you try to read Status or StdOut right away, there won’t be anything there. The MSDN documentation suggests using the following loop: Do While oExec.Status = 0 WScript.Sleep 100 Loop This checks Status every 100ms until it changes. Essentially, you have to wait … Read more

How can I show a message box with two buttons?

You probably want to do something like this: result = MsgBox (“Yes or No?”, vbYesNo, “Yes No Example”) Select Case result Case vbYes MsgBox(“You chose Yes”) Case vbNo MsgBox(“You chose No”) End Select To add an icon: result = MsgBox (“Yes or No?”, vbYesNo + vbQuestion, “Yes No Example”) Other icon options: vbCritical or vbExclamation

How do I include a common file in VBScript (similar to C #include)?

You can create a (relatively) small function in each file that you want to include other files into, as follows: sub includeFile (fSpec) dim fileSys, file, fileData set fileSys = createObject (“Scripting.FileSystemObject”) set file = fileSys.openTextFile (fSpec) fileData = file.readAll () file.close executeGlobal fileData set file = nothing set fileSys = nothing end sub and … Read more

Use clipboard from VBScript

Another solution I have found that isn’t perfect in my opinion, but doesn’t have the annoying security warnings is to use clip.exe from a w2k3 server. Set WshShell = WScript.CreateObject(“WScript.Shell”) WshShell.Run “cmd.exe /c echo hello world | clip”, 0, TRUE Example with a multiline string as per question below : Link1 Dim string String = … Read more

VBscript relative path

WScript.ScriptFullName and FSO.GetParentFolder should solve your problem: >> p = CreateObject(“Scripting.FileSystemObject”).GetParentFolderName(WScript.ScriptFullName) >> >> WScript.Echo p >> M:\bin Update wrt Kiril’s comment: Evidence for the answer “Yes”: Option Explicit Class cX Private Sub Class_Initialize() WScript.Echo “Class_Initialize” End Sub Private Sub Class_Terminate() WScript.Echo “Class_Terminate” End Sub Public Function f() f = “qed” End Function End Class WScript.Echo … Read more