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.
Related
I have legal .strm files of different TV Shows in a folder named TV Shows. Each strm file of each episode is stored in different subfolders.
I would like to run a certain VBScript before these strm files are played.
Then I have a different folder named MOVIES. Again, I would like to run a VBScript before these strm files are played. But this VBScript is a different one.
How would I do that?
Platform is Windows.
Thanks!
If you're looking to open or do something to each file based on extension, An easy way to do this is to use an for loop with /R to search all sub-directories for an *.strm file.
#ECHO OFF
SET "LOC=C:\Folder"
CD %LOC%
FOR /R %%A IN (*.strm) DO (
Rem | Do something with each file.
Start cmd.exe /C "notepad.exe "%%A""
)
Echo No More Items Found!
pause
goto :EOF
%%A will return the file path.
Start cmd.exe /C "" will start a CMD command. (Replace with your code)
notepad.exe "" will open the file (Used as an example)
EDIT:
So you're looking to check if the file exists then if true run the script? Bellow should solve that.
#ECHO OFF
If exist (C:/Path/file.strm) (
Rem | File exists, run script
Echo Do something
)
GOTO :EOF
I have created login script using batch file. But actually I need this batch runs invisible (but still showing on the task manager).
As far that I can go is that I only able to minimize the batch file using below code:
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
#echo off
echo *Logon Script*
rem :Time_Set
rem echo Setting the system time...
rem net time \\EX001LT /set /y
rem echo.
I have tried using cmd /c "batchfile" and didn't work.
You can use vbs to hide the batch completely. Add the path to the logon script to MyScript.Run line.
Hidden.vbs
Set MyScript = CreateObject("WScript.Shell")
MyScript.Run "C:\path to batch\logonscript.cmd", 0, False
Then simply call the Hidden.vbs file instead of the batch file
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
i want to watch a folder on my Win7 64bit Machine for new pdf files - and print them autmatically when there is a pdf file in the folder. After printing, the pdf file should be moved in a subfolder. So, after some google research i did a small batch file.
cd "D:\print"
for %%i in (*.pdf) do (
"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" /print "%%i"
timeout /T 10 /nobreak
move D:\print\*.pdf D:\print\printed
echo %%i
)
I stored this in folder d:\print as print.cmd . When i start the cmd by doubleclick, my printer starts working and the pdf file moves to the subfolder i defined (D:\print\printed).
To watch the folder, i had the idea to create a sheduled task that repeat this cmd-script all 5 minutes.
BUT:
This dont work, when the script is started via scheduled tasks, the printer is not working - the "movement" of the file instead, is working.
I entered in the scheduled task:
Program: C:\Windows\SysWOW64\cmd.exe
Argument: /c"d:\print\print.cmd"
Any idea, why i cant acces the printer via the scheduled task?
The printer is connected via usb.
Hope i could provide necessary information! Thanks for your answers!
Change this line: move D:\print\*.pdf to move /Y D:\print\%%i
Point the scheduled task to actually start your batch file instead of calling cmd and putting the path to your script in the arguments.
You could also edit the batch file and code it to loop every 5 minutes so you only have to start it once:
PushD %~dp0
:start
for %%i in ("D:\print\*.pdf") do (
"C:\Program Files\Tracker Software\PDF Viewer\PDFXCview.exe" /print "%%i"
move /y "%%i" "D:\print\printed"
echo %%i
)
timeout /T 300 /nobreak
goto start
I'm publishing content to autogenerated folders and after the publishing has finished I want to copy files to that folder based on the foldersname using a batch
The autogenerated folders always have a language name, for example German, Dutch, French and English.
What I want my batch to do is that when the folder name is German it copies all the files from C:\Sourcefolder\DE\ to the new generated folder I'm running the batch from. I've tried to find something myself but my lack of knowledge results in this:
CHDIR /D %1
#ECHO OFF
SETLOCAL
SET "sourcedir=%cd%"
IF "%1"=="German" goto :German
:German
xcopy /Y "C:\Sourcefolder\DE\*.jpg" "%1"
GOTO :EOF
Is there anyone who can help me in the right direction?
Thanks in advance!
Here is the code for a batch file which might do what you want.
#echo off
rem Is this batch file called without any parameter?
if "%~1"=="" (
echo.
echo Run %~nx0 with language as first parameter.
echo.
echo Example: %~nx0 English
echo.
pause
goto :EOF
)
if /I "%~1"=="German" set "ShortName=DE" & goto CopyFiles
if /I "%~1"=="English" set "ShortName=EN" & goto CopyFiles
rem This batch file was called with a (language) string not listed above.
echo.
echo Error: "%~1" is not a supported language.
echo.
pause
goto :EOF
:CopyFiles
rem Copy all JPEG files of the specified language from source folder
rem to the specified language folder in current working directory.
xcopy /H /I /K /Q /R /Y "C:\SourceFolder\%ShortName%\*.jpg" "%~1"
set "ShortName="
Some notes additionally to the comments in the batch code:
%~1 is replaced by cmd.exe on execution of the batch file with the string of first parameter with removing double quotes if batch file was called for example with "English" instead of just English as first parameter.
If you want to know more about %~1 or %~nx0 (name of batch file with extension but without drive and path), open a command prompt window, run there call /? and read help output for this command.
/I option of command if makes the string comparison case-insensitive.
The ampersand in set "ShortName=DE" & goto CopyFiles concatenates the two commands set and goto on a single line which makes it possible here to specify 2 commands for each if without using parentheses. See Conditional Execution for details about this special operator.
For details on the switches used on command xcopy run in a command prompt window xcopy /? and read output help.
By the way: The batch files copies the JPEG files into specified language subfolder of current working directory. The current working directory can be the directory the batch file is stored, but can be also a different directory depending on how batch file was started and from which directory. If you want to make sure that the JPEG files are copied into specified language subfolder of batch file directory, you would need for the line with xcopy:
xcopy /H /I /K /Q /R /Y "C:\SourceFolder\%ShortName%\*.jpg" "%~dp0%~1"