Environmental variable are a set of dynamic named value that allows you to open the specified location through running processes (RUN).
This script allow you to add the Environmental variable to the endpoint .
Input Parameters:
- var_name : Enter the name for environmental variable .
- value : Enter the path that needed to be open.
Example:
var_name: “XXX”
value : r"C:\Users\YYY\Downloads"
Note:
Run the script as “Logged in User”.
var_name= "XXX" # enter the name
value=r"C:\Users\YYY\Downloads" #Enter your path
import os
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
with disable_file_system_redirection():
if os.path.exists(value):
print "File exists and is readable"
a=os.popen('setx '+var_name+" "+value).read()
print "The Environmental variable "+ var_name +" has been created successfully"
print a
else:
print "Either file is missing or is not readable"
Output :
20170523-Create_custom_environmental_variable.json (1.59 KB)