Environment variable

Mainfunctions

Settingparameters

Environmentalvariablesareequivalenttosomeparameterssetforthesystemoruserapplications.Whatarethespecificfunctions?Ofcourse,itdependsonthespecificenvironmentvariables.Related.Forexample,pathtellsthesystemthatwhenthesystemisrequiredtorunaprogramwithouttellingitthecompletepathoftheprogram,inadditiontosearchingfortheprograminthecurrentdirectory,thesystemshouldalsogotowhichdirectoriestosearch;forexampleintcorvc++,setinclude=path1;path2;istotellthecompilerwheretofind.hfiles;ofcourse,itisnotonlyspecifyingthepath,butalsootherfunctions,suchassetdircmd=/4.ThefunctionofsettinganenvironmentvariableistoWhenyouusethedircommand,youwilladd/4asthedefaultparametertoyourdircommand,justlikeeachofyourcommandsaddsthe/4parameter,whichisactuallyanenvironmentvariablesetforthecommandinterpretercommand.Anditissetfortheinternalcommanddir.

DWORDGetEnvironmentVariable(LPCSTRlpName,LPSTRlpBuffer,DWORDdSize),theparameterlpNameisthenameoftheenvironmentvariableyourequesttoquery,lpBufferreturnsthevalueoftheenvironmentvariableyouspecify,anddSizetellsthisfunctionHowmanybytescanbestoredinlpBuffer.

Whenanalyzingthelocalfailure,thereasonisprobablybecausethedefaultpathintheenvironmentvariableisdeleted.Oncethedefaultpathisset,someDLLorEXEfilesandActivecontrolsarerequiredwhenthecurrentsystemisrunning.Itwillsearchinallthedefaultpathsatthetime.Ifthecorrespondingprogramisfoundinthesedirectories,itwillbeautomaticallyloaded.Ifitisnotfound,itwillreporttheerrormessageofmissingcertainfiles.

Softwaresharing

Manyfriendswillinstalldualsystemsontheircomputers,suchasinstallingWindowsXPontheCdriveandWindows7ontheDdrive.However,somesoftwareisoftenonlyinstalledintheWindowsXPsystem,andcannotbeusednormallyintheWindows7system.Themoretroublesomebuteffectivemethodistoinstallitagain.Whenweunderstandtheuseofenvironmentvariables,wecansolvetheproblemofsoftwaresharingbetweendualsystems.

Systemoperation

WhydoesthesoftwareinstalledinWindowsXPfailtorununderWindows7(exceptforgreensoftware)?Thereasonisthatwheninstallingsoftware,itisoftennecessarytocopytothesystemdirectoryCertainfilescannotberunduetolackofthesefileswhenusinganothersystem.Therefore,wecansolvethisproblembysettingenvironmentvariables.

Commonenvironmentvariables

WINDOWSsystem

%ALLUSERSPROFILE%PartialReturnsthelocationofall"userprofiles".

%APPDATA%PartialReturnsthelocationwheretheapplicationstoresdatabydefault.

%CD%Partiallyreturnsthecurrentdirectorystring.

%CMDCMDLINE%PartiallyreturnstheexactcommandlineusedtostartthecurrentCmd.exe.

%CMDEXTVERSION%Thesystemreturnstheversionnumberofthecurrent"CommandProcessorExtension".

%COMPUTERNAME%systemreturnsthenameofthecomputer.

%COMSPEC%systemreturnstheexactpathofthecommandlineinterpreterexecutableprogram.

%DATE%Thesystemreturnsthecurrentdate.Usethesameformatasthedate/tcommand.GeneratedbyCmd.exe.Formoreinformationaboutthedatecommand,seeDate.

%ERRORLEVEL%Thesystemreturnstheerrorcodeoftheusedcommand.Usuallyanon-zerovalueisusedtoindicateanerror.

%HOMEDRIVE%Thesystemreturnsthedriveletterofthelocalworkstationconnectedtotheuser'shomedirectory.Settingsbasedonthevalueofthehomedirectory.Theuserhomedirectoryisspecifiedin"LocalUsersandGroups".

%HOMEPATH%Thesystemreturnsthefullpathoftheuser'shomedirectory.Settingsbasedonthevalueofthehomedirectory.Theuserhomedirectoryisspecifiedin"LocalUsersandGroups".

%HOMESHARE%Thesystemreturnsthenetworkpathoftheuser'ssharedhomedirectory.Settingsbasedonthevalueofthehomedirectory.Theuserhomedirectoryisspecifiedin"LocalUsersandGroups".

%LOGONSEVER%Partiallyreturnsthenameofthedomaincontrollerverifyingthecurrentloginsession.

%NUMBER_OF_PROCESSORS%SystemSpecifiesthenumberofprocessorsinstalledonthecomputer.

%OS%systemreturnsthenameoftheoperatingsystem.Windows2000displaystheoperatingsystemasWindows_NT.

%PATH%Systemspecifiesthesearchpathforexecutablefiles.

%PATHEXT%systemreturnsalistoffileextensionsconsideredexecutablebytheoperatingsystem.

%PROCESSOR_ARCHITECTURE%SystemReturnsthechiparchitectureoftheprocessor.Value:x86,IA64.

%PROCESSOR_IDENTIFIER%Thesystemreturnstheprocessordescription.

%PROCESSOR_LEVEL%SystemReturnsthemodeloftheprocessorinstalledonthecomputer.

%PROCESSOR_REVISION%SystemReturnsthesystemvariableoftheprocessorrevisionnumber.

