Reputation: 161
If made a installer which requires a little script to restore a database and a user. This is a sqlcmd
script and requires administrator rights.
But I can't get it working in the installer (runascurrentuser
and/or PrivilegesRequired=admin
). If I run it manually as administrator, it does work.
Code:
[Setup]
PrivilegesRequired=admin
[Run]
Filename: "{app}\DBenUser.cmd"; Components: DbenUser; Flags: runascurrentuser; StatusMsg: net 2 moveanduser wordt geinstaleerd even geduld...
I saw somethings about a registry is this the way to go?
Basicly this is little sqlcmd script to restore some db files and create a user.
CD\
Net stop MSSQL$NET2
Net stop Net2ClientSvc
MOVE /Y "C:\Program Files\IQ Soft\Net2_Data.MDF" "C:\Net2 Access Control\Net2_Data.MDF"
MOVE /Y "C:\Program Files\IQ Soft\Net2_Log.LDF" "C:\Net2 Access Control\Net2_Log.LDF"
MOVE /Y "C:\Program Files\IQ Soft\Net2Archive_Data.MDF" "C:\Net2 Access Control\Net2Archive_Data.MDF"
MOVE /Y "C:\Program Files\IQ Soft\Net2Archive_Log.LDF" "C:\Net2 Access Control\Net2Archive_Log.LDF"
MOVE /Y "C:\Program Files\IQ Soft\Net2Events_Data.MDF" "C:\Net2 Access Control\Net2Events_Data.MDF"
MOVE /Y "C:\Program Files\IQ Soft\Net2Events_Log.LDF" "C:\Net2 Access Control\Net2Events_Log.LDF"
Net stop MSSQL$NET2
Net stop Net2ClientSvc
Net start MSSQL$NET2 /m
SQLCMD -S localhost\net2 -Q "CREATE LOGIN b4tmm WITH PASSWORD='b4tmm'"
SQLCMD -S localhost\net2 -Q "SP_ADDSRVROLEMEMBER 'b4tmm', 'SYSADMIN'"
net stop MSSQL$NET2
net start MSSQL$NET2
net start Net2ClientSvc
These are all the things the sqlcmd file uses within innosetup (file is called DBenUser.cmd):
[Types]
Name: "Compleet"; Description: "IQ Soft Compleet"
Name: "Client"; Description: "IQ Soft Client"
[Components]
Name: "DbenUser"; Description: "DbenUser "; Types: Compleet;
[Files]
Filename: "{app}\DBenUser.cmd"; Components: DbenUser; Flags: runascurrentuser; StatusMsg: net 2 moveanduser wordt geinstaleerd even geduld...
[Eddited]
I tested the admin rights by unchecking all my components in innosetup except the sqlcmd script (and running it on a snapshot of vm ware where all the other programs where installed and only needed the script to compleet the installation). If i ran it as the first/only program im my installer it works (so admin rights are ok (also tested this by moving a file to a admin only folder with a cmd script). After that i tested the compleet installation again with all the other components active and it woudn't work. It seems like somehow the installer "loses" its admin rights after all the other components are installed. The cmd gives me the error: SQLCMD is not recognized as an internal or external command, program or batch file
SQLCMD -S localhost\net2 -Q "CREATE LOGIN b4tmm WITH PASSWORD='b4tmm'"
SQLCMD -S localhost\net2 -Q "SP_ADDSRVROLEMEMBER 'b4tmm', 'SYSADMIN'"
(The other components are .net 4,5, Paxton (net2), Sql manager 2012, Sql express 2012, Crystal reports , SQLCMD script in that order)
Anyone has any idea? Im clueless at this point
Additional information
[Files]
Source: "C:\Users\Chris V\Desktop\IQ-Soft\IQ-Soft.exe"; DestDir: "{app}"; Components: IQ_soft;
Source: "C:\Users\Chris V\Desktop\IQ-Soft\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\Chris V\Desktop\IQ-Soft\IQ-Soft Setup.exe"; DestDir: "{app}"; Components: IQ_Database
;----------------------------------------------------------------------------------------------------------------------------------------
Source: "C:\Users\Chris V\Desktop\Net4\dotNetFx45_Full_setup.exe"; DestDir: {tmp};
;----------------------------------------------------------------------------------------------------------------------------------------
;Source: "C:\Users\Chris V\Desktop\crystal reports\crystalreports.msi"; DestDir: {tmp}; Components: CrystalReports
;----------------------------------------------------------------------------------------------------------------------------------------
Source: "C:\Users\Chris V\Desktop\Paxton\SetupPaxton.exe"; DestDir: {tmp}; Components: Paxton;
;----------------------------------------------------------------------------------------------------------------------------------------
;Source: "C:\Users\Chris V\Desktop\Sdk\RedistOEM.msi"; DestDir: {tmp}; Components: Sdk;
;----------------------------------------------------------------------------------------------------------------------------------------
Source: "C:\Users\Chris V\Desktop\Sql expr\SQLEXPR.exe"; DestDir: {tmp}; Components: Sqlexpress;
Source: "C:\Users\Chris V\Desktop\Sql expr\SQLMANG.exe"; DestDir: {tmp}; Components: Sqlman;
;----------------------------------------------------------------------------------------------------------------------------------------
Source: "C:\Users\Chris V\Desktop\Net2\Net2Databaseschoon\*"; DestDir: "{app}"; Components: Net2DB;
;Source: "C:\Users\Chris V\Desktop\Net2\handleiding.odt"; DestDir: "{app}"; Components: Handleiding;
Source: "C:\Users\Chris V\Desktop\Net2\DBenUser.cmd"; DestDir: "{app}"; Components: DbenUser;
[Run]
Filename: {tmp}\dotNetFx45_Full_setup.exe; Parameters: "/q:a /c:""install /l /q"""; StatusMsg: Microsoft Framework 4.5 wordt geinstaleerd even geduld...
;-------------------------------------------------------------------------------------
Filename: {tmp}\SetupPaxton.exe;Components: Paxton; StatusMsg: Paxton wordt geinstaleerd even geduld...
;Filename: {tmp}\RedistOEM.msi;Components: Sdk; Flags: shellexec waituntilterminated; StatusMsg: Sdk wordt geinstaleerd even geduld...
;-------------------------------------------------------------------------------------
Filename: {tmp}\SQLMANG.exe;Components: Sqlman; StatusMsg: SQL Manager wordt geinstaleerd even geduld...
Filename: {tmp}\SQLEXPR.exe;Components: Sqlexpress; StatusMsg: Sql express wordt geinstaleerd even geduld...
;-------------------------------------------------------------------------------------
;Filename: {tmp}\crystalreports.msi;Components: CrystalReports; Flags: shellexec waituntilterminated ; StatusMsg: Crystal reports wordt geinstaleerd even geduld...
;-------------------------------------------------------------------------------------
Filename: "{app}\DBenUser.cmd"; Components: DbenUser; Flags: runascurrentuser; StatusMsg: net 2 moveanduser wordt geinstaleerd even geduld...
Upvotes: 1
Views: 4057
Reputation: 11
In the script, you must include full path to the programs. E.g.
%WINDIR%\SYSTEM32\NET.exe
then it works.
Upvotes: 1
Reputation: 202642
I have tried to create the simplest installer possible that installs a single .cmd
file and runs it:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
OutputDir=.
[Files]
Source: "test.cmd"; DestDir: {app}
[Run]
FileName: "{app}\test.cmd"; StatusMsg: "running cmd"
The test.cmd
is like:
echo a > c:\admintestfile
dir c:\admintestfile
pause
I cannot write to c:\
without Administrator privileges.
As expected, the batch file succeeds, as it is run with Administrator privileges (as long as the installer itself is), as expected:
So there's probably something else, something specific about the batch file, that causes your problems.
Upvotes: 2