Windows silent installation with file parameter - powershell

I'm trying to make a silent installation through a Windows Batch script with a file parameter, but I'm not being able to do it.
I have a file (params.txt) which contains the parameters that should be input during the installation (such as path, choices etc).
Obs.: It may also be by PowerShell.
I have something similar in Linux, which is pretty easy:
.../installer.sh < .../params.txt
But I'm trying in many different ways, with NSIS, MSI. But none of them seens to solve my problem with these parameters.
The closest that I've got was
C:\installer.exe /S
indeed its make the installation with the default parameters, but I would like to specify them through my file.
I've made many researches, even here in stackoverflow, but nothing that solves my problem.
Content of my params.txt file:
yes
no
C:\Software\MySoftware
yes
no
no
no
The installation prompts a few questions, and the file contains the answers that I need to give during the installation.
Also, the installer was generated using NSIS (Nullsoft Scriptable Install System) .
Thank you in advance.

NSIS supports the /S and /D=c:\installpath parameters by default, support for anything else has to be provided by the install author.
Install authors can check for specific parameters and/or a answer file:
!include FileFunc.nsh
!include LogicLib.nsh
Section
; Command-line parameter:
${GetParameters} $0
ClearErrors
${GetOptions} $0 "/Something" $1
${IfNot} ${Errors}
; Do Something
${Else}
; Do something else?
${EndIf}
; Answer .INI file:
Var /Global AnswerFile
StrCpy $AnswerFile $ExePath -4
StrCpy $AnswerFile "$AnswerFile.ini"
ReadIniStr $0 $AnswerFile "Options" "OtherPath"
${If} $0 != ""
File "/oname=$0\file.ext" "c:\mysource\fileForOtherPath.ext"
${EndIf}
SectionEnd

Related

checking to see if files are executable perl

I have a program that checks to see if the files in my directory are readable,writeable, and executable.
i have it set up so it looks like
if (-e $file){
print "exists";
}
if (-x $file){
print "executable";
}
and so on
but my issue is when I run it it shows that the text files are executable too. Plain text files with 1 word in them. I feel like there is an error. What did I do wrong. I am a complete perl noob so forgive me.
It is quite possible for a text file to be executable. It might not be particularly useful in many cases, but it's certainly possible.
In Unix (and your Mac is running a Unix-like operating system) the "executable" setting is just a flag that is set in the directory entry for a file. That flag can be set on or off for any file.
There are actually three of these permissions why record if you can read, write or execute a file. You can see these permissions by using the ls -l command in a terminal window (see man ls for more details of what various ls options mean). There are probably ways to view these permissions in the Finder too (perhaps a "properties" menu item or something like that - I don't have a Mac handy to check).
You can change these permissions with the chmod ("change mode") command. See man chmod for details.
For more information about Unix file modes, see this Wikipedia article.
But whether or not a file is executable has nothing at all to do with its contents.
The statement if (-x $file) does not check wether a file is an executable but if your user has execution priveleges on it.
For checking if a file is executable or not, I'm affraid there isn't a magic method for it. You may try to use:
if (-T $file) for checking if the file has an ASCII or UTF-8 enconding.
if (-B $file) for checking if the file is binary.
If this is unsuitable for your case, consider the following:
Assuming you are on a Linux enviroment, note that every file can be executed. The question here is: The execution of e.g.: test.txt, is going to throw a standard error (STDERR)?
Most likely, it will.
If test.txt file contains:
Some text
And you launched it in your Perl script by: system("./test.txt"); This will display a STDERR like:
./test.txt: line 1: Some: command not found
If for some reason you are looking to run all the files of your directory (in a for loop for instance) be warned that this is pretty dangerous, since you will launch all your files and you may not be willing to do so. Specially if the perl script is in the same directory that you are checking (this will lead to undesirable script behaviour).
Hope it helps ;)

Current working directory for SXPG_COMMAND_EXECUTE?