%PROMPT%Partiallyreturnsthecommandpromptsettingsofthecurrentinterpreter.GeneratedbyCmd.exe.

The%RANDOM%systemreturnsanydecimalnumberbetween0and32767.GeneratedbyCmd.exe.

%SYSTEMDRIVE%systemreturnsthedrivecontainingtherootdirectoryofWindowsXP(therootdirectoryofthesystem).

%SYSTEMROOT%systemreturnsthelocationoftherootdirectoryofWindowsXP.

%TEMP%and%TMP%SystemandUserReturnsthedefaulttemporarydirectoryusedbytheapplicationsavailabletothecurrentlylogged-inuser.SomeapplicationsrequireTEMP,whileotherapplicationsrequireTMP.

%TIME%Thesystemreturnsthecurrenttime.Usethesameformatasthetime/tcommand.GeneratedbyCmd.exe.Formoreinformationaboutthetimecommand,seeTime.

%USERDOMAIN%Partiallyreturnsthenameofthedomainthatcontainstheuseraccount.

%USERNAME%Partiallyreturnsthenameofthecurrentlylogged-inuser.

%UserProfile%PartialReturnsthelocationofthecurrentuser'sprofile.

%WINDIR%systemreturnsthelocationoftheoperatingsystemdirectory.

Linuxsystem

Theshellenvironmentdependsonthesettingsofmultiplefiles.Whentheshellisinvoked,itreadscommandsfromthetwoinitialfiles./etc/profilecontainssystemvariables,whicharemaintainedbythesystemadministratorandsetlocalsystemvariablesandspecialcommandsbythesystemadministrator.Thestartupinformationfile($HOME/.bash_project)ofordinaryusersismaintainedbyeachuser.Thisfilecanbemodifiedtorealizeanyspecificsysteminitialization.

Onlyreadtheprofilefileundercertaincircumstances,tobeprecisewhentheuserlogsin.Afterrunningtheshellscriptorsubshell,thereisnoneedtoreadtheprofile.Althoughallprofilesareoptional,basicallyallsystemshave/etc/profile.

IfthevariableENVisdefinedandpassedtoIntheenvironment,allbashshellsmustreadandcallthecommandscontainedinthefilespecifiedbythisvariable.Thisfileisusedtodefineallthecharacteristicsofthebashshell,notjustlogintotheshell.Thetypicalnameofthisfileis$HOME/,bashrc.

Whenusing(systemadministrator)tocreateanewuser,.bash_profile,bashrcandotherpublicenvironmentfiletemplateswillbecopiedtothe/etc/skeldirectory.Youcanedittheseinitialsettings,oryoucanaddadditionalfilesinthisdirectory.

Example:

Atypicalsystemprofile(/etc/profile):

PATH=$PATH:/usr/qa/tools/bin

p>

ENV==$HOME/.bashrc

ORACLE_HOME=/dbs/oracle

ORACLE_SID=qadb

ExportPATHENVORACLE_HOMEORCAL_SID

p>

Cat/etc/motd

Atypicaluserprofile(.bashrc)

PATH=$PATH:$HOME/bin

TEAM=uvt1224exportTERM

sttyintr\^C

cal

mesgn

Atypicaluserbashrcfile(.bashrc):

aliasdir=lslf='ls-FC'

PSI='$PWS[!]>'

set-ovi

Alias​​andotherbash-specificdefinitionsshouldbeplacedinthe.bashrcfile(notdefinedin.bash_profile);otherwise,certaincommandswillnotbefound.

Youshouldrememberthedifferencebetweentheprofilefileandthe.bashrcfile:bothprofilesarereadonlyoncewhenthesystemisstarted,and.bashrcisreadwhenthesystemisstartedandeverytimetheshelliscalledPick.

Settingmethod

Inthewindowsoperatingsystem,youcansetthesystemenvironmentvariablesthroughMyComputer->SystemProperties->AdvancedSystemSettings->EnvironmentVariables,butinDoestheenvironmentvariableofthissettinghaveacorrespondingentryintheregistry?Theanswerisyes.In.net,aclassisprovidedtoobtainsystemenvironmentvariablesandtheirvalues.

Environmentvariablesaredividedintotwocategories:uservariablesandsystemvariables.Therearecorrespondingentriesintheregistry.

Thelocationofuservariables:

HKEY_CURRENT_USER\Environment;

Thelocationofsystemvariablesis:\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001

\Control\SessionManager\Environment.

Inaddition,youcanalsoright-clickonmycomputer-advancedsystemsettings-environmentvariables-thereisapathoptioninthesystemvariables-double-clicktoopen-addtheEnglishstatebasedontheoriginalvariablesSemicolon-thenenterthepathname.(Remember,don’tdeletetheoriginalsystemvariables,justseparatethemwithsemicolons,thenaddthem,andaddasemicolonattheend)

Editingmethod

Howtoeditvariables

Viewallcurrentlyavailableenvironmentvariables(=systemvariables+uservariables)

set

Viewanenvironmentvariable,suchasPATH

setPATH

Addenvironmentvariables,suchasxxx=aa

setxxx=aa

Settheenvironmentvariables(suchasxxx)Setthevaluetoempty

setxxx=

Addanewvalue(suchasd:\xxx)afteranenvironmentvariable(suchasPATH)

setPATH=%PATH%;d:\xxx

(Note:Theoperationofenvironmentvariablesbycommandlineinthedoswindowisonlyvalidfortheapplicationofthecurrentwindow)

Related Articles
TOP