From: Nobody on
"Leo" <ttdhead(a)gmail.com> wrote in message
news:i1kphu$7d7$1(a)news.eternal-september.org...
> Environ("PROMPT") returns a blank string for me on Win7 64 Bit.

Same here with XP 32-Bit + SP2. When I type "set" at the command prompt, I
see "PROMPT" string.


From: dpb on
Jeff Johnson wrote:
> "dpb" <none(a)non.net> wrote in message
> news:i1ke21$mbo$1(a)news.eternal-september.org...
>> Leo wrote:
>>> Leo formulated on Wednesday :
>>>> I need a way to get the value of the %prompt% environment variable. I
>>>> would prefer it actually if I could get the value from a more reliable
>>>> source as this is a console app I'm writing.
>>> Scrap the more reliable way section as it is one of the few environment
>>> variables that I don't mind changing. I forgot to mention I have tried
>>> Environ and GetEnvironmentVariable. I think it has to do with the fact
>>> the prompt environment variable is hidden according to
>>> http://ss64.com/nt/prompt.html.
>>>
>> Don't know if there's anywhere like in registry the current value is
>> stashed reliably or not; if GETENV doesn't work (I've never tried it for
>> the prompt string) about the best I can think of would be to issue a
>>
>> SET PROMPT
>>
>> command and redirect the output and parse that. That, of course, has the
>> problem of whether that gets executed in the current shell or a spawned
>> one and whether they're the same or not. Not to mention, of course, the
>> issues of what happens if the user is running an extended shell such as
>> one of the JP Software products <www.jpsoft.com> with a great number of
>> additional features including being able to string variable functions into
>> the string, etc., ...
>>
>>
>> 4NT 3.02B Windows NT 5.01
>> Copyright 1988-1999 Rex Conn & JP Software Inc. All Rights Reserved
>> 4NT S/N CDXXXXXX, registered to ------------
>> for use on a single computer. May not be distributed to others.
>>
>> c:\> set prompt
>> %@if[%@len[%_cwd] le 35,%_cwd,%@left[16,%_cwd]...%@right[16,%_cwd]]$g
>>
>> c:\>
>>
>> Good luck... :)
>
> ECHO %PROMPT% worked for me as well, and you don't have to parse out the
> PROMPT= stuff at the beginning....

Again, will likely by shell-dependent unless you can control which shell
the user uses (_VERY_ rude, imo :) )...

Here again w/ 4NT from JP Software (I deliberately moved to a deep
directory path to demonstrate what happens w/ the prompt defined when
length of the path string is excessive)...

C:\PMW\PWDIR_41\...UN\OLDMS\BACKUPS> echo %prompt
C:\PMW\PWDIR_41\...UN\OLDMS\BACKUPS$g

C:\PMW\PWDIR_41\...UN\OLDMS\BACKUPS> set prompt
%@if[%@len[%_cwd] le 35,%_cwd,%@left[16,%_cwd]...%@right[16,%_cwd]]$g

C:\PMW\PWDIR_41\...UN\OLDMS\BACKUPS>


I don't know what the perceived need or desire is, but I think it's the
act up the proverbial rope in all likelihood unless one restricts it to
a very constrained set of conditions...

--
From: Karl E. Peterson on
on 7/14/2010, Nobody supposed :
> "Leo" <ttdhead(a)gmail.com> wrote...
>> Environ("PROMPT") returns a blank string for me on Win7 64 Bit.
>
> Same here with XP 32-Bit + SP2. When I type "set" at the command prompt, I
> see "PROMPT" string.

Because the console window *has* the %prompt% defined in its
environment block, but Explorer (parent of VB6.exe) doesn't. Take a
look in Process Explorer (double-click any process, go to the
Environment tab in its Properties window).

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Karl E. Peterson on
Leo pretended :
> Leo formulated on Wednesday :
>> I need a way to get the value of the %prompt% environment variable. I would
>> prefer it actually if I could get the value from a more reliable source as
>> this is a console app I'm writing.
>
> Scrap the more reliable way section as it is one of the few environment
> variables that I don't mind changing. I forgot to mention I have tried
> Environ and GetEnvironmentVariable. I think it has to do with the fact the
> prompt environment variable is hidden according to
> http://ss64.com/nt/prompt.html.

The %prompt% environment variable isn't hidden at all. In the case
you're testing, it (almost certainly) just doesn't exist. You need to
understand that your process inherits its environment block from its
parent process. What's your parent process? Is it %comspec%?

Compile this:

Public Sub Main()
MsgBox Environ$("prompt"), , "%PROMPT%"
End Sub

Run it from the command line. It works! :-)

Or, alternatively, write an actual console app, using my drop-in
console support module and vbAdvance. Use this code:

Option Explicit

Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias
"GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As
String, ByVal nSize As Long) As Long

Public Sub Main()
Con.Initialize
Con.WriteLine GetEvar(Command$)
Con.WriteLine Environ(Command$)
End Sub

Public Function GetEvar(ByVal eVar As String) As String
Dim Buffer As String
Dim nLen As Long
nLen = GetEnvironmentVariable(eVar, Buffer, nLen)
If nLen Then
Buffer = Space$(nLen)
If GetEnvironmentVariable(eVar, Buffer, nLen) Then
GetEvar = Left$(Buffer, nLen)
End If
End If
End Function

It'll get the %prompt% just fine if run from a console window, but fail
if run from Explorer.

--
..NET: It's About Trust!
http://vfred.mvps.org