Batch script does not execute properly when launched automatically - batch-file

I've an issue that seems a privilege issue but i really do not understand what is happening.
This is my installation script :
...some command...
C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil C:\Programmi\ProgDir\ProgService.exe >> log.txt
ping 127.0.0.1 -n 5 > null
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /f
ping 127.0.0.1 -n 2 > null
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v Shell /t REG_SZ /d C:\Programmi\ProgDir\ProgName.exe /f
I try this script using installation wizard (created by winrar) and manually , in both cases i give to the script admin privilege; to prove this the service is installed successfully (it require administration privilege, so the script has these privileges as expected) but the registry is not affected if the script is launched by the wizard.
Can anybody explain to me what is happening ?
Thanks in advance (and sorry for my poor english)

Related

MSI installer does not install when executed from a batch file

I am currently creating an improvised installer for a cople software packages. To do this I have to install a couple MSI packages first before doing a couple file operations.
To install an MSI package I am using the following command:
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
This command works and installs the package instantly and witout any problems via CMD.
But when I put this command in my batch file and execute it as an administrator, I get the following error:
This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package
What cold be the problem? Using the same command via the console works flawlessly, only the batch file throws the error...
EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either. Full command in batch file:
start /wait msiexec /qn /a "Myinstaller V2.1.msi"
EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator
When I open a console with administrative rights and start my batch file it works for some reason...
Is there a way to make it work with the Right click > Run as administrator method?
SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator. With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause
I've now also implemented a feature to detect wether or not the installation fails or not:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause
The current directory changes when you run as administrator. If you want to prove that to yourself, see this post
Difference between "%~dp0" and ".\"?
Include the full path to your filename and it will work.

Batch file Proxy Setting Disable not working Win 10

The following line of script from a Batch file works fine in Win 7 and successfully disables the proxy setting in IE, but when i have tried it on Win 10 it dosnt work the proxy setting in unaffected, any ideas why?
UAC is auto elevated as per UAC so admin privileges is not an issue.
i have checked with regedit and the HKCU directory seems to be the same path on both.
echo LAN Settings - Proxy Setting *Disable*
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^ /v ProxyEnable /t REG_DWORD /d 0 /f
IE > Internet Options > Connections > LAN Settings

In batch script silent installation using Reboot=reallysuppress is not updating the files

I am using batch Script for silent Installation to update the locked and in use files.Using silent installation reboots my system automatically after the update.But I wanna setup a custom reboot message box , So I used the REBOOT=ReallySuppress attribute. And I used a message box to popup the custom reboot message. This helps me avoid the auto-reboot of the system but it is not updating the files even after performing a manual reboot.
Here is the script that I am using.
#echo off
title Installing Updates
msiexec /i "C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi" /qn /REBOOT=ReallySuppress
echo updates installed
echo msgbox "Restart your system to complete the installation." > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"
pause >NUL
shutdown.exe /r /t 000
Can someone give me a solution to get the files updated with manual reboot.
did you try instead of /REBOOT=ReallySuppress the /norestart option?
Please also make a log file in the install cammand via /l option. Then read the log if really the installer reboots the computer.

Batch script not working after deploy with SCCM

I have created a script to manage manually the windows update clean up. When i try to run as admin the below script, it works fine. i am trying to deploy it through SCCM. The script is copied in the ccmcache folder but it's not running. Any help please ?
#echo off
echo Config cleanmgr flag 5100.
call reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup" /v StateFlags0011 /t REG_DWORD /d 0x2 /f
%systemroot%\System32\cleanmgr.exe /sagerun:11

sql server installation errors regarding WMI service

I am trying to install SQL Server 2008 and during the pre requisite check its always fails on
WMI service "Failed".
I went to the event viewer and found this error in there.
"Failed to Initialize WMI Core or Provider SubSystem or Event SubSystem with error number 0x80040154. This could be due to a badly installed version of WMI, WMI repository upgrade failure, insufficient disk space or insufficient memory."
I know there is a lot of space available in my hard drive. Also i tried a few things after googling like WMIFIX.bat file. The file ran fine but did not fix the problem.
Has anyone had this problem? If so do you have a solution?
if you have a domain so Run this Command with administrator Privilege
you can copy this Command and Past in Notbat with .bat extention. and run them.
Rundll32 setupapi,InstallHinfSection Ndi-Steelhead 132 %windir%\inf\netrass.inf
Netsh firewall reset
sc config SharedAccess obj= LocalSystem password= "" type= interact type= own
sc config RpcSs obj= LocalSystem password= "" type= interact type= own
sc config RpcLocator obj= LocalSystem password= "" type= interact type= own
sc config winmgmt obj= LocalSystem password= "" type= interact type= own
sc config Wmi obj= LocalSystem password= "" type= interact type= own
net start winmgmt
net start Wmi
net start RpcSs
net start RpcLocator
net start WmiApSrv
netsh firewall add portopening TCP 135 "Open Port 135"
netsh firewall add portopening TCP 445 "Open Port 445"
netsh firewall add portopening TCP 139 "Open Port 139"
netsh firewall set opmode mode=DISABLE
shutdown /r
if your problem did not solve you Can execute this Command in Command Prompt with admin privilege.. you can just copy and paste them in notepad and rename it with .bat extention an run the file..
net stop winmgmt
C:
cd %systemroot%\system32\wbem
rd /S /Q repository
regsvr32 /s %systemroot%\system32\scecli.dll
regsvr32 /s %systemroot%\system32\userenv.dll
mofcomp cimwin32.mof
mofcomp cimwin32.mfl
mofcomp rsop.mof
mofcomp rsop.mfl
for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
for /f %%s in ('dir /b *.mof') do mofcomp %%s
for /f %%s in ('dir /b *.mfl') do mofcomp %%s
echo DONE reboot
pause
just it and have a good day !!!!!
Run the WMI Diag Utility. Here are the instructions how to do this:
Download WMIDiag.
To run the WMIDiag tool:
1. Open a command prompt window.
(Use "Run As Administrator", if applies to your Operating System version)
2. Navigate to the wmidiag folder that was created when you ran Wmidiag.exe.
3. Type cscript wmidiag.vbs.
View what the output of that is and post what it says. That'll give you a better indication of what's happening.
Here is a reference for the above instructions.
I faced this issue when I tried to install SQL Express
For me, following steps worked out which I referred from http://mikeymurph.me/fix-wmi-service-error/
Run the following in Powershell in Administrator mode
PS C:\Windows\system32> winmgmt /verifyrepository
WMI repository verification failed
Error code: 0x80041002
Facility: WMI
Description: Not found
PS C:\Windows\system32> Winmgmt /resetrepository
WMI repository has been reset
Now try to install SQL Server again.

Resources