Ejemplo n.º 1
0
 internal void InitializeFixedVariables()
 {
     PSVariable variable = new PSVariable("Host", this._context.EngineHostInterface, ScopedItemOptions.AllScope | ScopedItemOptions.Constant, RunspaceInit.PSHostDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     string environmentVariable = Environment.GetEnvironmentVariable("HomeDrive");
     string str2 = Environment.GetEnvironmentVariable("HomePath");
     string str3 = environmentVariable + str2;
     variable = new PSVariable("HOME", str3, ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly, RunspaceInit.HOMEDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     variable = new PSVariable("ExecutionContext", this._context.EngineIntrinsics, ScopedItemOptions.AllScope | ScopedItemOptions.Constant, RunspaceInit.ExecutionContextDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     variable = new PSVariable("PSVersionTable", PSVersionInfo.GetPSVersionTable(), ScopedItemOptions.AllScope | ScopedItemOptions.Constant, RunspaceInit.PSVersionTableDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     Process currentProcess = Process.GetCurrentProcess();
     variable = new PSVariable("PID", currentProcess.Id, ScopedItemOptions.AllScope | ScopedItemOptions.Constant, RunspaceInit.PIDDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     variable = new PSCultureVariable();
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     variable = new PSUICultureVariable();
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     string shellID = this._context.ShellID;
     variable = new PSVariable("ShellId", shellID, ScopedItemOptions.AllScope | ScopedItemOptions.Constant, RunspaceInit.MshShellIdDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     string applicationBase = "";
     try
     {
         applicationBase = Utils.GetApplicationBase(shellID);
     }
     catch (SecurityException)
     {
     }
     variable = new PSVariable("PSHOME", applicationBase, ScopedItemOptions.AllScope | ScopedItemOptions.Constant, RunspaceInit.PSHOMEDescription);
     this.GlobalScope.SetVariable(variable.Name, variable, false, true, this, CommandOrigin.Internal, true);
     this.SetConsoleVariable();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Add the variables that must always be present in a SessionState instance...
        /// </summary>
        internal void InitializeFixedVariables()
        {
            //
            // BUGBUG
            //
            // String resources for aliases are currently associated with Runspace init
            //

            // $Host
            PSVariable v = new PSVariable(
                SpecialVariables.Host,
                ExecutionContext.EngineHostInterface,
                ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                RunspaceInit.PSHostDescription);

            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $HOME - indicate where a user's home directory is located in the file system.
            //    -- %USERPROFILE% on windows
            //    -- %HOME% on unix
            string home = Environment.GetEnvironmentVariable(Platform.CommonEnvVariableNames.Home) ?? string.Empty;

            v = new PSVariable(SpecialVariables.Home,
                               home,
                               ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope,
                               RunspaceInit.HOMEDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $ExecutionContext
            v = new PSVariable(SpecialVariables.ExecutionContext,
                               ExecutionContext.EngineIntrinsics,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.ExecutionContextDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $PSVersionTable
            v = new PSVariable(SpecialVariables.PSVersionTable,
                               PSVersionInfo.GetPSVersionTable(),
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.PSVersionTableDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $PSEdition
            v = new PSVariable(SpecialVariables.PSEdition,
                               PSVersionInfo.PSEditionValue,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.PSEditionDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $PID
            Process currentProcess = Process.GetCurrentProcess();

            v = new PSVariable(
                SpecialVariables.PID,
                currentProcess.Id,
                ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                RunspaceInit.PIDDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $PSCulture
            v = new PSCultureVariable();
            this.GlobalScope.SetVariableForce(v, this);

            // $PSUICulture
            v = new PSUICultureVariable();
            this.GlobalScope.SetVariableForce(v, this);

            // $?
            v = new QuestionMarkVariable(this.ExecutionContext);
            this.GlobalScope.SetVariableForce(v, this);

            // $ShellId - if there is no runspace config, use the default string
            string shellId = ExecutionContext.ShellID;

            v = new PSVariable(SpecialVariables.ShellId, shellId,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.MshShellIdDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $PSHOME
            string applicationBase = Utils.DefaultPowerShellAppBase;

            v = new PSVariable(SpecialVariables.PSHome, applicationBase,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.PSHOMEDescription);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);

            // $EnabledExperimentalFeatures
            v = new PSVariable(SpecialVariables.EnabledExperimentalFeatures,
                               ExperimentalFeature.EnabledExperimentalFeatureNames,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.EnabledExperimentalFeatures);
            this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add the variables that must always be present in a SessionState instance...
        /// </summary>
        internal void InitializeFixedVariables()
        {
            //
            // BUGBUG
            //
            // String resources for aliases are currently associated with Runspace init 
            //

            // $Host
            PSVariable v = new PSVariable(
                    SpecialVariables.Host,
                    ExecutionContext.EngineHostInterface,
                    ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.PSHostDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $HOME - indicate where a user's home directory is located in the file system.
            //    -- %USERPROFILE% on windows
            //    -- %HOME% on unix
            string home = Environment.GetEnvironmentVariable(Platform.CommonEnvVariableNames.Home) ?? string.Empty;
            v = new PSVariable(SpecialVariables.Home,
                    home,
                    ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope,
                    RunspaceInit.HOMEDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $ExecutionContext
            v = new PSVariable(SpecialVariables.ExecutionContext,
                    ExecutionContext.EngineIntrinsics,
                    ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.ExecutionContextDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSVersionTable
            v = new PSVariable(SpecialVariables.PSVersionTable,
                    PSVersionInfo.GetPSVersionTable(),
                    ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.PSVersionTableDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSEdition
            v = new PSVariable(SpecialVariables.PSEdition,
                    PSVersionInfo.PSEditionValue,
                    ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.PSEditionDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PID
            Process currentProcess = Process.GetCurrentProcess();
            v = new PSVariable(
                    SpecialVariables.PID,
                    currentProcess.Id,
                    ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.PIDDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSCulture
            v = new PSCultureVariable();
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSUICulture
            v = new PSUICultureVariable();
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $ShellId - if there is no runspace config, use the default string
            string shellId = ExecutionContext.ShellID;

            v = new PSVariable(SpecialVariables.ShellId, shellId,
                   ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.MshShellIdDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSHOME
            // This depends on the shellId. If we cannot read the application base
            // registry key, set the variable to empty string
            string applicationBase = "";
            try
            {
                applicationBase = Utils.GetApplicationBase(shellId);
            }
            catch (SecurityException)
            {
            }
            v = new PSVariable(SpecialVariables.PSHome, applicationBase,
                    ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                    RunspaceInit.PSHOMEDescription);

            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $Console - set the console file for this shell, if there is one, "" otherwise...
            SetConsoleVariable();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add the variables that must always be present in a SessionState instance...
        /// </summary>
        internal void InitializeFixedVariables()
        {
            //
            // BUGBUG
            //
            // String resources for aliases are currently associated with Runspace init
            //

            // $Host
            PSVariable v = new PSVariable(
                SpecialVariables.Host,
                ExecutionContext.EngineHostInterface,
                ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                RunspaceInit.PSHostDescription);

            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $HOME - indicate where a user's home directory is located in the file system.
            //    -- %USERPROFILE% on windows
            //    -- %HOME% on unix
            string home = Environment.GetEnvironmentVariable(Platform.CommonEnvVariableNames.Home) ?? string.Empty;

            v = new PSVariable(SpecialVariables.Home,
                               home,
                               ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope,
                               RunspaceInit.HOMEDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $ExecutionContext
            v = new PSVariable(SpecialVariables.ExecutionContext,
                               ExecutionContext.EngineIntrinsics,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.ExecutionContextDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSVersionTable
            v = new PSVariable(SpecialVariables.PSVersionTable,
                               PSVersionInfo.GetPSVersionTable(),
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.PSVersionTableDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSEdition
            v = new PSVariable(SpecialVariables.PSEdition,
                               PSVersionInfo.PSEditionValue,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.PSEditionDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PID
            Process currentProcess = Process.GetCurrentProcess();

            v = new PSVariable(
                SpecialVariables.PID,
                currentProcess.Id,
                ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                RunspaceInit.PIDDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSCulture
            v = new PSCultureVariable();
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSUICulture
            v = new PSUICultureVariable();
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $ShellId - if there is no runspace config, use the default string
            string shellId = ExecutionContext.ShellID;

            v = new PSVariable(SpecialVariables.ShellId, shellId,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.MshShellIdDescription);
            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $PSHOME
            // This depends on the shellId. If we cannot read the application base
            // registry key, set the variable to empty string
            string applicationBase = "";

            try
            {
                applicationBase = Utils.GetApplicationBase(shellId);
            }
            catch (SecurityException)
            {
            }
            v = new PSVariable(SpecialVariables.PSHome, applicationBase,
                               ScopedItemOptions.Constant | ScopedItemOptions.AllScope,
                               RunspaceInit.PSHOMEDescription);

            this.GlobalScope.SetVariable(v.Name, v, false, true, this, CommandOrigin.Internal, fastPath: true);

            // $Console - set the console file for this shell, if there is one, "" otherwise...
            SetConsoleVariable();
        }