Is there a way to specify the current working directory for the system command executed by the function module SXPG_COMMAND_EXECUTE?
I do not see any parameter which would allow me to do that either by defining the command in transaction SM69 or on the list of IMPORTING parameters in SE37.
It looks like by default such commands are started in DIR_HOME which can be viewed by the transaction AL11. Do I have any control over that?
There isn't a way of doing it via `SM69' unfortunately. I think the only solution is to create a script and call that.
I was going to suggest wrapping the statements in a SM69 command defined as a call to sh with parameters of -c 'cd <dir> && /path/to/command' but unfortunately that doesn't work. According to note 401095 wildcards are not permitted. When I tested, && was translated into a single &, causing the command to fail.
Would be good if you access this information using FM FILE_GET_NAME_USING_PATH (export the script name for which you want to find the physical directory).
The recieving path can be used in SXPG_COMMAND_EXECUTE.
Because the external commands I called were actually .bat files I solved this by putting the following expression at the beginning of each and every one.
cd /d %~dp0
This Stackoverflow question helped a lot actually.

Git Bash shell fails to create symbolic links

When I try to create a symbolic link from the Git Bash shell, it fails every time all the time:
ln -s /c/Users/bzisad0/Work testlink
Output:
ln: creating symbolic link `testlink' to `/c/Users/bzisad0/Work': Permission denied
The only thing it does, besides giving the error message, is create an empty directory named (in this case) testlink.
I don't see any problem with the ln executable. For instance, it is owned by me and marked as executable:
which ln
ls -hal /bin/ln
Output:
/bin/ln
-rwxr-xr-x 1 BZISAD0 Administ 71k Sep 5 11:55 /bin/ln
I also own the current directory (~, which is /c/Users/bzisad0):
ls -dhal .
Output:
drwxr-xr-x 115 BZISAD0 Administ 40k Sep 5 12:23 .
I have administrative rights, and I've tried opening the Git Bash shell with "Run as Administrator", but that makes no difference.
I've tried opening the Windows properties for ln.exe and setting the Privilege Level to "Run this program as an administrator" but that doesn't help.
I've gone into the Security → Advanced properties in Windows and made myself (rather than the Administrators group) the owner, but that doesn't fix anything either.
I'm at a loss. I don't know whether this error message is ultimately coming from ln, from Bash, or from Windows, or how I could possibly lack the permission. How can I get to the bottom of this?
It is possible, albeit extremely awkward, to create a symbolic link in MSysGit.
First, we need to make sure we are on Windows. Here's an example function to check that:
windows() { [[ -n "$WINDIR" ]]; }
Now, we can't do cmd /C, because MSysGit will fornicate with this argument and turn it into C:. Also, don't be tempted to use /K; it only works if you don't have a K: drive.
So while it will replace this value on program arguments, it won't on heredocs. We can use this to our advantage:
if windows; then
cmd <<< "mklink /D \"${link%/}\" \"${target%/}\"" > /dev/null
else
ln -s "$target" "$link"
fi
Also: note that I included /D because I'm interested in directory symlinks only; Windows has that distinction. With plenty of effort, you could write a ln() { ... } function that wraps the Windows API and serves as a complete drop-in solution, but that's... left as an exercise for the reader.
As a thank-you for the accepted answer, here's a more comprehensive function.
# We still need this.
windows() { [[ -n "$WINDIR" ]]; }
# Cross-platform symlink function. With one parameter, it will check
# whether the parameter is a symlink. With two parameters, it will create
# a symlink to a file or directory, with syntax: link $linkname $target
link() {
if [[ -z "$2" ]]; then
# Link-checking mode.
if windows; then
fsutil reparsepoint query "$1" > /dev/null
else
[[ -h "$1" ]]
fi
else
# Link-creation mode.
if windows; then
# Windows needs to be told if it's a directory or not. Infer that.
# Also: note that we convert `/` to `\`. In this case it's necessary.
if [[ -d "$2" ]]; then
cmd <<< "mklink /D \"$1\" \"${2//\//\\}\"" > /dev/null
else
cmd <<< "mklink \"$1\" \"${2//\//\\}\"" > /dev/null
fi
else
# You know what? I think ln's parameters are backwards.
ln -s "$2" "$1"
fi
fi
}
Also note a few things:
I just wrote this and briefly tested it on Windows 7 and Ubuntu, give it a try first if you're from 2015 and using Windows 9.
NTFS has reparse points and junction points. I chose reparse points, because it's more of an actual symbolic link and works for files or directories, but junction points would have the benefit of being an usable solution in Windows XP, except it's just for directories.
Some filesystems, the FAT ones in particular, do not support symbolic links. Modern Windows versions do not support booting from them anymore, but Windows and Linux can mount them.
Bonus function: remove a link.
# Remove a link, cross-platform.
rmlink() {
if windows; then
# Again, Windows needs to be told if it's a file or directory.
if [[ -d "$1" ]]; then
rmdir "$1";
else
rm "$1"
fi
else
rm "$1"
fi
}
For my setup, that is Git for Windows 2.11.0 installed on Windows 8.1, export MSYS=winsymlinks:nativestrict does the trick as
The Git Bash shell may need to be run as an administrator, as by default on Windows only administrators can create the symbolic links.
So, in order to make tar -xf work and create the required symbolic links:
Run Git Bash shell as an administrator
Run export MSYS=winsymlinks:nativestrict
Run tar
A workaround is to run mklink from Bash. This also allows you to create either a symbolic link or a junction point.
Take care to send the mklink command as a single argument to cmd...
cmd /c "mklink link target"
Here are the options for mklink...
cmd /c mklink
Output:
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
If you want to create links via a GUI instead ... I recommend Link Shell Extension that is a Windows Explorer plugin for creating symbolic links, hard links, junction points, and volume mount points. I've been using it for years!
Link Shell Extension
Symbolic links can be a life saver if you have a smaller SSD drive on your system C: drive and need to symbolic link some bloated folders that don't need to be on SSD, but off onto other drives. I use the free WinDirStat to find the disk space hogs.
I believe that the ln that shipped with MSysGit simply tries to copy its arguments, rather than fiddle with links. This is because links only work (sort of) on NTFS filesystems, and the MSYS team didn't want to reimplement ln.
See, for example, http://mingw.5.n7.nabble.com/symbolic-link-to-My-Documents-in-MSYS-td28492.html
Do
Grant yourself privileges to create symbolic links.
Search for local security policies
Local Policies/User Rights Assignment/Create symbolic links
Take a moment to scold Windows. "Bad OS! Bad!"
Profit
This grants you the privilege to create symbolic links. Note, this takes effect on the next login.
The next step is to figure out how ln is configured:
env | grep MSYS
We are looking for MSYS=winsymlink: which controls how ln creates symbolic links.
If the variable doesn't exist, create it. Note, this will overwrite the existing MSYS environment variable.
setx MSYS winsymlinks:nativestrict
Do not
Run your shell as an administrator just to create symbolic links.
Explanation
The error is somewhat self-explanatory, yet elusive.
You lack the appropriate privileges to run the command.
Why?
Be default, Windows only grants symlink creation rights to Administrators.
Cygwin has to do a song and dance to get around Windows subpar treatment of symbolic links.
Why?
Something, something "security"
¯\_(ツ)_/¯
Edit:
I just realized OP had admin rights. I leave this answer up, hoping it's useful to others.
Extending Camilo Martin's answer as you need to use the /j parameter switch for Windows 10; otherwise the call will just return "You do not have sufficient privilege to perform this operation."
This works for Git Bash 2.20.1.windows.1/MINGW64 (Windows 10) without administrator rights (if you can read/write both /old/path and /link/path:
original_folder=$(cygpath -w "/old/path")
create_link_new_folder=$(cygpath -w "/link/path")
cmd <<< "mklink /j \"${create_link_new_folder}\" \"${original_folder}\"" > /dev/null
For anyone who's interested in how to accomplish this in Windows 10 Git Bash 2.28.0.0.1:
You have to prefix the ln -s command with the MSYS=.. instead of executing export MSYS=.. first, namely it's just one command:
MSYS=winsymlinks:nativestrict ln -s <TARGET> <NEW_LINK_NAME>
Since this is one of the top links that come up when searching for creating symbolic links in MSYS or Git Bash, I found the answer was to add
set MSYS=winsymlinks:native when calling git-cmd.exe (I run ConEmu) or uncomment the same line in the msys2_shell.bat file.
I prefer PowerShell to CMD, and thought I'd share the PowerShell version of this.
In my case it consists of making symbolic links linking ~/.$file to ~/dotfiles/$file, for dotfile configurations. I put this inside a .sh script and ran it with Git Bash:
powershell New-Item -ItemType SymbolicLink\
-Path \$Home/.$file\
-Target \$Home/dotfiles/$file
Instead of symbolic links on Windows, I found it easier to write a small Bash script that I place in my ~/bin directory.
To start Notepad++ with the npp command, I have this file:
~/bin/npp
#!/usr/bin/bash
'/c/Program Files (x86)/Notepad++/notepad++.exe' $#
And I get the path syntax right by dragging and dropping the file from Windows Explorer into Vim.
The Windows command mklink /J Link Target doesn't seem to work any more.
git bash honors the symbolic links created by cygwin. The caveat is that the symbolic link not use, e.g., '/cygdrive/c/directory' and instead use '/c/directory'.

Is there any MS-DOS command to get the version of an executable (or dll) file?

Is there any MS-DOS command to get the version of am executable (or dll) file?
Of course there is a simple command ;-)
wmic /node:"servername" datafile where name='c:\\Program Files (x86)\\Symantec\\Symantec Endpoint Protection\\smc.exe' get version
you can ommit /node to perform check on the local computer. And if you ommit "get version" you get all the values and column names. Of course there are standard wmic parameters available like /output:filename, /append:filename or /format:csv and you can use #list.txt instead of a server name to perform check on list of machines.
Either user powershell
see
Get file version in PowerShell
or Windows Explorer
or write your own utility, I don't think that MSDOS supports this natively.
You could load the executable as a binary file and read the PE headers manually...
http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
You can try Resource Hacker with the following syntax:
reshack.exe -extract "path\to\my\file.dll," ver.rc, VERSIONINFO, , && findstr FILEVERSION ver.rc
Beware of commas. Make sure you can create ver.rc.

