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

I think what you’re looking for is this. shell.run “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 (“http://schemas.microsoft.com/cdo/configuration/sendusing”)=2 ‘SMTP Server MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver”)=”smtp.server.com” ‘SMTP Port MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport”)=25 MyEmail.Configuration.Fields.Update MyEmail.Send set MyEmail=nothing If your SMTP server requires a … Read more

VBScript: What is the simplest way to format a string?

Replace (strFormat, “{0}”, value1) Based on your code snip, I’m guessing you believe Replace mutates strFormat directly. It doesn’t work like that; You assign the result to the original variable like this: strFormat = Replace (strFormat, “{0}”, value1) You can also assign to another variable to store the changed results, like this: strFormat2 = Replace … Read more

ADODB.Parameters error ‘800a0e7c’ Parameter object is improperly defined. Inconsistent or incomplete information was provided

Common occurrence is likely you do not have adVarChar defined, so the CreateParameter() method is “improperly defined”. This is just an example of one of the many named constants found in the ADODB Library. A messy approach to dealing with this is to just define the value yourself something like; Const adVarChar = 200 The … Read more