2012-12-05 89 views
1

新手問題:我想在INNO-安裝程序安裝結束時運行PowerShell腳本(名爲.ps1)。任何人都可以給我一個提示放在哪裏?我希望提示用戶詢問他是否要運行此腳本。PowerShell腳本之後安裝

哦,是的,這是什麼腳本並運行netsh.exe中打開一個端口,劇本是聰明的,它抓住ENV:從當前上下文USERDOMAIN:用戶名和Env。上下文是運行安裝程序的管理員?或者它會是運行setup.exe的原始用戶?

回答

2
[Run] 
.....; Description: Run Script; Flags: postinstall 

(詳情參見幫助。)默認情況下,這將顯示一個複選框和原始用戶的上下文中運行(儘管它取決於如何安裝程序運行位)。

你可能要重新考慮這種做法,雖然;如果您正在執行機器範圍的安裝,那麼您應該也可以在機器範圍內打開端口。你可以用純Inno代碼調用WinAPI來做到這一點 - 不需要PowerShell。 (這是一件好事,因爲它可能未安裝。)

另外,如果你想保持它的每個用戶設置,你應該考慮讓你的應用程序提示在第一次運行的決定的用戶。畢竟,爲什麼只給你的應用程序的許多可能的用戶中的一個選項?

+0

一個非常好的問題。但在這種情況下,我們的用戶喜歡限制誰可以爲單個用戶開放端口的安全性。我注意到InstallShield已經允許PowerShell腳本作爲設置的一部分。 INHO:如果inno setup刪除了Pascal,並且使用集成的PowerShell for vista,win7和up安裝,那將會很棒。 –

+0

那麼,你可以自由地建議在官方Inno建議網站上。但我懷疑它會得到很多牽引力,因爲Inno本身就是用Pascal編寫的。 – Miral

2

另一種方法是使用運行從代碼中ShellExec腳本。

[Files] 
Source: "yourPowershell.ps1"; DestDir: "{app}"; Flags: overwritereadonly replacesameversion promptifolder; 

[Tasks] 
Name: "runpowershell"; Description: "Do you want to run Powershell script?" 

[Code] 

procedure CurStepChanged(CurStep: TSetupStep); 
var 
    ErrorCode: Integer; 
    ReturnCode: Boolean; 
begin 
    if CurStep = ssPostInstall then begin 

    if(IsTaskSelected('runpowershell')) then begin 
     ExtractTemporaryFile('yourPowershell.ps1'); 
     ReturnCode := ShellExec('open', '"PowerShell"', ExpandConstant(' -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File "{tmp}\YourPowershell.ps1"'), '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode); 

    if (ReturnCode = False) then 
     MsgBox('Message about problem. Error code: ' + IntToStr(ErrorCode) + ' ' + SysErrorMessage(ErrorCode), mbInformation, MB_OK); 

    end; 
end;