Discussion:
How to invoke a VBScript from inside a MFC/C++ program ?
(too old to reply)
Sudhakar
2009-06-27 15:03:01 UTC
Permalink
Raw Message
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
2009-06-27 15:09:01 UTC
Permalink
Raw Message
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
2009-06-27 17:35:42 UTC
Permalink
Raw Message
Post by Sudhakar
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
Pavel A.
2009-06-28 15:55:52 UTC
Permalink
Raw Message
Post by Sudhakar
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).
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
Alex Blekhman
2009-06-27 17:31:43 UTC
Permalink
Raw Message
Post by Sudhakar
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
2009-06-28 06:54:04 UTC
Permalink
Raw Message
Post by Sudhakar
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.
Post by Sudhakar
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, ***@probo.com
Providenza & Boekelheide, Inc.
Ben Voigt [C++ MVP]
2009-06-30 20:53:39 UTC
Permalink
Raw Message
Post by Tim Roberts
Post by Sudhakar
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.
Post by Sudhakar
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?
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.
Post by Tim Roberts
--
Providenza & Boekelheide, Inc.
c***@gmail.com
2012-07-06 01:03:19 UTC
Permalink
Raw Message
checkout this:

http://support.microsoft.com/default.aspx?scid=kb;en-us;221992

Loading...