On Wed, 20 Mar 2019 13:45:13 -0400, Mayayana wrote:
> "JJ" <
jj4p...@vfemail.net> wrote
>
>| Meaning that the "RunAs" verb did ignored or messed up the given working
>| directory. FYI, if the Command Prompt is already elevated, everything
> works
>| fine. So is there a solution other than manually readjusting the working
>| directory?
>
> Just guessing as I'm not on a restricted system. My
> first guess would be that, of course, why should it
> cooperate with a programmatic attempt to elevate?
> That would defeat the purpose of restrcitions.
Well, the shell framework itself is automatable. Be it from a VBScript, or
any native application that can use COM. The shell's "runas" verb is a known
method to run an application elevated. The UAC is the one which is
responsible for allowing the elevation or not, by showing the UAC prompt.
> My second guess is... what? I can't find ShellExecute
> as being available either in the WSH docs or in Win7
> MSDN for the Shell object. I've only seen it as an
> API call. Nor do I see it in the typelib on XP.
The ShellExecute is a method of the IShellDispatch2 interface, but MSDN
separate it from the Shell automation object. The Shell automation object
actually implements multiple interfaces: IShellDispatch, IShellDispatch2,
IShellDispatch3, and IShellDispatch4; for shell versions that support those
interfaces. IShellDispatch is the main interface for the Shell object. It's
just like the FolderItems object which also implement FolderItems2 and
FolderItems3.
> This is a longshot, but you might test this:
>
> MsgBox WScript.ScriptFullName
> Set SH = CreateObject("WScript.Shell")
> MsgBox sh.CurrentDirectory
> Set sh = Nothing
>
> That will not always return the same path for both. The
> first is the path of the script. The second can vary. You
> may be getting the path of cscript parent folder.
I only use CurrentDirectory which is already proven as correct by
"elevate.vbs", and that same directory is also used for ShellExecute's
working directory argument.
If "elevate.vbs" (i.e. the parent process) is already elevated, the child
process (i.e. "test.vbs") will have the correct working directory
("test.vbs" shows that too, using CurrentDirectory).
However, if "elevate.vbs" (i.e. the parent process) is not elevated, the
child process (i.e. "test.vbs") will *not* have the correct working
directory ("test.vbs" shows that too, using CurrentDirectory).
None of the script is modified, and the same command line is used, to
reproduce both results.
To sum it up, all of below conditions must be met in order to reproduce the
problem.
1. Windows version is Vista or later.
2. Parent process is not elevated.
3. Working directory of parent process is not Windows's SYSTEM32 directory.
e.g. is not "c:\windows\system32"
4. Child process is executed using VBScript using Shell object's
ShellExecute method.
5. When calling ShellExecute, parent process' working directory is used for
the working directory (vDirectory) argument, and "runas" is used for the
verb (vOperation) argument.
Expected result:
The initial working directory of the child process is same as parent
process'.
Actual result:
The initial working directory of the child process is always the Windows's
SYSTEM32 directory.