I know it’s rare I actually ask a question, but Windows is harassing me, so I could use a little help.
I’ve got a Shell object that I need to execute some commands which contain environmental variables. The first few commands I issue setup the variables, the subsequent commands use those variables. Problem is, each command seems to be executed inside its own environment, even though they’re all executing on the same Shell object. I’ve tried all three execution modes, but it makes no difference. I’ve also tried packing everything into a single Execute statement separated by &, but still no luck.
Is there anything I can do about this? My last resort is to have my app build out a batch file and run that, but I’d rather use that only as a last resort.
Yes, for interactive mode. However, from your original description, I suspect you can execute each command individually and not need the complexity of interactive mode. Use System.EnvironmentVariable to set up the environment and fire away.
Ok, I opted for the batch file. I really need the commands to be part of one session, so mode 0 just won’t work. I began implementing in interactive mode, but I don’t feel confident enough that I can detect the incoming prompt signifying that it is okay to move on.
From the Better-Late-Than-Never department. Permanently setting a Windows environment variable. Code by other people ( I don’t have the brains for this sort of thing). It seems to work.
[code]’ You have to run this as administrator since you are writing to the registry
’ You probably need to check if the key already exists too
’ This survives reboots so you only need to ever run it once
Dim r as new RegistryItem(“HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment”,True)
Dim results as Integer
Dim c as new shell
r = new RegistryItem(“HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment”)
r.value(“MYPATH”) =“C:\MyFolder”
’ This declare by Aaron Ballman
Declare Sub SendMessageTimeoutA Lib “user32” ( hwnd as Integer, _
msg as Integer, wParam as Integer, lParam as CString, _
flags as Integer, timeout as Integer, ByRef retVal as Integer )