Solved

Executing VBScript that contains sendkeys

Posted on 2003-10-31
10
6,456 Views
Last Modified: 2013-12-24
I need to execute a VBScript on the server by a page request.  The script functions correctly when started directly from the desktop (has a .vbs extension). The script opens applications and uses sendkeys to accomplish tasks.  

I've been successful using cfexecute to start cmd or wsh, but it runs system.  I'm ok with it occupying the desktop while it runs.

How can I run the script?

Thanks!
0
Comment
Question by:duhar
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 17

Expert Comment

by:anandkp
ID: 9662215
U mentioned u used CFEXECUTE ... right !
then what do u mean by "How can I run the script?"
0
 
LVL 4

Expert Comment

by:procept
ID: 9662501
Hi,

<cfexecute name="C:\WINNT\System32\CScript.exe" arguments="C:\shutdown.vbs"/>

OR

<cfexecute name="C:\WINNT\System32\CScript.exe C:\shutdown.vbs"/>

Make sure your path to the vbs file does not contain any spaces!

What doe you mean by "but it runs system"? Do you want to actually see it execute? I doubt if that is possible, even if CF uses your username/password to start the service....

HTH,

Chris


0
 

Author Comment

by:duhar
ID: 9664983
I don't really want to see it execute.  I just didn't realize that it could run as a service.

I guess the better question to ask is...
Can a vbscript running as a service (started by cfexecute) still have all the functionality as if it was initiated and ran on the desktop?  wshshell.sendkeys and .run in particular?

Thanks so much!
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 17

Expert Comment

by:anandkp
ID: 9668726
ok in that case - use a CFScheduler [using CFEXECUTE] to schedule ur vbscript. - so u dont see it execute - but it keeps running in the background as & when required by u & specified in the scheduler timings.

this wld enable u to run ur vbscript running as a service !

HTH

K'Rgds
Anand
0
 
LVL 4

Expert Comment

by:procept
ID: 9669283
Just to clear up some confusion.... I didn't mean the VBScript should run as a service, I meant that you won't actually see the script execute on the screen , even if the CF-Service runs under your username/pwd.

I played around a bit during the weekend and found that using <cfexecut> for a VBScript with the sendkeys command doesn't work as expected. Can you post the script you want to execute or at least describe what you want to to??

Right now I would say your best bet would be to use the windows scheduler. :-(

Chris


0
 
LVL 17

Expert Comment

by:anandkp
ID: 9669312
yeah ... windows scheduler wld be a good idea as well !
0
 

Author Comment

by:duhar
ID: 9680648
To explain a little better,
I have ODBC read only on an POS/Inventory application.  I've written Flash/CF applications to work around things a don't like.  Since I can't write back to their database, I need a script to post changes through the normal UI.

Scheduler did work for me.  Thanks to Norton it didn't work during my original test.  I can accept scheduler if there is no other way.  

Here is the script.  Thanks so much for the time!!

set wshShell = WScript.CreateObject("WScript.Shell")
Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
' TEST.TXT CONTAINS THE DATA TO POST
Set File = Fso.GetFile("c:\test.txt")
Set Textstream = File.OpenAsTextStream(1)
'START THE PROGRAM AND GET TO THE RIGHT SPOT
WshShell.Run "C:\UIProgram.exe"
WScript.Sleep 5000
WshShell.SendKeys("FIL{ENTER}")
WshShell.SendKeys("OPMAX{ENTER}{ENTER}{ENTER}")

'LOOP THROUGH THE DATA
Do while Not TextStream.AtEndOfStream
data = textStream.ReadLine & Newline
wshShell.SendKeys data
WScript.Sleep 500
WshShell.SendKeys "{F4}"
WScript.Sleep 500
WshShell.SendKeys "{F12}"
WScript.Sleep 500
loop

'AFTER THE DATA IS POSTED, FINALIZE
WScript.Sleep 10000
WshShell.SendKeys "{ESC}"
WScript.Sleep 500
WshShell.SendKeys ("OPMAX{ENTER}")
WScript.Sleep 500
WshShell.SendKeys "N"
WScript.Sleep 500
WshShell.SendKeys "{F3}"
0
 
LVL 4

Accepted Solution

by:
procept earned 250 total points
ID: 9685065
I just did a test with your script. Only changed the run command to start notepad.exe. ;-))

Works on desktop, works with Windows scheduler, does not work with <cfexecute>. :-((

I saved the output of <cfexecute> to a file (<cfexecute name="......" outputfile="C:\vbsExec.txt">), but, did not show any error.

Seems like the Windows scheduler is your easiest option. :-((

Chris
0
 
LVL 2

Expert Comment

by:jalpino
ID: 10364177
You might also want to write a batch file (.bat) that contains your windows\dos commands and execute that instead of the instructions themselves using <cfexecute>.

Jalpino
0
 
LVL 2

Expert Comment

by:jalpino
ID: 10364178
disreguard that last post, I didnot see that answer was accepted
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question