Is there a way to use WScript.Shell's Run method to invoke Start?

The reason is that I want to get ahold of a pseudo-hidden environment
variable, %cmdcmdline%. For example, if (on Win XP) at the Cmd window
you type:
SET XY=%cmdcmdline%
SET
you will see how that cmd window was invoked (simply typing echo
%cmdcmdline% might lead to odd results).

Start has the characteristic, that it will preserve the environment
variable settings. Thus, if at the Cmd window you type:
START cmd.exe
SET XYZ=%cmdcmdline%
SET
you'll see that the results are the same as for the original Cmd
window.

That is why I would like to be able to use
CreateObject('WScript.Shell')->Run to invoke Start. However, Run seems
not to know about Start. Any ideas?

Or perhaps someone has a better method? I've tried
Set aEnv=CreateObject("WScript.Shell").Environment("Process")
then
aEnv('cmdcmdline'), aEnv('=cmdcmdline'), and friends without success.

Thanks,
Csaba Gabor from Vienna

Re: Using Run to access Start by Franz

Franz
Mon Aug 14 13:52:29 CDT 2006

Csaba Gabor wrote:
> Is there a way to use WScript.Shell's Run method to invoke Start?

If "start" means the windows's start menu...

try this one:

WSHShell.SendKeys "^{ESC}"

except for the ctrl+alt+del combination wich is impossible
with sendkeys, if you can do it with your keyboard, you can do
it with sendkeys.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx




Re: Using Run to access Start by Babu

Babu
Mon Aug 14 14:32:50 CDT 2006

in reading his post, how did you manage to think he meant the start button?



"Franz aRTiglio" <franzgol@N0SPAMtin.it> wrote in message
news:44e0c67e$0$15874$4fafbaef@reader2.news.tin.it...
> Csaba Gabor wrote:
>> Is there a way to use WScript.Shell's Run method to invoke Start?
>
> If "start" means the windows's start menu...
>
> try this one:
>
> WSHShell.SendKeys "^{ESC}"
>
> except for the ctrl+alt+del combination wich is impossible
> with sendkeys, if you can do it with your keyboard, you can do
> it with sendkeys.
>
> http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
>
>
>



Re: Using Run to access Start by VS

VS
Mon Aug 14 16:14:54 CDT 2006

START is a built in part of cmd.exe so if you really do need to use
START in wscript.run you need to do something like:

Ret = Wscript.Run ( "cmd /c start /wait <some_command>" , 3, true)

Surely %cmdcmdline% only exists if your script has been spawned from
cmd.exe ??

Doesn't %comspec% have what you want ?

set shell = createobject("wscript.shell")
set envProc = shell.Environment("process")
comspec = envProc.item("comspec")
Wscript.Echo "%comspec% = " & comspec & vbcrlf

--
VS

Re: Using Run to access Start by Franz

Franz
Mon Aug 14 19:19:55 CDT 2006

Babu VT wrote:

> in reading his post, how did you manage to think he meant the start
> button?


Maybe nowere, maybe someone should stop topquoting

http://tinyurl.com/hdn68 ;)

By the way, I just trown my 2 eurocents.



Re: Using Run to access Start by Csaba

Csaba
Tue Aug 15 09:56:35 CDT 2006

VS wrote:
> START is a built in part of cmd.exe so if you really do need to use
> START in wscript.run you need to do something like:
>
> Ret = Wscript.Run ( "cmd /c start /wait <some_command>" , 3, true)

But by the time this new Cmd kicks in it is too late, because it will
have its own %cmdcmdline%.

> Surely %cmdcmdline% only exists if your script has been spawned from
> cmd.exe ??

This is not clear to me. %cmdcmdline% as such, as far as I know,
exists only within cmd.exe. However, as far as I am aware, whenever
any program is started off, it has an associated "command line" that
caused it to be executed. Within a VB Project you can obtain it
directly with Command$ and from c++ evidently with GetCommandLine().

For example, if you make a context menu that you associate with any
file that will start off the Cmd window in the directory of that file,
then the cmdcmdline for that Cmd window will not be your vanilla
expansion of %comspec% but rather that expansion followed by the
directive to switch the directory.

> Doesn't %comspec% have what you want ?
>
> set shell = createobject("wscript.shell")
> set envProc = shell.Environment("process")
> comspec = envProc.item("comspec")
> Wscript.Echo "%comspec% = " & comspec & vbcrlf

This doesn't do what I want because I want to know how my script was
called and not where Cmd.exe sits. I believe that I can get the
Command line with Win API, but I was hoping that there was a more
simple minded way.

For example, if you have tlist.exe from Win 2K, then this will show you
each process id (and associated window title). If you then do tlist
pid# then you will get the command line that started that app.
However, the replacement on Win XP for tlist.exe is tasklist.exe (in
other words, I can't guarantee the existence of tlist.exe on a target
system) and it does not offer this feature.

Csaba