Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to invoke a VBScript from inside a MFC/C++ program ?

1,751 views
Skip to first unread message

Sudhakar

unread,
Jun 27, 2009, 11:03:01 AM6/27/09
to

I want to execute a VBScript in a Windows XP machine via VC++. this will run
in the user machines, so I'm unaware of the policies and setting applied for
those users.


How to execute that test.vbs file inside VC++ program ?
I wrote an MFC application, and followed the methods below,

1) I used system() function, it works, but I was told that's not the good way

2)then I opted for

ShellExecute(NULL,_T("open"),"C:\\test.vbs",NULL,NULL,SW_SHOW);
it worked but I had a doubt that the "open" verb for the VBScript mmight be
disabled for the VBScript in some of the machines by tech savvy administrators

3) so, i thought of invoking the Wscript.exe explicitly like the call below,
ShellExecute(NULL,_T("open"), ""C:\\wscript.exe
C:\\GPSUpgrade.vbs",NULL,NULL,SW_SHOW);
but this is not working, the GetLastError() returns the Error description "
The spefified module is not found"

Please anybody suggest that How can i call a VBScript from inside a MFC/C++
program in such a way that it bypasses any user policies(the user must have
some basic privileges).


Sudhakar

unread,
Jun 27, 2009, 11:09:01 AM6/27/09
to

a small correction in my last para above,

Please anybody suggest that How can i call a VBScript from inside a MFC/C++
program in such a way that it bypasses any user policies(I know that the
user must have some basic privileges).

thanks
Sudhakar

Alex Blekhman

unread,
Jun 27, 2009, 1:35:42 PM6/27/09
to

"Sudhakar" wrote:
> Please anybody suggest that How can i call a VBScript from
> inside a MFC/C++ program in such a way that it bypasses any user
> policies(I know that the user must have some basic privileges).

If you could do this your program would be a malware. Any decent
system administrator will prohibit a program if it tries to breach
security policies.

Alex


Alex Blekhman

unread,
Jun 27, 2009, 1:31:43 PM6/27/09
to

"Sudhakar" wrote:
> 3) so, i thought of invoking the Wscript.exe explicitly like the
> call below,
> ShellExecute(NULL,_T("open"), ""C:\\wscript.exe
> C:\\GPSUpgrade.vbs",NULL,NULL,SW_SHOW);
> but this is not working, the GetLastError() returns the Error
> description "The spefified module is not found"

You're calling ShellExecute with one string that contains both
wscript.exe path and its parameters. Instead, you should pass
wscript.exe as a lpFile and GPSUpgrade.vbs as lpParameters
arguments. Also, it's bad practice to call wscript.exe with
hardcoded path. User can install Windows on any disk with any
directory name. You should call GetSystemDirectory (or
SHGetFolderPath) in order to obtain system directory.

Alex


Tim Roberts

unread,
Jun 28, 2009, 2:54:04 AM6/28/09
to

Sudhakar <Sudh...@discussions.microsoft.com> wrote:
>
>I want to execute a VBScript in a Windows XP machine via VC++. this will run
>in the user machines, so I'm unaware of the policies and setting applied for
>those users.
>
>How to execute that test.vbs file inside VC++ program ?
>I wrote an MFC application, and followed the methods below,
>
>1) I used system() function, it works, but I was told that's not the good way

If it works, then I would argue there is no particular reason to look
elsewhere. The other solutions offer more options and more flexibility,
but it's silly to discard an option that works based fundamentally on
superstition.

>ShellExecute(NULL,_T("open"),"C:\\test.vbs",NULL,NULL,SW_SHOW);
>it worked but I had a doubt that the "open" verb for the VBScript mmight be
>disabled for the VBScript in some of the machines by tech savvy administrators

That's unlikely. There are standard system utilities implemented as .vbs
scripts. And if the administrator doesn't want VBScripts to execute, then
why should your VBScript should be allowed to run?
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Pavel A.

unread,
Jun 28, 2009, 11:55:52 AM6/28/09
to

Your app should host the script control, rather
than spawn external wscript or cscript.
Then, execution of a script by your app
will be not distinguishable from anything else
that your app can do under these policies.

- pa


Ben Voigt [C++ MVP]

unread,
Jun 30, 2009, 4:53:39 PM6/30/09
to


"Tim Roberts" <ti...@probo.com> wrote in message
news:8e4e451enqh1t22od...@4ax.com...

Note that I was the one who said this, but what I actually said was that the
"edit" verb would be default, not that the "open" verb would be deleted. So
relying on the default verb, as the system() function does, would not be
reliable.

chandpr...@gmail.com

unread,
Jul 5, 2012, 9:03:19 PM7/5/12
to
0 new messages