Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #12066

Re: ShellExecute with "RunAs" verb ignores the working directory argument

From "Mayayana" <mayayana@invalid.nospam>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: ShellExecute with "RunAs" verb ignores the working directory argument
Date 2019-03-21 11:34 -0400
Organization A noiseless patient Spider
Message-ID <q70b10$34h$1@dont-email.me> (permalink)
References <158t4z9xz8rj1.18ijto36bnr3g$.dlg@40tude.net> <q6tuah$n9$1@dont-email.me> <u7434rsf8ndx.1i9jgcw24a0h6.dlg@40tude.net>

Show all headers | View raw


"JJ" <jj4public@vfemail.net> wrote

| 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.

Interesting. Thanks. I never noticed that. This is really obscure.
2,3,4,5 haven't been added to the original shell object listing,
but they're in the help file from the Win7 SDK. But runas is
undocumented. Secrets within secrets.

  At first I was excited, but aside from what you're doing
and the ability to stop/start services (which can be done
with WMI) they haven't added anything interesting.

  I found this, in case it's useful:

https://ss64.com/vb/shellexecute.html

"When a script is run with elevated permissions several aspects of the user 
environment may change: The current directory, the current TEMP folder and 
any mapped drives will be disconnected."

|
| >   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. 

Back to microsoft.public.scripting.vbscript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

ShellExecute with "RunAs" verb ignores the working directory argument JJ <jj4public@vfemail.net> - 2019-03-20 21:31 +0700
  Re: ShellExecute with "RunAs" verb ignores the working directory argument "Mayayana" <mayayana@invalid.nospam> - 2019-03-20 13:45 -0400
    Re: ShellExecute with "RunAs" verb ignores the working directory argument JJ <jj4public@vfemail.net> - 2019-03-21 21:48 +0700
      Re: ShellExecute with "RunAs" verb ignores the working directory argument "Mayayana" <mayayana@invalid.nospam> - 2019-03-21 11:34 -0400
        Re: ShellExecute with "RunAs" verb ignores the working directory argument JJ <jj4public@vfemail.net> - 2019-03-23 11:11 +0700
          Re: ShellExecute with "RunAs" verb ignores the working directory argument "Mayayana" <mayayana@invalid.nospam> - 2019-03-23 09:27 -0400
            Re: ShellExecute with "RunAs" verb ignores the working directory argument JJ <jj4public@vfemail.net> - 2019-03-24 13:37 +0700
              Re: ShellExecute with "RunAs" verb ignores the working directory argument "Mayayana" <mayayana@invalid.nospam> - 2019-03-24 11:17 -0400
                Re: ShellExecute with "RunAs" verb ignores the working directory argument JJ <jj4public@vfemail.net> - 2019-03-25 20:12 +0700
                Re: ShellExecute with "RunAs" verb ignores the working directory argument "Mayayana" <mayayana@invalid.nospam> - 2019-03-25 10:52 -0400
  Re: ShellExecute with "RunAs" verb ignores the working directory argument Thomas Langer <spam4nl@langer-online.net> - 2019-03-24 22:50 +0100

csiph-web