Solved

Executing VBScript that contains sendkeys

Posted on 2003-10-31
10
6,452 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
Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

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…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

10 Experts available now in Live!

Get 1:1 Help Now