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?

<< < (3/4) > >>

f0dder:
Set wshSystemEnv = wshShell.Environment( "SYSTEM" )
--- End quote ---
Do. Not. Do. This.

You'll be setting a system-wide environment variable - this is a bad, bad, bad idea unless you're specifically aiming to do that. Fortunately, at least on modern Windows versions, vbscript isn't allowed to do this, unless you're running it with admin privileges.

If you need to use vbscript instead of a proper language, go for the solution that executes cmd /c "set foo=bar & mainexecutable".

KodeZwerg:
Sorry my fault.

f0dder:
Could you enlighten me why it is bad to set/unset global environment? That it is bad you mentioned, the "because" is missing. Thanks in advance!-KodeZwerg (July 18, 2018, 03:38 PM)
--- End quote ---
Sure thing :)

First, notice that the global environment is persistent. You shouldn't be making persistent changes to the user's system unless that is what the user directly expects. If there's a name clash, you're going to overwrite the user's own setting, and if your program crashes, you leave a garbage environment variable behind.

By using global environment, you get re-entrancy issues - if you launch multiple child processes simultaneously, you risk several children getting the parameters for one of them.

And then there's the issue of admin privileges necessary for setting system environment variables, which makes this unsuitable for a general mechanism.

Finally, you should generally strive to adhere to the principle of least surprise, and keep mutable state as local as possible - since that leads to fewer bugs, and has the bugs that slip past you be easier-to-debug ones.

KodeZwerg:
Wow, you are FAAAAAAAAAAAAAAST. Even faster than my "Save" -> "Modify Message" -> "Save"
At first clicking "Save" most of your statements rushed through my brain so i've removed my Message.

Big thanks for explaining!

OptimalDesigns:
Set wshSystemEnv = wshShell.Environment( "SYSTEM" )
--- End quote ---
Do. Not. Do. This.

If you need to use vbscript instead of a proper language, go for the solution that executes cmd /c "set foo=bar & mainexecutable".
-f0dder (July 18, 2018, 11:13 AM)
--- End quote ---

I'm a little lost here ... so we are back to cmd /c "set foo=bar & mainexecutable"?  What is the '"mainexecutable"?  This -must- be "set" before executing my main batch file.  So, will or should my oShell.run "cmd /C Set tmp = "ABC" do the trick?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version