Solved

msscript.ocx with atl problem

Posted on 2003-12-09
7
1,503 Views
Last Modified: 2007-12-19
I have this code in vbs:
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate (" - Conversation")
WshShell.SendKeys ("check")
WshShell.SendKeys ("{ENTER}")

i need to write in c++ with atl. i tried the following:
bstr_t bstrLanguage(L"VBScript");
_bstr_t bstrCode1(L"set WshShell = WScript.CreateObject(\"WScript.Shell\")\n");
_bstr_t bstrCode2(L"WshShell.AppActivate (\" - Conversation\")\n");
_bstr_t bstrCode3(L"WshShell.SendKeys (\"check\") \n");
_bstr_t bstrCode4(L"WshShell.SendKeys (\"{ENTER}\")\n");
IScriptControlPtr spScriptCtl(__uuidof(ScriptControl));
spScriptCtl->put_Language(bstrLanguage);
spScriptCtl->AddCode(bstrCode1);
spScriptCtl->AddCode(bstrCode2);
spScriptCtl->AddCode(bstrCode3);
spScriptCtl->AddCode(bstrCode4);

this generates an error ( the vbs script works fine).
how to fix it?
0
Comment
Question by:etay
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:purpleblob
ID: 9906762
What's the error it reports ?
0
 
LVL 15

Expert Comment

by:Raisor
ID: 9907932
Hi,

msscript.ocx  seems an unstable little thing to me regarding this article ---> http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q315922

Anyway, just as an approach:

When you use this function in c++:

function StartCalc()
{
 var WshShell = new ActiveXObject("WScript.Shell");
 var oExec = WshShell.Exec("calc");
     WshShell = null;
}

... you'll get the calculator going ... but from design this looks a little different to your code!

I can not test this right now, but why not trying:

function StartConversation()
{
 var WshShell = new ActiveXObject("WScript.Shell");
 var oExec1 = WshShell.AppActivate(" - Conversation");
 var oExec2 = WshShell.SendKeys("check");
 var oExec3 = WshShell.SendKeys("{ENTER}");
 WshShell = null;
}


Best regards, Raisor
0
 

Author Comment

by:etay
ID: 9910379
regarding first comment it return an iexplore error reported in the visual studio debug view. &  the code itself is not running.
regarding the seond comment , i think you missed the main problem; the problem is not in the vbscript itself but with the VC++ ATL implementing it. javascript wont solve this.

the vb script you have here will add "check" string & send it to any open conversation in the msn messenger.

the purpose of the vc code is to automate this withput vbs file.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 6

Accepted Solution

by:
purpleblob earned 500 total points
ID: 9910834
Okay, it's been a few years since I used the scripting control but it would appear you're using the the wrong code to create your object in the script you've supplied, i.e.

replace

_bstr_t bstrCode1(L"set WshShell = WScript.CreateObject(\"WScript.Shell\")\n");

with

_bstr_t bstrCode1(L"set WshShell = CreateObject(\"WScript.Shell\")\n");

See if this works - if it does then I understand the reason - it's probable that WScript object is added to the Windows scripting engine when used directly via a windows script (i.e. running a .vbs through Windows). When you create the scripting control you need to either create and then add the WScript object to your instance of the scripting or use the global version of CreateObject.

If this doesn't solve the problem then please explain what happened (if anything) witht he chane and I'll have another look. On my machine I've just tested this change and it doesn't exception when run, although I obviously have nothing that the script actually interacts with so I cannot say whether your script works.

Hope this helps

0
 
LVL 6

Expert Comment

by:purpleblob
ID: 9910876
Ah, I see this is interacting with MSN - okay I just tried the amended code which sent the word check into messenger and then "pressed" return - all works fine here with the amended code
0
 

Author Comment

by:etay
ID: 9910899
thanks purpleblob,
it works.
0
 
LVL 6

Expert Comment

by:purpleblob
ID: 9911077
Glad to have helped
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 76
topping3 challenge 14 50
firstChar challenge 13 84
C# Error - Add Failed 12 39
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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