TechNet - Только для профессионалов. Специально для Вас. > Форумы > Windows PowerShell > Anyone have an example of running a script as part of the session state or session configuration?
Задайте вопросЗадайте вопрос
 

ВопросAnyone have an example of running a script as part of the session state or session configuration?

  • 30 июня 2009 г. 16:48CodeSlinger Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    I have my own hosting application, with UI and RawUI implemented, that generally works fine and want the runspace to run profiles before I use the pipeline.

    If there is no concept of running them for me I want to load certain scripts and run them myself. I have tried using RunspaceInvoke(myRunspace) with the Profile variable set in the session and that does strange and unatural things that I have been unable to debug or catch [puts up my dialog from within the append call without returning to the mainform_load call].

    I have tried the below code with variations on the path separation characters. As soon as I execute the append statement, my forms dialog comes up and I never actually make it to the 2nd statement which creates the RunspaveInvoke object. My call stack shows me in some werid kind of inner message loop with the last call being System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop.

    mRunspace.RunspaceConfiguration.InitializationScripts.Append(

    new ScriptConfigurationEntry(@"C:\\Users\\[MyUserid]\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1", "Profile script"));
    RunspaceInvoke lRunspaceInvoke = new RunspaceInvoke(mRunspace); 

     

    The MSDN doc is no help as it refers to skin and bone examples that do not use these methods. I would love to know how to use RunspaceInvoke, RunspaceConfiguration, ScriptConfigurationEntry etc. in general but specifically to run some profile scripts. Seems these methods will get me what I want but how to use them is not readily apparent to me or does not work.

    Thanks, Dave
    • ИзмененоCodeSlinger 30 июня 2009 г. 16:49remove extra linefeeds
    •  

Все ответы