Solved

Executing VBScript that contains sendkeys

Posted on 2003-10-31
10
6,457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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