I'mt trying to create a batch file that wil be called by another program but can not get the sendkey to work properly. It calls Zune and opens it but does not send the ctrl+p to start the play. If I have Zune open and run the batch file repetitively it will eventually start playing but I may have to run the batch 10 time in a row. Not sure why that is. Ideas?
#echo off
setlocal
start zune.exe
call :SendCtrlP "Name in Windowtitle"
:SendCtrlP <app>
setlocal
set vbs=%Temp%\_.vbs
>%vbs% echo set s = CreateObject("Wscript.Shell")
>>%vbs% echo s.appactivate "%~1"
>>%vbs% echo s.sendkeys "^p"
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
exit /b
Related
so I have 2 files, a zipped file with all my files/folders for a game and a unzipper.bat file that puts everything in the correct place to work.
I decided to use IExpress to make an installer for my game, and there was an option for running a file on installation, so i put setup.bat there thinking that it would run when all the files were installed, but it didnt do that.
how can I make it so that it runs setup.bat ones all the files have been installed?
edit: this i my current SED file
[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=0
HideExtractAnimation=1
UseLongFileName=0
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=I
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles
[Strings]
InstallPrompt=Are you sure you want to install Block Dodger?
DisplayLicense=
FinishMessage=Thank you for installing Block Dodger.
TargetName=C:\Users\Gebruiker\Desktop\Block Dodger (installer).EXE
FriendlyName=Block Dodger installer
AppLaunched=cmd.exe /c unzipper.bat
PostInstallCmd=%SystemRoot%\System32\cmd.exe /C unzipper.bat
AdminQuietInstCmd=
UserQuietInstCmd=
FILE0="Block_Dodger.zip"
FILE1="unzipper.bat"
[SourceFiles]
SourceFiles0=C:\Users\Gebruiker\Desktop\
[SourceFiles0]
%FILE0%=
%FILE1%=
when i run the installer it gives the following error:
the batch file which couldnt be found (shortcut_creator.bat) is in the zipped file unzipper.bat is supposed to unzip.
this is the content of unzipper.bat:
#echo off
setlocal
cd /d %~dp0
Call :UnZipFile "%~dp0" "%~dp0Block_Dodger.zip"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
del /f /q "%~dp0Block_Dodger.zip"
start /d "%~dp0Block_Dodger" shortcut_creator.bat
edit 2: i just checked the box "Store files using Long Files names inside Package" and it does work now, the only thing left now is how do i change where the files end up?
In your SED file, the PostInstallCmdshould be set as :
PostInstallCmd="%SystemRoot%\System32\cmd.exe /C setup.bat"
i fixed it by checking the box "Store files using Long Files names inside Package"
you can also do it by going to the SED file and setting
UseLongFileName=0
to
UseLongFileName=1
I am creating a batch file to open remote Computer Management console by taking User ID as input and computer name from 2nd column from file data.csv. it works fine on first attempt. When it goes back to :start label. and ask for other input. it gives error. System cannot find file ./data.csv
My code is
:start
set /p Input="Enter User-ID:"
for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")
)
cls
GOTO start
Good practice to use %~dp0 for paths in batch files (instead of relative paths like .) that way if the current working folder changes the file will always be located.
So change to %~dp0data.csv
:start
set /p Input="Enter User-ID:"
PUSHD
for /f "usebackq tokens=1-4 delims=," %%a in (".\data.csv") do (
if %input% ==%%a ("cmd /c Start /B /wait compmgmt.msc –a /computer=%%b")
)
POPD
cls
GOTO start
should restore sanity, pushing the directory then restoring it before the next cycle.
I have some code here that is being used to clear the event viewers on a few pcs. Currently I have to run this batch file with administrator access. Could someone help me in trying to modify it to just run normally.
Thanks
Here is the code
#echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
:noAdmin
exit
I've written a little .bat file containing the following commands:
#echo off
Slmgr /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
slmgr /ato edkk4b-3sf6-j3h4-i5i5-d04gd453dgr3
Then i've packaged it in a .exe with a tool.
It works great but at the end of the execution two popup are displayed...
Can i remove the first popup and let display only the second?
As I see it, there are 2 options:
Run slmgr with cscript so all of the output goes to the console.
#echo off
setlocal
cscript //nologo c:\windows\system32\slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
cscript //nologo c:\windows\system32\slmgr.vbs /ato edkk4b-3sf6-j3h4-i5i5-d04gd453dgr3
Call :MsgBox "Done!" "VBOkOnly" "Process Complete"
exit /b
:MsgBox prompt type title
::Function by MC ND
setlocal enableextensions
set "tempFile=%temp%\%~nx0.%random%%random%%random%vbs.tmp"
>"%tempFile%" echo(WScript.Quit msgBox("%~1",%~2,"%~3") & cscript //nologo //e:vbscript "%tempFile%"
set "exitCode=%errorlevel%" & del "%tempFile%" >nul 2>nul
endlocal & exit /b %exitCode%
Edit 1 copy of slmgr.vbs and put it on a network share and run it from there for all PC's.
New to batch scripting. Trying to write a script which checks for files with filename starting with LEND by polling a directory and if the file is not received by 17:30, then write a log message to log file. I have written the below batch script, the script runs fine as long as there are no files in the directory. As soon as I put files in there, it stops running. And restarts if I delete the files from that directory. Could you please advise where I am going wrong?
Thanks
#echo off
set I=0
set log=C:\logs\alerting.log
:recurse
for /f %%P in ('dir /b "C:\incoming\LEND*"') do (call :countfiles)
set Time=%time:~0,5%
echo Filecount: %I% at Time: %Time% >> %log%
if %Time%==17:30 goto OUT
pause 60
goto :recurse
:countfiles
set /a I+=1
:OUT
if %I%==0 echo LEND Files not received >> %log%
EXIT
Your code goes from countfiles to exit. Try this:
:countfiles
set /a I+=1
goto:eof
There were actually several flaws - reusing the time variable, expecting pause to be used as a delay, the time frame could have been missed in the test, and other more minor things.
This is tested as far as the file counting goes but not the 17:30 branch
I changed the style of a few commands and variable names (I is too much like l and i and 1 in many fonts)
#echo off
set log=C:\logs\alerting.log
:loop
for /f %%P in ('dir /b "C:\incoming\LEND*" 2^>nul ^| find /c /v "" ') do set c=%%P
set now=%time:~0,5%
echo Filecount: %c% at Time: %now%
echo Filecount: %c% at Time: %now% >> %log%
if %now:~0,2%%now:~3,2% GTR 1730 goto :OUT
ping -n 60 localhost >nul
goto :loop
:OUT
if %c% EQU 0 echo LEND Files not received >> %log%
EXIT