Run a batch file from Inno Setup installer with Administrator privileges - admin

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...

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.

In the script, you must include full path to the programs. E.g.
%WINDIR%\SYSTEM32\NET.exe
then it works.

Related

Azure Devops Test Pipeline LNK1107 When Opening vulkan-1.lib on MSVC but Works fine on GCC

Currently have a linker error in an Azure Devops test pipeline:
##[error]lib\static\x64\vulkan-1.lib(0,0): Error LNK1107: invalid or corrupt file: cannot read at 0x82
lib\static\x64\vulkan-1.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x82 [d:\a\1\s\Rhea\Rhea.vcxproj]
Done Building Project "d:\a\1\s\Rhea\Rhea.vcxproj" (default targets) -- FAILED.
This only happens when attempting to build on MSVC on the build machine. GCC on the build machine works fine and local machines using MSVC are able to compile just fine.
This is the testpipeline.yml:
trigger:
- master
strategy:
matrix:
x64-Debug:
configuration: 'debug'
architecture: 'x64'
x64-Release:
configuration: 'release'
architecture: 'x64'
pool:
vmImage: 'windows-2019'
steps:
- checkout: self
submodules: true
- bash: chmod -R 755 ./
displayName: "Elevate Bash"
#Windows
- bash: ./vendor/premake/win/premake5.exe vs2019 --standalone
displayName: "Premake Windows"
condition: eq( variables['Agent.OS'], 'Windows_NT' )
#Compile with visual studio
- task: VSBuild#1
inputs:
solution: 'RheaDev.sln'
configuration: $(configuration)
msbuildArchitecture: $(architecture)
displayName: "Build Project"
Marked with GitLFS and the pipeline wasn't so the files were incorrect.

How to choose linux compiler and simplify this azure-pipeline script?

Setup different compilers for cmake;
Colorize build results.
my current pipeline script for linux ('Hosted Ubuntu 1604'):
steps:
- script: 'cp CMakeLists.txt build/'
displayName: 'cp cmakelist'
- script: 'export CC=/usr/local/bin/gcc-7'
displayName: 'set gcc version'
- script: 'export CXX=/usr/local/bin/g++-7'
displayName: 'set g++ version'
- script: 'cmake CMakeLists.txt'
displayName: 'cmake'
- script: 'make AllTest'
displayName: 'Build AllTest'
- script: 'cd lib/all_test'
displayName: 'set all test directory'
- script: './AllTest'
workingDirectory: lib/all_test/
displayName: 'run AllTest'
My problems:
CMake#1 works well in windows, but this command expect the cMakeLists.txt in the build directory
I've listed the available compilers and gcc 7 is available, but even I tried to setup to use it, the cmake uses gcc 5.4, how can I select different compilers e.g gcc 7, clang (in windows I use cmake -G Visual Studio...
I use a standalone test library (rili tests/ c++) , and on the azure servers the test results has no color, how can I colorize my test results?

Create FreeXL rpm for CentOS 7: spec file?

