Re: How do I set an environment variable to a string



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
.



Relevant Pages

  • Re: Running Excel
    ... I've gotten away from the SHELL command and am stuck with what appears to be ... Private Sub Command32_Click ... Dim xlWorkbook As Excel.Workbook ... > When you use Shell, you lose all subsequent control of the shelled program. ...
    (microsoft.public.access.modulesdaovba)
  • Re: perl menubased user interface
    ... actually use a perl package OR a hash for this, In a "perl package" ... sub map_method { ... # and they're all shell commands. ... Do whatever you want to wrap a shell command. ...
    (comp.lang.perl.misc)
  • Re: VBScripting, need a little help
    ... > them directly at a command prompt as any of the users and get the desired ... > shell, but nothing is connected or updated. ... >>> 2) I would like to time synch with the domain via VB with out calling ... >>> Sub MapDrive ...
    (microsoft.public.windows.server.scripting)
  • Re: How do I set an environment variable to a string
    ... duration of that Shell command--and only available to the that Shell? ... So if you need to run a .bat file that needs an environment variable, ... Win95 came with command called WinSet that did this. ... Dim ev_result As String ...
    (microsoft.public.excel.programming)
  • Re: How do I set an environment variable to a string
    ... limited to that shell and its children. ... So if you need to run a .bat file that needs an environment variable, ... Win95 came with command called WinSet that did this. ... Dim ev_result As String ...
    (microsoft.public.excel.programming)

Quantcast