Created a GPO to run a batch file on shutdown for domain XP computers - with the purpose of deleting old user profiles.
For this I am using an application called DeleteProfiles from OptimumX.
cd C:\
if exist "Program Files (x86)" GOTO Exit (Checks if XP or not)
if exist DeleteProfiles GOTO COMMAND
:CopyDeleteProfiles
md DeleteProfiles
copy /Y \\SomeShare\SomeFolder\DeleteProfiles\DeleteProfiles.exe
C:\DeleteProfiles\
:COMMAND
pushd C:\DeleteProfiles\
start /Wait DeleteProfiles.exe /MIN:14 /Y
rem (/Min: # = Delete profiles older than # and /y removes yes or no prompts)
:Exit
End
It works alright, but a CMD window appears at shutdown with the output of the program.
How do I make it go away?
The real problem here is that users can close the program which causes the script to stop. If I can't make that go away, I would like at least to make the window not close-able.
Looked up start /?, adding the /b parameter does the job
start /b /Wait DeleteProfiles.exe /MIN:14 /Y
Related
My goal is to create a batch script to copy a folder with subfolders to user desktop with overwrite option and minimized of command prompt.
I am pushing the script through Group policy in user start up screen.
However I am getting an error when running the script locally. Not sure what I am missing in the script..
#echo off
#cls
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
echo Your Source Path:
set INPUT1=\\X.X.X.X\Test\TMS\
echo Your Destination Path:
set INPUT2=C:\Users\%Username%\Desktop\
xcopy %INPUT1% %INPUT2% /y /s
:minimized
You mentioned folder, so I am writing this assuming you want to create the TMS folder with content on the desktop.
I would try something like this inside of you minimized label. This is untested as I have no Network drives to test with.
for /f "tokens=2" %i in ('net use * "\\X.X.X.X\Test\TMS\" ^| findstr /i Drive') do set "tmpDr=%%i"
mkdir "%USERPROFILE%\Desktop\TMS" >nul
xcopy "%tmpDir%\*" "%USERPROFILE%\Desktop\TMS" /s /y
net use /d %tmpDir% >nul
Some things to note in your code. You have 2 minimized labels, you need to enclose path variables with double quotes to eliminate possible whitespace, you can drop the echo's seeing as you plan on running the script minimized. Last but not least, you do not need to specify full path to the user's desktop as %USERPROFILE% variable already exists as Drive:\Users\Username
Here is what I have so far:
IF EXIST "C:\Program Files (x86)\Yawcam\Yawcam.exe" GOTO :eof
ELSE
start \\hazel\software$\YawCam\v6.0\yawcam_install.exe /SP- /VERYSILENT
xcopy "\\hazel\software$\YawCam\Doc Cam.lnk" "C:\users\public\desktop\Doc Cam.lnk" /C /Y
:eof
pause
EXIT
Now, it installs properly, but doesn't create the shortcut. I have tried so many different combinations of switches, quotes, and statements. I just can't seem to get it to work. I would very much appreciate any help with this, because I'm sure it is just something I have simply overlooked. Thank you in advance!
The following rewrite requires to be run As administrator.
If Exist "%ProgramFiles(x86)%\Yawcam\Yawcam.exe" GoTo :EOF
"\\hazel\software$\YawCam\v6.0\yawcam_install.exe" /SP- /VERYSILENT
XCopy "%~dp0Doc Cam.lnk" "%PUBLIC%\Desktop" /C /Y
Pause
I would write it like this:
pushd "\\hazel\software$" || exit /B 1
if not exist "%ProgramFiles(x86)%\Yawcam\Yawcam.exe" (
".\YawCam\v6.0\yawcam_install.exe" /SP- /VERYSILENT
)
copy /Y ".\YawCam\Doc Cam.lnk" "%PUBLIC%\Desktop\Doc Cam.lnk"
popd
exit /B
What I did, and why:
added pushd to resolve the UNC path \\hazel\software$ as some commands might have trouble with such; || means to execute next command in case of failure, exit /B 1 exits the batch file if pushd fails, like when the path could not be found; popd at the end restores the previous working directory finally;
reversed the if query as you want something to happen in case the condition is not met; this also avoids the need of goto; in addition, never define a label :EOF as this is a reserved name (see this: goto); regard that your if/else syntax is wrong!
used environment variables for system paths, like %ProgramFiles(x86)% and %PUBLIC%, because the directory locations may be different on some systems;
removed the start command as it is usually not necessary to run external (console) programs; (if it is required for this application for some reason, you might want to change the syntax to: start "" /WAIT ".\YawCam\v6.0\yawcam_install.exe" /SP- /VERYSILENT)
replaced xcopy by copy since you are copying a single file only, in order not to having to deal with the F = file, D = directory prompt;
added switch /B to exit in order to just terminate the batch file but not the hosting command prompt (cmd) instance;
I'm not sure if this method is necessarily the best way to go about it, but it got it working for our needs! I appreciate all your guys' help with this! We looked at each comment/answer and went from there. Thank you!
Here's what we did in the end:
IF EXIST "C:\Program Files (x86)\Yawcam\Yawcam.exe" GOTO eof
ELSE
start \\hazel\software$\YawCam\v6.0\yawcam_install.exe /SP- /VERYSILENT
:eof
Echo F|xcopy "\\hazel\software$\YawCam\Doc Cam.lnk" "C:\users\public\desktop\Doc Cam.lnk" /C /Y
EXIT
Hopefully this can help someone trying to do the same in the future!
Details:
Using a program called MCEBuddy to process video files and when completed MCEBuddy will run a users batch file for custom processing. In this batch file, I fix up a few things and simply move the proccessed video to it's final location.
Goal:
To allow the batch file to return to MCEBuddy and not wait until the move has completed. Currently MCEBuddy will not resume before the entire file (video) has been moved, I don't want that.
I have 2 batch files, the first simply passes the parameters to the second batch file.
I have search and search, and even asked the developer over at MCEBuddy and is seems that everything I have tried just doesn't work.
The first Batch file:
#ECHO OFF
setlocal EnableDelayedExpansion
SET BatFile="E:\VideoCaptures\Cleaned Files\TVTransfer.bat"
SET OutputFileName="%~n1"
SET InputFileName="%~n2"
SET FolderOutput="%~3"
SET WideoWidth="%~4"
SET OutputExtension="%~5"
SET OutputFileSize="%~z1"
SET OADMonth="%~7"
SET OADDay="%~8"
SET OADYear="%~9"
START "MCE Move" /b cmd /c Call %BatFile% %OutputFileName% %InputFileName% %FolderOutput% %WideoWidth% %OutputExtension% %OutputFileSize% %OADMonth% %OADDay% %OADYear%
The second Batch file (the part that moves the file)
START "MCE Move" /b cmd /c move /y "%OUTPUT_FOLDER%\%~1%OUTPUT_Ext%" %sPAT%\%MMDDYYYY%
I have also tried:
START "MCE Move" /MIN cmd /c move /Y "%OUTPUT_FOLDER%\%~1%OUTPUT_Ext%" %sPAT%\%MMDDYYYY%
and:
START "MCE Move" /MIN /b cmd /c move /Y "%OUTPUT_FOLDER%\%~1%OUTPUT_Ext%" %sPAT%\%MMDDYYYY%
and many other iterations, but none will allow MCEBuddy to resume before the file has completed it's move.
What am I missing?
I'm on my phone right now. But have you tried
START "" "MCE Move" /b cmd /c move /y "%OUTPUT_FOLDER%\%~1%OUTPUT_Ext%" %sPAT%\%MMDDYYYY%
For my work I install software and configure it using a batch file; setting folder permissions, copying config files from a server share to make it work etc. All this is fine and I have been using stuff I have got from here for some time with no problem. I have to do it on multiple computers and on occasions at places where the link is so slow it takes ages to run everything from the server share.
I made a batch file that lets me choose between network install process or from USB to really speed things up. However I'm now faced with waiting for everything to finish installing from the USB before I can move on to the next PC. Many of the PC's are very slow so I can be waiting best part of 10 mins. I'd like to be able to run a batch file from the USB which then copies the software installer and related files to C:\Temp (or such) then launch another specific batch file from C:\Temp (and runs from that dir). The end result being I can plugin the USB, run the initial copy to C:\Temp bat file, the called batch file from C:\Temp then does the install instead of USB allowing me to remove the USB and get on with the next PC without waiting for the process to finish from USB.
I have had some success on my PC with windows 10 ( I assume will work fine for 7, 8 etc.) However with XP (which in my line of work still crops up more than you'd think) when I remove the USB stick, the process is trashed because for some reason, even though I call the C:\Temp bat installer in a new window, that new window still holds on to the fact it's coming from USB, there fore it wont complete unless I leave the USB in. Which is not what I want of course. Maybe there is a better way I'm sure, I just need a solution that works on all XP, 7 , 8 etc. You can see, I just copy a few things to C:\Temp then choose which bat installer I need at the time, then (try) and fire up the appropriate bat running from C:\Temp instead of USB letting me move on with out having to wait. Hope some one can advise. Many thanks!!
Here is the bat that copies from USB to C:\Temp
if not exist C:\Temp md C:\Temp
echo F| XCOPY %~dp0silentinstall.exe /y C:\Temp
xcopy /herky %~dp0GUIDES C:\Temp\Guides /i
echo 1 -- Standard
echo 2 -- DelR2
echo 3 -- FullWipeInstall
echo;
set /P rmFunc="Enter a choice: "
echo --------------------------------------------------------------------
for %%I in (1 2 3 4 5 x) do if #%rmFunc%==#%%I goto run%%I
goto begin
:run1
echo F| XCOPY %~dp0Standard /y C:\Temp
cd C:\Temp
call cmd /c Standard.bat
exit
:run2
echo F| XCOPY %~dp0DelR2.bat /y C:\Temp
cd C:\Temp
call cmd /c "DelR2.bat"
exit
:run3
echo F| XCOPY %~dp0"FullWipeInstall.bat" /y C:\Temp
cd C:\Temp
call cmd /c "FullWipeInstall.bat"
exit
Your bat file resides on the USB. So it can't load the exit statement if USB is removed. I suspect that you are just lucky that it works on some OS's because there is nothing to do other than exit anyway. Without testing there are probably several ways to fix:
1. Replace these 2 lines with a suitable START command and then exit. See START /?
cd C:\Temp
call cmd /c "FullWipeInstall.bat"
Put the exit on the call and the exit on the same line like this
call cmd /c "FullWipeInstall.bat" & exit
My batch file contains a START command that runs a short vbscript program. When the batch file completes, the code of the vbscript program is shown in an open Wordpad window. This only started happening after we converted to Windows 7. Never happened under XP. Why does this happen and how can I prevent it? I have done extensive internet searching and come up with nothing.
Here is batch file:
#echo off
cls
echo.
echo Copying Latest Version of FREDS Database ...
echo.
xcopy "\\sstore02\S-Drive.OOD\OPI\FREDS\FREDS.mdb" "K:\FREDS\" /i /q /y
echo.
echo If you see "1 File(s) copied" then the copy was successful
echo.
echo Copying Shortcut Installer ...
echo.
xcopy "\\sstore02\S-Drive.OOD\OPI\FREDS\FREDS-Shortcut.vbs" "K:\FREDS\" /i /q /y
echo.
echo If you see "1 File(s) copied" then the copy was successful
echo.
echo Adding Shortcut icon to Desktop ...
echo.
Start K:\FREDS\FREDS-Shortcut.vbs
echo.
pause
You need to call cscript instat of start.
cscript /nologo K:\FREDS\FREDS-Shortcut.vbs
The option /noscript hides the version of cscript in the output.
Notepad is the registered program for the VBS extension on your machine.
Right click a VBS file and select Open With and then navigate to cscript.exe in c:\windows\system32 folder usually. Select the checkbox to always use that program and then the start command will work with VBS scripts and Cscript.