WScript.Echo throwing object required error in vbscript - command-line

I'm trying to display messages as my vbscript program runs. It runs off a command prompt in xp, for example: cscript.exe test.vbs. I don't want to use msgBox while this is running as I just want it to post the scripts progress, but I don't want any user interaction.
I tried using Wscript.echo "Some text", but I'm getting compile errors when I step through the program using Words built-in vbeditor.
I found this code and it runs fine in another file:
Option Explicit
Dim strComputer
strComputer = "LocalHost"
WScript.Echo "Computer: " _
& strComputer
WScript.Quit
I then tried using Dim and set to setup a Wscript variable, but that didn't work either.
Any ideas as to what I'm doing wrong? I did verify Wscript is running on this machine.
Thanks,
James

Word uses VBA (Visual Basic for Applications), not VBScript. Although both languages belong to the Visual Basic family, they have differences. One of them is that the WScript object isn't available in VBA - that's why you're getting errors when debugging your script in Word.
Having said that, your code is valid and runs perfectly fine with both cscript and wscript.

Related

VB script for auto switch windows

I need to auto switch between 2 windows which are dashboards from the same program, but run in seperate windows. I saw the following:
Option Explicit
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Do
WScript.Sleep 30000
WshShell.SendKeys("%{TAB}")
Loop
There is a note: If you want to stop it, then you need to kill the process called "wscript".
Can someone tell me how to include this kill command, as when i run the code i get stuck in an endless loop and need to restart pc to stop it.
Perhaps there is a better solution even? its for an office tv that needs to rotate between dashboards of data on seperate windows.
Thanks!

How do I tell eclipse that an external tool is done executing?

The Eclipse IDE has a feature where one could run external tools. I use it to run batch scripts. Oddly if a batch script runs a powershell command, the powershell command will never exit until I hit enter. This is especially odd since it exits just fine when running in cmd. How should I correct my script so that it runs as expected via the eclipse external tools?
Current script (foo.bat):
#echo off
echo "Hello 1"
REM Configure this to your installation of maven.
SET "CMD=C:\foo.ps1"
REM Reformat args to be Powershell friendly.
SET "ARGS=%*"
SET "ARGS=%ARGS: =' '%"
PowerShell.Exe -Command "%CMD%" '%ARGS%'
echo "Hello 2"
EXIT /B
In cmd, I see "Hello 1", the output of %CMD%, and "Hello 2". In Eclipse, I see "Hello 1", the output of %CMD%, and then it hangs in the progress tab forever until I click the Console window and press the enter key.
I tried passing the -NonInteractive flag to Powershell. I tried having my Powershell script echo a newline at the end. Not sure how to get this to "just work".
Found the answer. I needed to add a NUL redirect to the end of my Powershell command. So it looks like this:
#echo off
REM Configure this to your installation of maven.
SET "CMD=C:\foo.ps1"
REM Reformat args to be Powershell friendly.
SET "ARGS=%*"
SET "ARGS=%ARGS: =' '%"
PowerShell.Exe -Command "%CMD%" '%ARGS%' < NUL
Note that I also removed the dubugging code from the script found in my question. If you add that code back in, you'll see that it echos everything now.

Creating a basic vbscript to call a single command

I have installed program where I need to run a command line in order for it to do something. So I want to create a simple vbscript to carry out this command ion order for me to deploy the cmd to several machines using SCCM2012.
The program sits in the %ProgramFiles% directory and it is an 'exe' file with a cmd switch I am wanting to use, example
program.exe -testcmd
Hope this makes sense and can anyone assist please?
I have looked at the forums but I don't understand what all the command mean in the script.....(I am hopeless)
You can use the Run method of the WshShell object. Just make sure to put quotes around the path to your EXE. In VBScript, you need to escape embedded quotes (by doubling them) or you can use the Chr(34) statement.
strCmd = Chr(34) & "%ProgramFiles%\program.exe" & Chr(34) & " -testcmd"
CreateObject("WScript.Shell").Run strCmd

launch cmd run command isn't working

I am working on a script or batch file (or combo of the two) which imports an outlook prf file, then launches a new cmd.exe window runs a application specific program which when passed a server cluster name pulls in an outlook data file in the previously created outlook profile. So i have the vbs script that checks for the outlook profile if it doesn't exist it imports the prf. That's working fine, now the program i need to is called addiman.exe the server cluster name is gsiapp...the manual method is i launch a cmd windows and type "addiman gsiapp" i wish to automates this by calling it in a routine called :Filesite the below command has been unsuccessful, it launches a new cmd.exe window but doesn't run the command.
:ImportPRf
call cscript \\gsf1\Apps\Scripts\public\deployprf.vbs
GOTO :FileSite
:FileSite
start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe" GSIAPP
GOTO :EXIT
:Exit
Exit
start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe GSIAPP"
try this, because cmd.exe interprets the part between "" as comand and ignores the GSIAPP statement
wild guess. Try adding another call before the "start" - like this
:FileSite
call start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe" GSIAPP
problem solved, the full path isn't needed. just had to putt "addiman GSIAPP". Thanks everyone who provided suggestions.

Outlook rule to run VBA script to pass the body of email to external program

I've set up an Outlook rule that filters emails. I want to run an external program (python script) to parse each such email.
I know of the SHELL function, but I need a way to pass the body of the email to my external program.
Google is your friend for this one, I got this snippet by searching "outlook vba script".
Basically for the body of the email you want to pass Item.Body to your python script.
http://support.microsoft.com/kb/306108
Sub CustomMailMessageRule(Item As Outlook.MailItem)
MsgBox "Mail message arrived: " & Item.Subject
End Sub`
Sub CustomMeetingRequestRule(Item As Outlook.MeetingItem)
MsgBox "Meeting request arrived: " & Item.Subject
End Sub
You'd need a VBA script to parse python in outlook.
Press alt+F11. You will get a VBA window.
Sub python(Item As Outlook.MailItem)
Shell ("python C:\path\tp\your\filename.py")
End Sub
I hope you have set windows variable path for python.
Shell command passes the command to windows shell prompt. You can test this by running your python script in command prompt. If it is working there, then it should work here as well.