batch file run as admin registry key? - batch-file

I was wondering if there is a string/value that I can add to the registry in order to always run a batch file as admin?
note: this batch file will run automatically at windows start up
This is only a project and I do not want to use any other language at this time.
Thanks in advance

The properties of the batch file can be changed to run as admin.

Related

Run command in powercli using batch

I am planning to use batch file to run few commands in VMWare PowerCli tool. I am able to open Powercli tool by batch file. But after the tool is opened, it should automatically go to a specific folder and then run a file from that folder.
Eventually I would like this to add in Task scheduler so that it runs on specific time with no human interaction.
Is there a way to do it in batch or cmd? Any help is appreciated.
If I have read the question correctly you want to run a script on a VMWare VM using PowerCLI in which case you can use the invoke-vmscript command and set the scripttype to BAT
https://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Invoke-VMScript.html
The batch file would change the location. Alternatively you can use the copy-vmguestfile command and copy the batch file over and just use the invoke-vmscript command to run that batch file.
If the eventual goal is to have start up run the file then use the copy command and use the invoke command to update registry keys regarding startup.
https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FCopy-VMGuestFile.html

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?

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.

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

Batch runs manually but not in scheduled task

I don't generally write batches, but I currently have a batch that uses forfiles to copy my FLVs from one folder to another. When I run the batch manually it works every time, but from a scheduled task, it throws a (0x1) error.
forfiles -p "C:\Program Files\Adobe\Flash Media Server 4.5\applications\name\streams" -m *.flv -s -d -1 -c "cmd /c copy #file ^0x22C:\Program^ Files\Adobe\Flash^ Media^ Server^ 4.5\applications\name\output\"
Not sure what syntax the scheduled task doesn't like.
Update
Under my scheduled task, Actions I have the following:
Program/script: name.bat
Start in (optional): \\servername\file\to\batch
Hi might be this is helpful,
I also face the same issue.
Just set the startin path like:
Here start in path is the path of batch file:
like you have enter in program script:
"E:\program related files\demo.bat"
then in startin just pass:
E:\program related files & done!
When my Start in (optional): path was a UNC path, it wouldn't work. So I moved my batch on the server and everything worked correctly.
UNC in Windows Batch Files
forfiles with UNC path
On Server 2008 R2 when running the batch file under domain user credentials, with confirmed "log on as a batch job" security in the Local Security Policy>Local Settings>User Rights Assignment,
even then my batch (copying a log file to a network share) would not run as scheduled task, until I selected in tab General the option "Run with highest privileges" (default NOT checked!)
The option Run whether user is logged on or not was also selected, with radio-button, but I guess this is quite standard, when selecting to run the task using a domain user account.
For the tab Actions : specifying the entire batch file name including its path, directly in "Program/script:" works fine (with Server 2008 R2)
Using double quotes inside the batch file causes no problems.
See the screen shot bellow.
You need to change the user to system
Most common reason for such problems is permissions: scheduled tasks does NOT always run with your user credentials. If you want scheduled task to run as you you will have to set it up as you or alternative user.
Besides that I hope that your line of code is a content of your batch file, you are not trying to run this command directly. Or are you?
P.S. What are these ^0x22 and ^ doing in your code?
I know this is an old question, but just wanted to share some info.
The (0x01) error code can also refer to resources that are not found. Therefore:
all files/folders referd from within the batch file should be accessible to the user which account is being used to run that scheduled task;
pay attention when using network locations in combination with "Run whether user is logged on or not" option;
the above-mentioned option can be tricky to use because some resources may be available only after log on.
For .bat files to run inside your scheduled task, you need to specify your .bat file path inside the start option - despite the fact that your .bat file is at the same directory as your .exe. Also, I flagged it to run with highest privilege. After I have done those two things, the task suddenly takes off without any problem!

Resources