Best way to open an URL in Vim

Lets say that you have either URL or a link on a webpage that is a text file. How would be the easiest way for the user to be able to open that file in a Vim?
Right click and save link as?
Use a specific file extension that defaults to Vim?
Command line command?
Depending on how your vim binary was built you can just give vim the url:
vim http://www.google.com/
Vim spawns curl and grabs the file, then opens it.
Assuming you want to just open a link in vim, how about this:
curl http://www.google.com | vim -
EDIT
to make this command easier you can always user your browser of choice's "Copy link address" option.
EDIT
Given #speshak's answer and my own, I would say the "easiest" way would be option 3, "a command line command".
Solution 1: use command
" gvimrc
for g:chrome_exe in [
\'C:\...\Google\Chrome\Application\chrome.exe',
\]
if !filereadable(g:chrome_exe)
continue
endif
command -nargs=+ URL :exe "silent !start ".g:chrome_exe." <args>"
break
endfor
Now when you type: :URL https://news.google.com/topstories?hl=en-US&gl=US&ceid=US:en
it will open google news
Solution 2: use function
or if you have a file that records a lot of URLs, and you want to use hotkey to open it, then you can try in this way
" .gvimrc
let g:chrome_exe = 'C:/.../Google/Chrome/Application/chrome.exe'
function OpenURL()
normal "*yy
" let result = getreg("x")
" return result
:execute "silent !start ".g:chrome_exe2." ".getreg("*")
endfunction
map ,url :call OpenURL()<CR>
and then, you can open it with ,url
" test.txt
https://www.google.com/
https://news.google.com/topstories?hl=en-US&gl=US&ceid=US:en
Explanation of command
URL is a name, choose by you. (remember User-defined commands must start with an uppercase letter)
what is the command
command -nargs=+ Say :echo "<args>"
Now when you type :Say Hello World
Vim echoes "Hello World".
nargs
-nargs=0 No arguments
-nargs=1 One argument
-nargs=* Any number of arguments
-nargs=? Zero or one argument
-nargs=+ One or more arguments
I have used links before since RedHat days. The command would be
links http://www.google.com
If links is not installed, you can do sudo apt-get install links on Ubuntu 14.04 LTS to install it.
Hope it helps.