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
Related
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.
When I build a go project using a bat in jenkins, it reports an error:
go tool: no such tool "asm"
however, when I build the go project alone with cmd or goland, the error does't happen, Why this error happen?
the Command in Jenkins is
C:/Users/Administrator/Desktop/build.bat
and the bat content is:
#echo off
cd C:/Users/Administrator/Desktop/GOPATH/src/Flipped_Server/main
go build main.go
xcopy main.exe "C:/Users/Administrator/Desktop/Flipped-Server" /s /e /c /y /h /r
echo "Succeed to build and deploy the flipped-Server"
When I uncheck the option
Set up Go Programming language tools
It works! build Successfully
So, there is always one installer (msi) in a folder for install generation, but the name changes many times. I tried doing the following:
"C:\Windows\system32\msiexec.exe" /i "C:\test\*.msi" /qn
But sadly, this doesn't work and complains. How can we get the name of the single msi in the folder, and plonk it into the command?
I'm using jenkins and using the "Execute windows batch command" item
Perhaps use a for loop to find all .msi files in that directory, and run it accordingly (obviously if there is more than one .msi you will need to tweak this logic):
for /r "C:\test" %%a in (*.msi) do msiexec /i "%%~dpnxa" /qn
This seems like such a basic thing..kill app & restart it..
I have this batch file configure to run daily through windows task scheduler:
#ECHO OFF
::Daily reboot to limit ram usage
taskkill /F /IM javaw.exe
::
:: start app again
::
start app.jar
The script is run each day successfully according to windows but it is only closing the program not starting it again. When I double click my .bat file it works just fine..
What am I missing?
Well I'm in my first year of bachelor only using BlueJ so far to learn java so I apologize.
Happy that I now know the task run from c:\win\sys32. I could see the logs from the java app there not finding the libraries. so the #CD /D "%~dp0" I'll try to remember for sure. Thx
final code:
#CD /D "%~dp0"
::Daily reboot to limit ram usage
taskkill /F /IM javaw.exe
::
:: start app again
::
start java -jar d:\path\to\app.jar
full path to javaw.exe was not needed, only diff when running the app with task scheduler is that the last line in log should be "added to SystemTray" making the app visible. Now it is running hidden, which is ok for it's use but I'll try to figure out on my own why.
(just "start app.jar" is also working just fine btw with the #CD /D "%~dp0" on top.)
thx,
First make sure you have configured environment variable for running java.exe . If not, refer this .
Secondly, always use complete path to start/kill your jar execution.
The command to run your application is:
java -jar app.jar
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)