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).
thanks
Sudhakar
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
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
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.
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
"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.