ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

How to -connect- Windows Visual Basic Apps with Windows Batch files?

<< < (2/4) > >>

OptimalDesigns:
I got this "set -ua ..." off the www as a possible answer to my question.  I write VB code and VBscript when necessary.

Anyone out there knows how to pass an environment variable from Windows?

Phil

f0dder:
I got this "set -ua ..." off the www as a possible answer to my question.-OptimalDesigns (July 17, 2018, 03:28 PM)
--- End quote ---
Where? Considering "u" isn't a valid argument to set, and "-" being the wrong argument specifier, that just seems like bad advice.

I write VB code and VBscript when necessary.-OptimalDesigns (July 17, 2018, 03:28 PM)
--- End quote ---
VBScript (probably) requires the hack from your original post, VB should be able to use normal environment passing. Which language do you need the solution for? And if it's VB, is it old-school VB or VB.NET? And which version?

Anyone out there knows how to pass an environment variable from Windows?-OptimalDesigns (July 17, 2018, 03:28 PM)
--- End quote ---
It's the seventh argument to CreateProcess ;)

KodeZwerg:
Visual Basic with .Net support (code from Microsoft)

--- ---Module Example
   Public Sub Main()
      Dim envName As String = "AppDomain"
      Dim envValue As String = "True"

      ' Determine whether the environment variable exists.
      If Environment.GetEnvironmentVariable(envName) Is Nothing Then
         ' If it doesn't exist, create it.
         Environment.SetEnvironmentVariable(envName, envValue)
      End If

      Dim createAppDomain As Boolean
      Dim msg As Message
      If Boolean.TryParse(Environment.GetEnvironmentVariable(envName),
                          createAppDomain) AndAlso createAppDomain Then
         Dim domain As AppDomain = AppDomain.CreateDomain("Domain2")
         msg = CType(domain.CreateInstanceAndUnwrap(GetType(Example).Assembly.FullName,
                                                    "Message"), Message)
         msg.Display()                                                                           
      Else
         msg = New Message()
         msg.Display()   
      End If     
   End Sub
End Module

Public Class Message : Inherits MarshalByRefObject
   Public Sub Display()
      Console.WriteLine("Executing in domain {0}",
                        AppDomain.CurrentDomain.FriendlyName)
   End Sub
End Class

Visual Basic Script example

--- ---Set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "SYSTEM" )
' Display the current value
WScript.Echo "TestSystem=" & wshSystemEnv( "TestSystem" )

' Set the environment variable
wshSystemEnv( "TestSystem" ) = "Test System"

' Display the result
WScript.Echo "TestSystem=" & wshSystemEnv( "TestSystem" )
' Delete the environment variable
wshSystemEnv.Remove( "TestSystem" )
' Display the result once more
WScript.Echo "TestSystem=" & wshSystemEnv( "TestSystem" )
Set wshSystemEnv = Nothing
Set wshShell     = Nothing
Does that answer your question?

My question would be, why using batch files while having developing software (in your case VB/VBS) ?

4wd:
I got this "set -ua ..." off the www as a possible answer to my question.-OptimalDesigns (July 17, 2018, 03:28 PM)
--- End quote ---

set -u is used in Linux Bash shells.
set /a is used in Windows CLI to set environment variables using arithmetic expressions. eg. set /a "ABC+=2"

OptimalDesigns:
Set wshShell = CreateObject( "WScript.Shell" )
Set wshSystemEnv = wshShell.Environment( "SYSTEM" )
' Display the current value
WScript.Echo "TestSystem=" & wshSystemEnv( "TestSystem" )
-KodeZwerg (July 17, 2018, 07:43 PM)
--- End quote ---
Close ... I have the following code that may explain my problem.
        Dim oShell As Variant, intResponse As Integer
        Set oShell = CreateObject("WSCript.shell")
---
Your example shows "Set wshShell = " and mine has "Set oShell = ".  So, I made that change but then "Set wshSystemEnv = " produces an error msg. saying that "wshSystemEnv" is not defined.  So, "Dim wshSystemEnv As Variant" line was added but that caused other problems. 

Next, the line 'WScript.Echo "TestSystem=" & wshSystemEnv("TestSystem")
' causes an error abort msg.  It seems that it doesn't like the "WScript.Echo" portion, but not sure what it is trying to point too.  Ideas?

Thanks for the help!  Close ... so close!
Phil

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version