Is it possible to set a one time environment variable for an application?

#1
First of all, here is how I got here. I migrated from Microsoft Community because they now tell me to verify using a phone number which I don't have. So, I searched 'windows forums' and found this, so I will be using this website for all my Windows needs from now on.

Anyways, now to my question. I have heard that changing some environment variables around helps some applications work. I wanted to try Android Studio Portable in school, but I ran across an error saying I need to provide an environment variable for JDK which I already have), but I don't have access to those. I knew I needed to change environment variables in order for it to work before, but I can't do it as I want to try it in school. So, is it possible to define a custom, one-time variable to only Android Studio Portable without the need for actually changing it in the Control Panel? Also, I am referring to a way which does not require admin access, because I have none in school. If such a feature doesn't exist, maybe someone can invent one that sets a one-time variable to Android Studio Portable?

Just to let you know, I am posting this from Windows 10 Home at home, but I want to try it on Windows 7 Enterprise at school.
 


Neemobeer

Windows Forum Team
Staff member
#2
Yes you can temporarily change them. Create a batch file (.bat)

SET VARIABLENAME=VALUE
START processname, it should be set to the new value for that instances
 


#3
Yes you can temporarily change them. Create a batch file (.bat)

SET VARIABLENAME=VALUE
START processname, it should be set to the new value for that instances
Can't wait to try it out. But does it work on school computers? I am eager to try it out in school, but I am not allowed to change variables (can access bat files though). And can you please provide an example of this, I am unsure what to do with the basic information you have given me.
 


Neemobeer

Windows Forum Team
Staff member
#4
As long as you can open a command prompt and run a batch file then yes it should work.
 


ussnorway

Windows Forum Team
Staff member
Premium Supporter
#5
in most senarios a school system will dump any temp data once you sign out at the end of class so you will need to re-run this batch at the start of each new class
 


Neemobeer

Windows Forum Team
Staff member
#6
A variable set in this fashion will only exist as in the command prompt where it's set. If you open another command prompt it will have the old variable in it.
 


#7
As long as you can open a command prompt and run a batch file then yes it should work.
Well yeah, its blocked (AT SCHOOL BUT NOT AT HOME) but I have a batch file which allows me to enter commands. Will this work when I am in school? (I have uploaded it as a text file so you can see if it can work with this)
 


Attachments

#8
in most senarios a school system will dump any temp data once you sign out at the end of class so you will need to re-run this batch at the start of each new class
I don't know ... maybe I can try to see if it works using my (otherwise) made up CMD, which maybe might not work anyways. See the attached file for my reply to Neemobeer for the file.
 


#9
A variable set in this fashion will only exist as in the command prompt where it's set. If you open another command prompt it will have the old variable in it.
Command prompt is blocked at school. But maybe my own batch file could work to replace CMD.
 


Neemobeer

Windows Forum Team
Staff member
#10
No batch files execute from conhost which launches cmd.exe
 


ussnorway

Windows Forum Team
Staff member
Premium Supporter
#11
does the school allow v-systems like vmware or hyper-v... you can use them to get a cmd prompt
 


#12
Ok, new question. Can I set a one-time variable to run an application in Powershell? For my COMMAND batch script, it does (appear to) set an environment variable, but when I call the .exe from the window, it doesn't work.
 


Neemobeer

Windows Forum Team
Staff member
#13
Yes, if you need to change an existing variable you can see what you have available by typing

Get-ChildItem ENV:

and set a variable with
In the example I'm setting the existing environment variable TEMP to hello
Set-Item ENV:\TEMP -Value "Hello"

In this example I'm just creating a new variable called T
Set-Item Env:\T -Value "Hello"

You can then run a program with
Start-Process pathtoprocess\process.exe
 


#14
So what if you need the value to be a path? The path?
 


Neemobeer

Windows Forum Team
Staff member
#15
Yes
 


This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.
Top