I'd like to run a Powershell script on Windows Server 2008. I'd like to check the status of FTPServer and enable it if isn't already enabled. I hope to use dism.exe to do this. Is this possible? I think I need to use a VBScript to start powershell, but I can't seem to get this to work.
I'd like to run a Powershell script on Windows Server 2008. I'd like to check the status of FTPServer and enable it if isn't already enabled. I hope to use dism.exe to do this. Is this possible?
You can try to run your script in an elevated powershell cmd and there shouldn't be any trouble. The custom action that launches the powershell cmd will run as admin if you enable its "Deferred, with no impersonation" execution option.
I think I need to use a VBScript to start powershell, but I can't seem to get this to work.
thanks for the reply. I enabled the "Deferred, with no impersonation" execution option as you suggested. I copied the code in the article. When I try running the script on the target system, with the ps1 file in the same folder, it works fine. When I try running it as part of the installer I get an error. The install logfile says script error -2146827788, Microsoft VBScript runtime error: Variable is undefined: 'WScript' Line 6, Column 1. I have the ps1 script installed in the Temp folder of the target machine. I've tried running the VBScript as an attached Custom Action , and as an Installed Custom Action, with the VBScript in the Temp folder. Same result each time. Any ideas?
As I understood from the article both the vbscript and power shell script should have the same file name and placed in the same folder. Also, if you have copied them as temporary files you should make sure the custom action is placed after the CostFinalize standard action in hte InstallExecuteSequence.
If all above are fine and the script still doesn't work, please send us the VBS and PS1 files along with your AIP to support at advancedinstaller dot com so we can investigate them.
After looking into the VBScript a bit more closer, it seems it is calling a property of a WScript instance which is not supported in Windows Installer.
Here's what you can try, to make the script work with the installer:
When I run a powershell script in the way outlined here, the main thread of the installation does not wait on the script to finish, even though I have selected Synchronous execution, check return code as the Execution Property. Is there a way around this?
This is happening because your custom action launches the powershell script. From the Windows Installer perspective the custom action has finished and was successful. The process is not aware that the custom action actually triggered the powershell script so it will wait for it to complete as well.
To solve this, you should add code to your custom action which should wait for the powershell script to complete.
FOLLOW US
Get the latest news in Application Packaging