NSIS batch file permissions - batch-file

I have a batch file which modifies some files within program files upon installation of an application using NSIS.
The issue I currently have is that NSIS is not running the batch file with administrator permissions so the script fails.
Is it possible to run the script with the required admin permission set?
It must support the OS XP+, and the batch script is run from an NSIS installer.

Is the NSIS installer being ran with administrator permissions? If so, any process that the installer starts will also have administrator permissions.
Check out Ander's answer on how to request admin rights for your installer:
https://stackoverflow.com/a/8735349/1030416

How do you execute your batch? Exec, ExecShell or nsExec?
Try changing it or paste snippet of your code here.

Related

Is there any way I can run a batch file with administrator privileges ( without right clicking and selecting "Run as admin")

I'm actually looking for a way to run the batch file as admin by using a code. If that is not possible is there any way to run an .exe file as admin by default?

Unable to access pscp.exe with a windows service account

I have built a windows batch file code that fetches the list of files from an FTP server and then pulls the appropriate file from that list. The batch file uses a combination of pscp.exe and psftp.exe in order to achieve this.
If I login as a member of the administrator group and execute this batch file manually (double clicking) it works perfectly, but the problem arises when I schedule a windows task to run that batch file from a windows service account (which is not in the administrator group).
The job when running under the windows service account is unable to execute the command for pscp.exe used in the code, whereas it executes everything else prior to that in the batch file perfectly normal.
Below is the line of code that I have used in my batch file :
pscp.exe -sftp -v -batch -pw %password% -ls %username%#ServerAddress:/outbox > F:\dirlist.txt
The service account is a member of BatchAccountsLG and ServiceAccountsLG groups, which is needed for the job to be able to execute the batch file code. Also, the service account has all the required access on any of the files/folders needed in the execution of the code.
I am not sure what the problem is because the batch file works perfectly fine if use my admin credentials, whereas it fails when the job is scheduled with the windows service account.
I have tried looking for an answer through google, but I have drawn a blank, any help on this would be highly appreciated. If there is anything else that I need to add to this, I would be more than glad to do so.
Thanks to all the ideas in advance.

Batch file to run under administrator always

How can i make a batch file always run as administrator and then convert it into exe file so that it asks the user to run as administrator in all computers
Depending on the version of windows you are using - there are already answers on stack about this
How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?

Running a bat file from another

this is the structure of a batch file
SET CURDATE=%date%
REM run some code bellow
.....
.....
.....
.....
"C:\CADMAC2k\SYS\CADMAC.exe"
this batch file reads the current date, does some modifications and then starts cadmac.exe (a cad program).
this batch file needs to be run as administrator right, but cadmac.exe should be run as current logged-in account.
when I right click this batch file and select run as administrator, cadmac.exe is run with admin rights too.
Is there any way to make cadmac.exe run with current user rights (logged in account) not administrator rights?
any kind of advice is much appreciated.
If there are specific commands in your batch file that need to be run as Administrator you can use the runas command.
Then, you can start the batch file as the logged-in user. runas prompts for Administrator credentials when necessary.
You can use Run AS for exe.
Here is possible solution
Running .exe's with Run As in a .bat file

Text File Permissions Issue

What is the default SSIS Account that is used in SSIS packages.
In one of my packages I have a Data Flow task that creates a flat file. A BAT file later runs and creates a file based on information in that .txt file. If I execute the .BAT in Windows Explorer it runs fine. When SSIS tries to execute it I can see the CMD window open and it tries to access the txt file and isnt able to. Says "Unable to access nameoffile.txt"
I assume the issue is that the permissions are probably inherited by the SSIS user account so I am trying to figure out which account that is.
If you are running it from the IDE then it uses your permissions. Most likely the problem is that your file is locked by some other process in your SSIS package. To verify:
Add a PAUSE to your batch file to make it wait for any key.
Run your package. While the dos prompt is waiting, go into windows explorer and run your batch file again - you'll find the same error.
I changed the attrib value in dos for that specific folder by attrib -r -s and it worked. It thought it was read-only.
I am using Windows Server 2012 server, with a SQL Server 2012 database.
Adding Modify, Read, Write permissions to the folder containing the required file to the NETWORK SERVICE user seems to work for me.

Resources