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

Passing-variable-from-vbscript-to-batch-file with arguments

I think what you’re looking for is this. “job.bat “”argfile.ext”” ” & inp However, as Ansgar Wiechers points out, this is a potentially severe security hole, as a treacherously crafted XML file could run arbitrary commands. To encapsulate your batch file arguments and prevent unintended consequences, consider switching to the Shell.Application object’s ShellExecute method. … Read more

How to find the window Title of Active(foreground) window using Window Script Host

Short answer: You can’t. At least not without writing a COM wrapper for the relevant Windows API calls. Can’t you just use AppActivate and check the result? Set oShell = CreateObject(“WScript.Shell”) If oShell.AppActivate “Untitled – Notepad” Then oShell.SendKeys “Hello, world!” End If Long answer: To get the active window title, you need to call the … Read more

Find my own process ID in VBScript

mshta terminates itself immediately. Maybe it’s too late to achieve parent process id by using WMI service. So, I’d use something like this to eliminate concurrent script processes. Generate random things. Determine an application which could be installed on each system, never terminates by itself (e.g. command prompt with /k parameter). Start the application in … Read more

How to set delay in vbscript

Work this end (XP). Create a new file, call it test.vbs. Put this in it. WScript.Sleep 1000 MsgBox “TEST” Run it, notice the delay before the message box is shown. Note, the number is in Milliseconds, so 1000 is 1 second.

How can I use Clipboard in vbscript? [duplicate]

You can do it with an html object to retrieve the contents of the clipboard: ‘ Get clipboard text Set objHTML = CreateObject(“htmlfile”) text = objHTML.ParentWindow.ClipboardData.GetData(“text”) EDIT: I use this snippet to put text back on the clipboard, but it needs third party software; a standalone executable ‘clip.exe’ which can be found on Windows 2003 … Read more

VBScript to send email without running Outlook

You can send email without Outlook in VBScript using the CDO.Message object. You will need to know the address of your SMTP server to use this: Set MyEmail=CreateObject(“CDO.Message”) MyEmail.Subject=”Subject” MyEmail.From=”[email protected]” MyEmail.To=”[email protected]” MyEmail.TextBody=”Testing one two three.” MyEmail.Configuration.Fields.Item (“”)=2 ‘SMTP Server MyEmail.Configuration.Fields.Item (“”)=”” ‘SMTP Port MyEmail.Configuration.Fields.Item (“”)=25 MyEmail.Configuration.Fields.Update MyEmail.Send set MyEmail=nothing If your SMTP server requires a … Read more