Re: How do I set an environment variable to a string
- From: ChristopherL <clusardi2k@xxxxxxx>
- Date: Wed, 13 Aug 2008 08:04:29 -0700 (PDT)
On Aug 13, 7:47 am, Dave Peterson <peter...@xxxxxxxxxxxxxxxx> wrote:
I don't understand what this:
ev_result = Wait_("cmd /k set chris=""1 2 3"" & %chris%", "", False, True)
is doing.
And I don't understand what you're really trying to do.
Are you trying to create an environment variable that's available for just the
duration of that Shell command--and only available to the that Shell?
Or are you trying to create an environment variable that can be seen by
anything?
ChristopherL wrote:
On Aug 13, 7:31 am, Dave Peterson <peter...@xxxxxxxxxxxxxxxx> wrote:
The environment variable would be alive as long as the Shell is alive--but it's
limited to that shell and its children.
So if you need to run a .bat file that needs an environment variable, you could
shell to a different .bat file that sets the environment variable and then runs
the .bat file that you need to run.
But if you want to change the environment variable globally, it's a different
story.
Win95 came with command called WinSet that did this. But I don't see it in
WinXP (at least in a normal install).
But you could search google looking for alternatives.
I've never used this, but it looks interesting:http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849/
...
Dave Peterson- Hide quoted text -
- Show quoted text -
Dave, I tried the following, but in the command prompt window it
said:
'%chris%' is not recognized as an internal or external
command, operable program or batch file.
Chris
Sub test6()
Dim count As Long
Dim ev_result As String
Row = 30
count = 0
ev_result = Wait_("cmd /k set chris=""1 2 3"" & %chris%", "", False,
True)
ev_result = Environ("chris")
Debug.Print "---> " & ev_result & " <---"
Debug.Print "end"
End Sub
--
Dave Peterson- Hide quoted text -
- Show quoted text -
For every one who has not formally tuned in, I've added a few comments
to the test.
After executing the code, the command prompt windows stays around and
says:
'%chris%' is not recognized as an internal or external command,
operable program or batch file.
Chris
Sub test7()
Dim Task_ID As Variant
Dim ev_result As String
'Create shell execute a set command, and then see if can use the
contents of the variable
Task_ID = Shell("cmd /k set chris=""1 2 3"" & %chris%") '/k means
stay around, & means do 2nd cmd
'Give it another try, see if environment variable still exists
ev_result = Environ("chris")
Debug.Print "---> " & ev_result & " <---"
End Sub
.
- References:
- How do I set an environment variable to a string
- From: ChristopherL
- RE: How do I set an environment variable to a string
- From: Bob Bridges
- Re: How do I set an environment variable to a string
- From: ChristopherL
- Re: How do I set an environment variable to a string
- From: Bob Bridges
- Re: How do I set an environment variable to a string
- From: ChristopherL
- Re: How do I set an environment variable to a string
- From: ChristopherL
- Re: How do I set an environment variable to a string
- From: Dave Peterson
- Re: How do I set an environment variable to a string
- From: ChristopherL
- Re: How do I set an environment variable to a string
- From: Dave Peterson
- How do I set an environment variable to a string
- Prev by Date: Using VBA to sort a column of data
- Next by Date: RE: VBA in a webpage
- Previous by thread: Re: How do I set an environment variable to a string
- Next by thread: Re: How do I set an environment variable to a string
- Index(es):
Relevant Pages
|