I'm trying to build a spec file to create rpm for FreeXL con CentOS 7.
If I try to execute these steps manually
tar xzf freexl-1.0.2.tar.gz
cd freexl-1.0.2
export MAKEFLAGS='-j2'
./configure --prefix=/usr/local && make && make install
all works fine I can see under /usr/local/..... the files aboout FreeXL.
I've tried to "translate" these steps in a spec file ... here you are it
#
# spec file for package freexl
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
%define libname lib%{name}1
Name: freexl
Version: 1.0.2
Release: 1.my
Summary: Library to extract valid data from within an Excel
License: MPL-1.1 or GPL-2.0+ or LGPL-2.1+
Group: Development/Libraries/C and C++
Url: https://www.gaia-gis.it/fossil/freexl/index
Source: http://www.gaia-gis.it/gaia-sins/%{name}-%{version}.tar.gz
BuildRequires: gcc-c++
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
FreeXL is an open source library to extract valid data from within an Excel (.xls) spreadsheet.
%package -n %{libname}
Summary: Shared library for FreeXL
Group: System/Libraries
%description -n %{libname}
FreeXL is an open source library to extract valid data from within an Excel (.xls) spreadsheet.
%package devel
Summary: Development files for %{name}
Group: Development/Libraries/C and C++
Requires: %{libname} = %{version}
Requires: glibc-devel
%description devel
This package contains all necessary include files and libraries needed
to compile and develop applications that use libspatialite.
#redefine path ...
%define _bindir /usr/local
%prep
%setup -q
%build
%configure
%install
./configure --prefix=%_bindir && make && make install
%changelog
I obtain my freexl-debuginfo-1.0.2-1.csi.x86_64.rpm file but when I try to install it nothing is installed (and no errors are shown during installation ....
I think that probably there are some errors in my spec file ...... any suggestions / examples?
I've solved: the problem was that my spec file was not complete ....
Here you're a correct spec file that works fine ....
https://build.opensuse.org/package/view_file/openSUSE:Factory/freexl/freexl.spec?expand=1
It works for CentOS 7 too!

Jenkins Build failed after restarting Tomcat

I set up an ant project and successfully built a project.
Started by user anonymous
Building in workspace /home/myusername/jenkins/workspace/ctascweb
[ctascweb] $ cvs -q -z3 update -PdC -r ctascweb-development-3_3_8 -D "Wednesday, November 28, 2012 10:20:13 PM UTC"
? ROOT.war
? build
U src/stdy/analyze/LoadSubjects.java
$ computing changelog
[ctascweb] $ ant -file build_hudson.xml
Buildfile: build_hudson.xml
init:
[echo] Base Directory : /home/myusername/jenkins/workspace/ctascweb
gen-footer:
compile-ctpm:
[echo] Compiling ctpm files
[javac] Compiling 1 source file to /home/myusername/jenkins/workspace/ctpm/bin
generate-ctpm-jar:
[echo] Building CTPM jar file
[jar] Building jar: /home/myusername/jenkins/workspace/ctpm/build/ctpm.jar
compile-ctascweb:
[echo] Compiling ctascweb files
[javac] Compiling 1 source file to /home/myusername/jenkins/workspace/ctascweb/build/classes
[mkdir] Created dir: /home/myusername/jenkins/workspace/ctascweb/build/classes/resource
build-ctascweb-war:
[echo] Building WAR file for ctascweb
[war] Building war: /home/myusername/jenkins/workspace/ctascweb/ROOT.war
[echo] Nov-28-2012 05:20:48
BUILD SUCCESSFUL
Total time: 7 seconds
Archiving artifacts
Finished: SUCCESS
I shut down my Tomcat and came back next work. I did not make any changes in my configuration and started the build again and the build failed.
Started by user anonymous
Building in workspace /home/myusername/jenkins/jobs/ctascweb/workspace
[ctascweb] $ cvs -Q -z3 -d :pserver:myusername:pwd#5.0.0.146:/CVS_RESP01 co -P -r ctascweb-development-3_3_8 -d workspace -D "Thursday, November 29, 2012 2:41:16 PM UTC" ctascweb
$ computing changelog
[workspace] $ ant -file build_hudson.xml
Buildfile: build_hudson.xml
init:
[mkdir] Created dir: /home/myusername/jenkins/jobs/ctascweb/workspace/build/classes
[echo] Base Directory : /home/myusername/jenkins/jobs/ctascweb/workspace
gen-footer:
BUILD FAILED
java.io.FileNotFoundException: /home/myusername/jenkins/jobs/ctascweb/ctpm/src/com/ctasc/ctpm/layout/StdyFooter.java (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
at java.io.FileWriter.<init>(FileWriter.java:61)
at org.apache.tools.ant.taskdefs.Echo.execute(Echo.java:67)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Total time: 0 seconds
Build step 'Invoke Ant' marked build as failure
Archiving artifacts
Finished: FAILURE
For some reason, the worspace changed from /home/myusername/jenkins/workspace/ctascweb to
/home/myusername/jenkins/jobs/ctascweb/workspace. Why would that happen? The only thing I did is stopped and restarted the Tomcat server?
Are you the admin of the Hudson/Jenkins server?
If the version was recently updated (in particular from Hudson to Jenkins), there is a difference in the path that's used for project's workspace (which can be changed in configuration). You should always use ${WORKSPACE} variable instead of directly referencing any path
Also, these lines look different, so there was more than just Tomcat restart
[ctascweb] $ cvs -q -z3 update -PdC -r ctascweb-development-3_3_8 -D "Wednesday, November 28, 2012 10:20:13 PM UTC"
[ctascweb] $ cvs -Q -z3 -d :pserver:myusername:pwd#5.0.0.146:/CVS_RESP01 co -P -r ctascweb-development-3_3_8 -d workspace -D "Thursday, November 29, 2012 2:41:16 PM UTC" ctascweb
Look for any changes in configuration of job from UI. Goto Advanced options and see if someone has unchecked your custom workspace as seems to be the case.
Also can I get to see your build_hudson.xml. There may be some issues with the way you used path in the build file.
Yes the Jenkins workspace folder is changing based on the way we run it. I had seen this in windows XP on my machine.
When I run the JAR file using java -jar jenkins.war
It is .jenkins/workspace/<job_name>
When I installed it as a windows service, the workspace folder changed to .jenkins/<job_name>/workspace

Inno Setup Uninstall

This is my situation, something like this:
I have three files: file1.txt, file2.txt, and file3.exe
I want to put three of them into a Directory in C:\Program Files, run file3.exe and create an uninstaller to uninstall everything with double-click on it.
when I make a double-click on uninstaller, the file3.exe will be uninstalled and all files will be removed from that Directory.
I've just done the first step, how can I do to get second step?
Thanks in advanced!
This is a good solution here
or I used this one: create an exe that can create a batch file which will uninstall the app and delete itself
you can use following code snippet of inno setup ,
[Files]
Source: "file3.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "file1.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "file2.txt"; DestDir: "{app}"; Flags: ignoreversion
[Run]
Filename: "{app}\file3.exe"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent