Solved

Executing VBScript that contains sendkeys

Posted on 2003-10-31
10
6,453 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
 
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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…
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now