msiexec /a not working - batch-file

I am trying to create a batch file to run an unattended installation of Adobe Reader 9 (it is a MSI file)
My problem is with the UAC. If I make a command like this:
msiexec.exe /i "AcroRead.msi" EULA_ACCEPT=1 ALLUSERS=1 /passive
The installation runs fine, except that I have to accept the UAC before it does anything. If I replace the /i with /a, it skips the UAC, and it seems to be installing, but when it finishes, it didn't install the program at all! No error message or nothing, it does not show up on add/remove programs.
Might it be that it installs to the wrong profile if I use the /a switch?
I am very new to scripting, so most of the info I have is what I can scavenge from google.
I know there are ways to disable the UAC from the batch, but if possible I would like to avoid that.
I am doing this on a virtual Win7 x64 sp1 machine.

Any software installation should prompt for admin credentials regardless of whether you launch the installer via the batch script or double-clicking the AcroRead.msi file in Windows Explorer. This is how permission on Windows works, and to be honest, I wouldn't want a system that could be bypassed via a terminal WITHOUT prompting for credentials. I don't believe there's any way around this.
Try removing /passive, since maybe that is suppressing an error message. Also insert a pause statement at the end of your batch script so you can read the error message before the command prompt is closed.
Edit:
Run the batch script as an administrator. This is different than running msiexec with the /a command. This will open the UAC prompt at the beginning of the script, and if authenticated, the rest of the batch file will be run with admin privileges.

/a is not used for a normal installation. It will generate an administrative installation. A "network" installation to allow other users to install from a common repository.

Related

start a batch file on startup as administrator on win 10

I want to disable auto-updating on Windows 10.
I found out that disabling the service "WINDOWS UPDATE" will do this.
It did for some time, but when ever i restart my system it enables itself again and again. So I created batch file that disables it.
#echo off
NET stop "Windows Update"
I put it in startup folder but it worked only if it is executed as administrator. I tried to set properties of the shortcut to "RUN AS ADMINISTRATOR" but it stopped executing on startup.
Then I read about Task scheduler and added this task there but still its not working there even it just shows "The Directory Name is Invalid. (0x8007010B)

Run file NOT as administrator

I'm trying to test a batch file that should test for administrator privileges, but I have the weird problem that I can't run it without administrator privileges.
net session >nul 2>&1
if %errorLevel% == 0 (
rem do whatever...
Sure, I can just create another user account and run it from there, but that's a bit much effort just for one little test.
The script example above may not exactly be what I wanted because I need a general solution, for example to test if an installer can run without admin rights.
Is there an easier way? A command line argument for running something without administrator privileges maybe?
BTW, I disabled UAC if that makes any difference.
You can try with
runas /trustlevel:0x20000 "cmd.exe /c ....."
use runas /showtrustlevels to see the available levels

How can I end a process with admin privileges using a batch file

I have written a batch file which starts OpenVPN. If the client is found, I check the connectivity by running PING. If the server is not found, then this means that although OpenVPN is running, the connection has not been established. At this point I want to restart OpenVPN. Because I am not using the admin account for this script, I always get the error "permission denied" when using TASKKILL /F. Is there anyway around this?
There are two methods of running a command with administrator privileges.
Solution 1:
Right-Click the batch-file and click run as admin.
Solution 2:
Use the runas command to run a command or batch file with administrative permissions. This way the process is still automate but you will still need to type in the password for administrator.
Example:
C:\> runas /user:administrator "taskkill /f /im explorer.exe"
Enter the password for administrator:
Type runas /? for more info.
if you are already the administrator, you can create a shortcut to your batch file and when you right click the shortcut -> properties -> advanced -> check the checkbox "run as administrator"
and voila!
everytime you run the batch script via this shortcut file, it will run as administrator and will kill without any discrimination, happily ever after

not able to delete file from command line in windows server 2008

I am writing a batch program in windows server 2008
I am using robocopy command and /move parameter to copy and delete the file from source path. Not able to succeed.
Then I tried using DEL dos command. Not successful.
Throwing access error
Could you please let me know the dos command to forcefully delete a file or clear the contents of the file.
assuming the file is write-protected, try:
del /f file
Sounds like you don't have permission to that file/folder. Even if you are an admin... open an administrative Command Prompt by Right Clicking on CMD.exe or shortcut and 'Run as administrator'.
AN administrator does not have the same privileges as THE local Administrator.

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