Running a bat file from another - batch-file

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

Related

Runas command to read user details from a txt file

having an issue where a batch script of mine is changing time server REG Keys but requires admin privildges to do so, even if local user is admin.
My way around this i have found is using this line of code:
runas /noprofile /user:administrator\administrator "%UserProfile%\Desktop\Time Server.bat"
But this asks me for the admin password everytime, and i cant be doing this for 150+ users.
Can i get this command to read user details from a .txt file or .ini file?
Thank you in advanced.
OliV555
AFAIK this is not possible out of security reasons. I've spent a lot of time on this but at the end, I had to use a workaround:
Create a new task with the windows scheduler. In the interface select the admin user you want to run your script with and enter the password. Check the option to run the task with highest privileges. Let your task execute the batch file with all the code you want to run as admin. Don't enter any trigger to start your task automatically.
Now here's the trick:
To run your command with admin privileges simply execute
SCHTASKS /Run /TN <taskname>
If your local user is admin this will work straight on. Otherwise, you'll have to grant the user rights to start tasks.
EDIT: The scheduler will execute your batch file with system32 as working directory. So if you are using any relative paths in your script don't forget to adjust them or replace them with absolute paths.

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?

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?

NSIS batch file permissions

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.

How can I use a batch file to launch an application as a specific user?

I'm trying to figure out how I can use a batch file to launch Internet Explorer as a local user on the system hosting the batch file. Ideally I'd like to be able to double click the batch file and not have to enter user credentials. To break it down a bit:
User is logged onto the host system with a domain user (Server 2008 R2 Standard 64bit)
User can then double click on a batch file that will launch Internet Explorer as a local user on the host system, without prompting for the local user credentials
All I can find is information about NET USE, any help would be greatly appreciated!
"runas" command was intentionally designed to prompt for password. So, that is not your solution.
One of option is to create a scheduled task where you can store the password (safely) and run the scheduled task from batch file.
But if the batch file is distributable and not going to be run on same machine.. you may have to investigate on how to create a schedule task from batch file and then run it.
you may find this reference helpful

Resources