Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

PowerShell in an exe

Back to Forum: Tech Off
  • User profile image

    Is it possible to embed powershell into a .net executable that can run a specified powershell script?  It sounds silly when I ask, but here is the scenerio: We have a few applications that run on workstations and unattended on servers that are constantly changing their configuration. They have in-house and 3rd party plugin .dlls that change on a regular basis.  I need the application to update itself and configure itself automatically EVERY time it starts. There is a central configuration and code repository that has the instructions on how to update and what registry, ini, conf, etc to change. And they are all different slightly depending on the user and machine.

    Since these applications don't provide an auto-updating feature, we resorted replacing the .exe with our own that runs a script of limited functionality, pulls the updates configures, and then runs the original .exe which was renamed.  This seems to work pretty well and is the only way to update the .dlls that may be locked by a running app.  The updater.exe has a companion text file. This text file has the sequence of commands so the updater.exe doesn't need to change to create a new configuration.

    The reason this system needs replacing is maintaining the updater.exe to do all the things it needs to is costly and only the person who wrote it knows how to do it.

    So back to the question. Can I package powershell into a .exe so that it can replace our c++ updater?


    Bonus question: Anyone figure out how to intercept the CreateProcess call on the application so I don't have to do all this nonsense? I almost got it working with "image file execution options" but then I either get an infinate loop, or the debugging flag is set to true, which breaks certain apps licensing systems, or they perform slower.

  • User profile image

    Of course you can. Just check the System.Management.Automation assembly. A quick example here 
    You can do what ever is possible with the PS and with much more control than using Process class.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.