Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Executing VBScript that contains sendkeys

Posted on 2003-10-31
10
Medium Priority
?
6,459 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
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 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
What You Need to Know when Searching for a Webhost Provider
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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