I tried to make a hybrid Batch-VBS script out of a VBS script that i already made. It would give a inputBox, and use the results to sapi.spvoice.Speak it. I tried to make it into a batch script (below), but it doesn't work, and tts.vbs ends up containing only
sapi.Speak message.
Batch Script:
#echo off
:start
cls
echo Batch Text-To-Speech
echo By SudDaBuilder
:: echo Fixed by %YourNameHere% ::
set /p msg=What do you want your PC to say?
set /p vce=Choose a Voice (0 - Male, 1 - Female)
pause
cls
echo Dim message, sapi, voice > tts.vbs
echo message=%msg% > tts.vbs
echo voice=%vce% > tts.vbs
echo Set sapi=CreateObject("sapi.spvoice") > tts.vbs
echo with sapi > tts.vbs
echo Set .voice = .getvoices.item(voice) > tts.vbs
echo .Volume = 100 > tts.vbs
echo end with > tts.vbs
echo sapi.Speak message > tts.vbs
cscript tts.vbs
cls
pause
:again
cls
set /p retry=Again? (y/n)
if %retry% == y goto start
goto end
:end
echo See you soon!
ping localhost > nul
You can embed the code directly into the batch script without using a temp file. This will increase the speed of the script as there will be no redundant IO operations:
<!-- : BATCH
#echo off
:start
cls
echo Batch Text-To-Speech
echo By SudDaBuilder
:: echo Fixed by %YourNameHere% ::
set /p msg=What do you want your PC to say?
set /p vce=Choose a Voice (0 - Male, 1 - Female)
pause
cscript //nologo "%~f0?.wsf" %msg% %vce%
:again
cls
set /p retry=Again? (y/n)
if %retry% == y goto start
goto end
:end
echo See you soon!
ping localhost > nul
exit /b %errorlevel%
BATCH : --->
<job><script language="VBScript">
Dim message, voice
message=WScript.Arguments.Item(0)
voice=WScript.Arguments.Item(1)
'WScript.Echo(voice & "--" & message)
set sapi = CreateObject("SAPI.SpVoice")
with sapi
Set .voice = .getvoices.item(voice)
'.Volume = 100
end with
sapi.Speak( message)
</script></job>
You even can use the sp voice objects in a one line:
#echo off
set /p "to_say=enter a text :"
mshta "javascript:code(close((V=(v=new ActiveXObject('SAPI.SpVoice')).GetVoices()).count&&v.Speak('%to_say%')))"
Simply enclose your echos in a (code block) that is redirected to a file.
The code is much easier to read then.
To not end the code block prematurely,
the closing parentheses inside have to be escaped with a caret ^)
( echo Dim message, sapi, voice
echo message=%msg%
echo voice=%vce%
echo Set sapi=CreateObject("sapi.spvoice"^)
echo with sapi
echo Set .voice = .getvoices.item(voice^)
echo .Volume = 100
echo end with
echo sapi.Speak message
) > tts.vbs
A real hybrid consists IMO of only one file.
This is also possible, but requires handling of parameters via cmd line arguments.
The `>` needs to become `>>` from the twelfth line onwards.
Why?
The > character overwrites the contents of the file and adds the specifie content, so you only end up getting the last line. Whereas, the >> character(s) adds on the specified line to the end of the file's contents.
You also need to enclose the msg and vce variables in quotations.
Fixed script:
#echo off
:start
cls
echo Batch Text-To-Speech
echo By SudDaBuilder
:: echo Fixed by SO Suda ::
set /p msg=What do you want your PC to say?
set /p vce=Choose a Voice (0 - Male, 1 - Female)
pause
cls
echo Dim message, sapi, voice > tts.vbs
:: THIS IS THE TWELFTH LINE ::
echo message="%msg%" >> tts.vbs
echo voice="%vce%" >> tts.vbs
echo Set sapi=CreateObject("sapi.spvoice") >> tts.vbs
echo with sapi >> tts.vbs
echo Set .voice = .getvoices.item(voice) >> tts.vbs
echo .Volume = 100 >> tts.vbs
echo end with >> tts.vbs
echo sapi.Speak message >> tts.vbs
cscript //NoLogo tts.vbs
cls
pause
:again
cls
:: ADDED A DELETE FOR THE tts.vbs FILE::
del tts.vbs
set /p retry=Again? (y/n)
if %retry% == y goto start
goto end
:end
echo See you soon!
ping localhost >> nul
Related
I would like to create an update function that works just after the user is prompted to type into the "ChatBox" so that other users on my school network can type and all other users can see it without having to restart the program or typing space to reload the .txt file
here is the code I have written so far;
:enter
cls
type cblog.txt
echo.
set /p text=
echo %text% >> cblog.txt
goto enter
I like this topic, so I wrote a fully working prototype:
#echo off
setlocal
if "%~1" equ "" echo You must give your username as parameter & goto :EOF
set "user=%~1"
set "now=%time%"
echo %now%: User %user% entered the chat room>> msgQueue.txt
call :chatRoom 3< msgQueue.txt
goto :EOF
:chatRoom
rem Omit previous messages
:omitMsg
set /P "msg=" <&3
if "%msg:~0,12%" neq "%now%:" goto omitMsg
echo %msg%
echo/
echo Press S to send a message or eXit to end
echo/
:msgLoop
rem Check for new messages received
:showMsg
set "msg="
set /P "msg=" <&3
if not defined msg goto send
echo %msg%
goto :showMsg
rem Check to send a new message
:send
ver > NUL
choice /C SNX /N /T 3 /D N > NUL
if errorlevel 3 goto end
if errorlevel 2 goto msgLoop
rem Send a message
echo -----------------------------------
set /P "msg=Message: "
echo -----------------------------------
echo %user%: %msg% >> msgQueue.txt
goto msgLoop
:end
echo %time%: User %user% leaved the chat room>> msgQueue.txt
The response time may be adjusted in /T 3 parameter of choice command: shorter times makes the chat more responsive, but it consume more CPU time.
Below is an image that show a test with four users in the Chat Room:
I wrote the following code:
#echo off
title Kiel Configurations
rem Credits Will Go Here
rem Website Here
color 08
echo **********************************************************************
echo **************************Kiel Configuration**************************
echo **********************************************************************
echo ======================================================================
echo Use yes/no to configure the following options
pause
cls
echo Would you like it to run in fake mode? (recommended for slow computers or for the paranoid)
set /p FakeModeVar=(yes/no):
cls
echo Would you like to close skype?
set /p SkypeVar=(yes/no):
cls
echo Woud you like to close spotify?
set /p SpotifyVar=(yes/no):
cls
echo Would you like to close steam?
set /p SteamVar=(yes/no)
cls
echo Would you like to close chrome? (reccommended)
set /p ChromeVar=(yes/no):
cls
echo Which chrome profile would you like chrome to open as? (Ask me if unsure)
set /p ChromeProfile=(1,2,3...):
cls
echo Now configurating you settings...
pause >nul
if %FakeModeVar%==yes goto Locate1
if %FakeModeVar%==no goto Locate2
:Locate1
echo yes> ConfigVarini.txt
goto Locate3
:Locate2
echo no> ConfigVarini.txt
goto Locate3
:Locate3
if %SkypeVar%==yes goto Locate4
if %SkypeVar%==no goto Locate5
:Locate4
echo yes>> ConfigVarini.txt
goto Locate6
:Locate5
echo no>> ConfigVarini.txt
goto Locate6
:Locate6
if %SpotifyVar%==yes goto Locate7
if %SpotifyVar%==no goto Locate8
:Locate7
echo yes>>> ConfigVarini.txt
goto Locate9
:Locate 8
echo no>>> ConfigVarini.txt
goto locate9
:Locate9
if %SteamVar%==yes goto Locate10
if %Steamvar%==no goto Locate11
:Locate10
echo yes>>>> ConfigVarini.txt
goto Locate12
:Locate11
echo no>>>> ConfigVarini.txt
goto Locate12
:Locate12
if %ChromeVar%==yes goto Locate13
if %ChromeVar%==no goto Locate14
:Locate13
echo yes>> ConfigVarini.txt
goto Locate15
:Locate14
echo no>>>>> ConfigVarini.txt
goto Locate15
:Locate15
if %ChromeProfile%==1 goto Locate16
if %ChromeProfile%==2 goto Locate17
if %ChromeProfile%==3 goto Locate18
:Locate16
echo 1>>>>> ConfigVarini.txt
goto End
:Locate17
echo 2>>>>>> ConfigVarini.txt
goto End
:Locate18
echo 3>>>>>> ConfigVarini.txt
goto End
:End
cls
echo Files Configured!
When i run it i want it to take the user through a configuration process then save their preferences to a text file called ConfigVarini.txt
Then i will have another program that reads the settings on the text file. However the file on says
yes yes
and it saves no other settings.
You can append to a batch file using ">>"
#echo off
echo Hi >> test.txt
echo Hello >> test.txt
echo. >>test.txt
echo 3 >> test.txt
Results in A file called test.txt containing
Hi
Hello
3
Im not sure what excatly you want besides this.
Also its good practice to leave a space before a inputting to a file since numbers from one to nine will cause problems.
Imho best practice: initially, empty your output file using
type nul> ConfigVarini.txt
and all further writing by either
(ECHO any text)>> ConfigVarini.txt
or
>> ConfigVarini.txt (ECHO any text)
Note:
no space preceding > nor >> redirection operator nor ) closing parenthesis. Otherwise, that space appears as a trailing one in output file (could be at least weird or even harmful);
() parentheses: important if output text ends with a single digit 0, 1, ..., 9 .
Explication (examples given with 1 but valid for any single decimal digit):
echo 1>> ConfigVarini.txt appends nothing (or an empty line or ECHO is on/off text) to output file as the CLI or batch parser treats a single decimal digit as the numeric file handle to be redirected (see redirection link above);
echo 1 >> ConfigVarini.txt appends 1 with trailing space;
>> ConfigVarini.txt ECHO 1 appends 1 but we can't be sure whether there is an unwanted (forgotten) trailing space;
>> ConfigVarini.txt (ECHO 1) appends 1 without trailing space;
(echo 1)>> ConfigVarini.txt appends 1 without trailing space;
More explanation and discussion here
One single > will overwrite whatever might be in ConfigVarini.txt and add only ONE line. Two >> will add another line on a new line and leave the previously written content intact. With the code below each time Locate1 or Locate2 is started old settings will be overwritten and new ones applied. (I didn't properly check all the code, only changed your flawed >> usage. Someone check and edit if needed)
#echo off
title Kiel Configurations
rem Credits Will Go Here
rem Website Here
color 08
echo **********************************************************************
echo **************************Kiel Configuration**************************
echo **********************************************************************
echo ======================================================================
echo Use yes/no to configure the following options
pause
cls
echo Would you like it to run in fake mode? (recommended for slow computers or for the paranoid)
set /p FakeModeVar=(yes/no):
cls
echo Would you like to close skype?
set /p SkypeVar=(yes/no):
cls
echo Woud you like to close spotify?
set /p SpotifyVar=(yes/no):
cls
echo Would you like to close steam?
set /p SteamVar=(yes/no)
cls
echo Would you like to close chrome? (reccommended)
set /p ChromeVar=(yes/no):
cls
echo Which chrome profile would you like chrome to open as? (Ask me if unsure)
set /p ChromeProfile=(1,2,3...):
cls
echo Now configurating you settings...
pause >nul
if %FakeModeVar%==yes goto Locate1
if %FakeModeVar%==no goto Locate2
:Locate1
echo yes > ConfigVarini.txt
goto Locate3
:Locate2
echo no > ConfigVarini.txt
goto Locate3
:Locate3
if %SkypeVar%==yes goto Locate4
if %SkypeVar%==no goto Locate5
:Locate4
echo yes >> ConfigVarini.txt
goto Locate6
:Locate5
echo no >> ConfigVarini.txt
goto Locate6
:Locate6
if %SpotifyVar%==yes goto Locate7
if %SpotifyVar%==no goto Locate8
:Locate7
echo yes >> ConfigVarini.txt
goto Locate9
:Locate 8
echo no >> ConfigVarini.txt
goto locate9
:Locate9
if %SteamVar%==yes goto Locate10
if %Steamvar%==no goto Locate11
:Locate10
echo yes >> ConfigVarini.txt
goto Locate12
:Locate11
echo no >> ConfigVarini.txt
goto Locate12
:Locate12
if %ChromeVar%==yes goto Locate13
if %ChromeVar%==no goto Locate14
:Locate13
echo yes >> ConfigVarini.txt
goto Locate15
:Locate14
echo no >> ConfigVarini.txt
goto Locate15
:Locate15
if %ChromeProfile%==1 goto Locate16
if %ChromeProfile%==2 goto Locate17
if %ChromeProfile%==3 goto Locate18
:Locate16
echo 1 >> ConfigVarini.txt
goto End
:Locate17
echo 2 >> ConfigVarini.txt
goto End
:Locate18
echo 3 >> ConfigVarini.txt
goto End
:End
cls
echo Files Configured!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 months ago.
Improve this question
Can I lock or set a password to a batch file/script, I have made a script but I don't want people on my work to change it. They must be able to run it but not edit it.
Is this possible and how?
I have search for it but I can't find it. I find all about how to lock PC or something else but not my batch file/script and the Q is not how to hide my script or something but if you whant to edit it, it gives a error or if you click on edit it don't work.
If you don't want them to be able to commit changes to the file, just set the file permissions, only allowing you (or some admin group) to modify the file.
This command will remove inherited ACL entries, grant you full permission, and grant everyone else read permission:
icacls your_file.cmd /inheritance:r /grant youruserid:F /grant everyone:RX
It's not possible however you can use this trick make a c/c++ program that simply call those cmds from system() function. In this case you commands will be hidden to some extent and they won't be able to change it.
One word more about this topic.
It is not possible to avoid that others have access to your Batch file; however, if you want to avoid that others can review the Batch file contents (so they can't modify any part of it) then there are several ways to do that including converting the file to .exe format, although no one of these methods gives complete protection against determined users.
The point here is to use a method simple enough for you, so you may implement it with no problems, but complex enough for others so it dissuade your users to try to break it. I propose a solution based on the Encode procedure for JScript source programs that is not a widely known method, so it may even gives protection against advanced users that have not the appropriate information about it. Here it is:
#if (#CodeSection == #Batch) #then
#echo off
setlocal DisableDelayedExpansion
REM Obfuscate.bat: Obfuscate Batch files
REM Antonio Perez Ayala
if "%~1" equ "" echo Usage: Obfuscate filename.bat & goto :EOF
if not exist "%~1" echo File not found: "%~1" & goto :EOF
set "at=#"
set "pass=%random%"
(
echo %at%if (#Pass == #X%pass%^) #begin
echo #echo off
echo CScript //nologo //E:JScript.Encode "%%~F0" ^> %pass%.bat
echo call %pass%
echo del %pass%.bat
echo exit /B
echo %at%end
echo //**Start Encode**
echo var a = new Array(^);
set "i=0"
for /F "usebackq delims=" %%a in ("%~1") do (
set /A i+=1
set "line=%%a"
setlocal EnableDelayedExpansion
echo a[!i!] = '!line:'=\x27!';
endlocal
)
setlocal EnableDelayedExpansion
echo for ( var i=1; i^<=!i!; ++i ^) WScript.Stdout.WriteLine(a[i]^);
) > "%~N1.tmp"
CScript //nologo //E:JScript "%~F0" "%~N1.tmp"
del "%~N1.tmp"
goto :EOF
#end
// Encode a JScript source file
// Antonio Perez Ayala
var fileToEncode = WScript.Arguments(0);
// Read the source file
var oFSO = WScript.CreateObject("Scripting.FileSystemObject");
var oFile = oFSO.GetFile(fileToEncode);
var oStream = oFile.OpenAsTextStream(1);
var sSourceFile = oStream.ReadAll();
oStream.Close();
// Encode the file
var oEncoder = WScript.CreateObject("Scripting.Encoder");
var sDest = oEncoder.EncodeScriptFile(".js",sSourceFile,0,"")
// Write the encoded version
var sFileOut = fileToEncode.slice(0,-3)+"obf.bat";
var oEncFile = oFSO.CreateTextFile(sFileOut);
oEncFile.Write(sDest);
oEncFile.Close();
Copy this program as Obfuscate.bat and use it giving your Batch file in the parameter; after that, a new file with .obf.bat extension is created that works in the same way than the original file, but with its contents encoded in an unreadable way. For example:
C:\> type test.bat
#echo off
echo Hello World
C:\> Obfuscate test.bat
C:\> type test.obf.bat
#if (#Pass == #X20203) #begin
#echo off
CScript //nologo //E:JScript.Encode "%~F0" > 20203.bat
call 20203
del 20203.bat
exit /B
#end
//**Start Encode**##~^kQAAAA==###&\CMPmP',x⌂APzD.lH`bI###&l]qT,'PE#$nm4W,WW0vI##
#&C$yDP{Pvn1tW~u⌂VsW, KDs9Bp###&6WM~`,\CD,kxqpPk#!x pP_3r~#,⌂Um.k2Oc?ONK;Yc⌂.r
D+SrU⌂`C$bD*i###&kiYAAA==^#~#
C:\> test.obf.bat
Hello World
I tested this method in Windows XP and Windows 8.
Short answer: No
Long answer: No, it's not possible
You can obfuscate it, but you can't hide the source.
Somehow cmd.exe has to execute your batch, so it has to see the commands, but when cmd.exe can see your commands, then a person can see them also.
As you only want to lock the file for editing you can use the both mentioned ways:
Then using attrib could solve it with adding readonly or hidden attributes (like #JanDoggen mentioned).
Or the more secure way by changing the security settings (like #mstth mentioned)
But this will only prevent changes from absolutly noobs.
I tried to make this in batch. I suppose this file could be somewhat helpful, it uses a encrypted password method. You could wrap the batch file into a encrypted exe file, also if you wanted the code obfuscated, possibly even an added byte order mark to make it harder for other people to get your password just ask and I will do that for you. Also you can automatically set the file by doing this ; Go to the "PasswordOptions.bat" file after it is created, set your password, un-hide password files, open then password folder, copy and paste the "Pswrd.Zask" & "Key.Zask" files in a different folder and use the contents for later use, lastly reset your password.
#echo off
title Zask's password encrypted batch file
color 0a
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º Zask's password encrypted batch file º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
if not exist "C:\Pswrd.Zask\" (
mkdir "C:\Pswrd.Zask\"
if "!errorlevel!" EQU "0" (
goto DirectoryExist
) else (
echo Created the folder "C:\Pswrd.Zask" & timeout /t 5 /nobreak
)
) else (
goto DirectoryExist
)
:DirectoryExist
if exist C:\Pswrd.Zask\Key.Zask (
goto UsernameExist
) else (
goto CreatePasswordScreen
)
:UsernameExist
for /f "Delims=" %%A in (C:\Pswrd.Zask\Password.Zask) do (
set CHECKPASSWORD=%%A
)
for /f "Delims=" %%B in (C:\Pswrd.Zask\Key.Zask) do (
set CHECKKEY=%%B
)
goto PasswordScreen
:CreatePasswordScreen
cls
echo Create a password.
echo.
setlocal EnableDelayedExpansion
set /p "CREATEPASSWORD= Enter password : "
set /p "CREATEKEY= Enter a key number (Choose a number 2-200) : "
set CHAR=0123456789bhfcjrwmudaxopvntzlqeisykg
for /l %%C in (10 1 36) do (
for /f %%D in ("!CHAR:~%%C,1!") do (
set /a MATH=%%C*%CREATEKEY%
for /f %%E in ("!MATH!") do (
set "CREATEPASSWORD=!CREATEPASSWORD:%%D=-%%E!"
)
)
)
echo %CREATEPASSWORD% >> C:\Pswrd.Zask\Password.Zask
attrib C:\Pswrd.Zask\Password.Zask +s +h & echo. & echo Password Created!
echo %CREATEKEY% >> C:\Pswrd.Zask\Key.Zask
attrib C:\Pswrd.Zask\Key.Zask +s +h & echo Username Created!
echo.
if exist "%~dp0ResetPassword.bat" (
del "%~dp0ResetPassword.bat" )
:ResetPassword
set /p "RESETOPTION=Would you like to create the password options file in the current directory (Y/N)? : "
if /i %RESETOPTION%==Y goto ResetOptions
if /i %RESETOPTION%==N goto SkipResetOptions
:ResetOptions
echo #echo off >> PasswordOptions.bat
echo title ResetPassword.bat >> PasswordOptions.bat
echo color 0a >> PasswordOptions.bat
echo :start >> PasswordOptions.bat
echo. >> PasswordOptions.bat
echo echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» >> PasswordOptions.bat
echo echo º This file is used to reset your password, hide it for future purposes or delete it º >> PasswordOptions.bat
echo echo º to avoid other users from removing your password. You have 5 options º >> PasswordOptions.bat
echo echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ >> PasswordOptions.bat
echo echo. >> PasswordOptions.bat
echo echo 1 - Reset password. >> PasswordOptions.bat
echo echo 2 - Open password folder. >> PasswordOptions.bat
echo echo 3 - Unhide files in the password folder. >> PasswordOptions.bat
echo echo 4 - Hide files in the password folder. >> PasswordOptions.bat
echo echo 5 - Exit dialog. >> PasswordOptions.bat
echo echo. >> PasswordOptions.bat
echo set /p "OPTIONS=Chose a number to select that option : " >> PasswordOptions.bat
echo if %%OPTIONS%%==1 goto PasswordReset >> PasswordOptions.bat
echo if %%OPTIONS%%==2 start C:\Pswrd.Zask ^& cls ^& goto start >> PasswordOptions.bat
echo if %%OPTIONS%%==3 attrib C:\Pswrd.Zask\Password.Zask -s -h ^& attrib C:\Pswrd.Zask\Key.Zask -s -h ^& cls ^& goto start >> PasswordOptions.bat
echo if %%OPTIONS%%==4 attrib C:\Pswrd.Zask\Password.Zask +s +h ^& attrib C:\Pswrd.Zask\Key.Zask +s +h ^& cls ^& goto start >> PasswordOptions.bat
echo if %%OPTIONS%%==5 exit >> PasswordOptions.bat
echo. >> PasswordOptions.bat
echo :PasswordReset >> PasswordOptions.bat
echo cls >> PasswordOptions.bat
echo set /p "RESET=Are you sure you want to reset your password (Y/N)? : " >> PasswordOptions.bat
echo if /i %%RESET%%==Y goto ResetPassword >> PasswordOptions.bat
echo if /i %%RESET%%==N goto start >> PasswordOptions.bat
echo cls >> PasswordOptions.bat
echo. >> PasswordOptions.bat
echo :ResetPassword >> PasswordOptions.bat
echo rd /s /q "C:\Pswrd.Zask" >> PasswordOptions.bat
echo echo Password was deleted! >> PasswordOptions.bat
echo pause >> PasswordOptions.bat
echo del %%~n0%%~x0 >> PasswordOptions.bat
echo exit >> PasswordOptions.bat
cls
echo. & echo Created file "%~dp0ResetPassword.bat" & timeout /t 5 /nobreak
:SkipResetOptions
start %~n0%~x0
exit
:PasswordScreen
color 0a
cls
echo Existing User Account.
echo.
setlocal EnableDelayedExpansion
set /p "PASSWORD= Enter Password : "
set /p "KEY= Enter the original encryption key : "
set CHAR=0123456789bhfcjrwmudaxopvntzlqeisykg
for /l %%C in (10 1 36) do (
for /f %%D in ("!CHAR:~%%C,1!") do (
set /a MATH=%%C*%CHECKKEY%
for /f %%E in ("!MATH!") do (
set "CHECKPASSWORD=!CHECKPASSWORD:%%E=%%D!"
)
)
)
for /f %%F in ("!CHECKPASSWORD!") do (
set "CHECKPASSWORD=!CHECKPASSWORD:-=!"
)
if %PASSWORD%==%CHECKPASSWORD% (
goto Operation1True
) else (
goto OperationFalse
)
:Operation1True
if %KEY%==%CHECKKEY% (
goto Operation2True
) else (
goto OperationFalse
)
:OperationFalse
color 0c
echo Password Incorrect!
timeout /t 10 /nobreak
goto PasswordScreen
:Operation2True
cls
echo Password Correct!
echo.
pause
REM YOUR CODE GOES HERE.
REM YOU CAN CONVERT THIS IS INTO A EXE FILE IF WANTED.
REM FREE TO MODIFY ANY CONTENT IN THIS FILE FOR BUSINESS OR PERSONAL REASONS.
You could set an attribute at the beginning of the file like this:
#echo off
attrib +R
If your users are not very sophisticated maybe you can hide your batch file and call it from another one:
One.bat
#echo off
two
Two.bat
#echo off
echo this is 2
pause
Set attributes of two.bat to -h (and maybe -r).
Then call one.bat. Just tested this under Win7 and to my surprise it works.
But this does not solve your issue if the people at your work know how to change file attributes.
I wrote a windows batch script to check and move files to another directory based on the list I put in a notepad file named list.txt. But I have no idea that how to set the while-loop. Only to jump out of the subroute when the condition fulfill.
In C Programming, we could write like this by setting a while-loop direcly. But seems in windows batch is quite different.
All I want is like this:
Directory A:
1. A.txt
2. B.txt
3. list.txt (By line sequential with filename want to move)
4. process.bat
Directory B:
None of files (Then move a file by order of line set in list.txt) OR
A.txt (If already existed a text file in directory, process.bat will pause before A.txt disappear)
Process.bat
#echo off
:readline
for /f "tokens=*" %%a in (list.txt) do call :processline %%a
goto :eof
:processline
if exist D:\DirectoryA\*.txt (
echo %time% >> D:\AutoLog\Log.txt
echo Previous job did not finished yet. >> D:\AutoLog\Log.txt
Timeout /t 30
echo.
)
set name=%*
if exist %name%.txt (
echo %time% >> D:\AutoLog\Log.txt
echo File found and processing %name%.txt now... >> D:\AutoLog\Log.txt
copy "%~dp0\%name%.txt" "D:\DirectoryB"
echo Transfer %name%.txt completed!! >> D:\AutoLog\Log.txt
echo. >> D:\AutoLog\Log.txt
Timeout /t 790
echo.
echo ==============================================================
)
:eof
Please guide me to finish the script by using a while-loop method. Thanks
I change some script sequence and it works now.
#echo off
:readline
for /f "tokens=*" %%a in (list.txt) do call :processline %%a
goto :eof
:processline
set name=%*
if exist C:\Test2\*.txt (
echo %date% %time% >> C:\Test2\Log.txt
echo Previous job did not finished yet. >> C:\Test2\Log.txt
Timeout /t 5
echo.
echo. >> C:\Test2\Log.txt
goto :processline
)
if exist %name%.txt (
echo %date% %time% >> C:\Test2\Log.txt
echo File found and processing %name%.txt now... >> C:\Test2\Log.txt
copy "%~dp0\%name%.txt" "C:\Test2"
echo Transfer %name%.txt completed!! >> C:\Test2\Log.txt
echo. >> C:\Test2\Log.txt
Timeout /t 10
echo.
echo ==============================================================
)
:eof
This will copy as well as count the number of lines from your text file..
# echo off
:TextPath
cls
set /p Input=#1 Enter the full path of the text file :
set /p Source=#2 Enter the full path of Source :
set /p Target=#3 Enter the full path of Destination :
:choice
set /P c=Ready to Continue[Y/N]?
if /I "%c%" EQU "Y" goto :Yes
if /I "%c%" EQU "N" goto :No
goto :choice
:Yes_Local
for /f "delims=" %%i in (%Input%) do echo f| xcopy /f /y "%Source%\%%i" "%Target%\%%i"
for /f %%C in ('Find /V /C "" ^< %Input%') do set Count=%%C
msg * No of Lines executed= %Count%
exit
:No
cls
color e
echo Redirecting to Main....
PING 127.0.0.1 -n 2 >NUL
cls
echo Please wait
PING 127.0.0.1 -n 4 >NUL
goto TextPath
About 3 days ago I asked a question, which can be found here:
how to replace a string on the second line in a text file using a batch file?
I'm converting the letters in a text file into their respective numbers. I'm getting error messages such as "Access denied" and "Cannot locate this file" -- but the same batch file that's giving me all these errors is also the one that made these text files to begin with! So it should be in the same directory as the batch file itself (unless specified otherwise), right? I even went to that folder and checked, and they're there.
I did add a small script to hide the files after they were created so that it wouldn't look so cluttered up. I did this by using
attrib +h C:\script\%name%.txt
Would hiding a file with this command make it invisible to batch programs that are searching for it/call upon it?
Here's a link to the file, "stringparsing.bat": http://uploading.com/files/a1m1d2f4/stringparsing.bat/
If you could assist me in getting this program to carry out its task without any errors it would be greatly appreciated!
Here's the "stringparsing.bat" file in full:
#echo off
setlocal enabledelayedexpansion
title BETA
cls
cd C:\script\st
echo.
echo.
echo.
echo Setting Variables...
echo Loading Language Database...
:: ###################################################################################
:: CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:MAIN
set foo=0
cls
echo.
echo.
echo.
echo.
echo ===================================
echo #################################
echo ####### Main Menu: #######
echo #################################
echo ===================================
echo.
echo.
echo 1.) Create New Language File...
echo.
echo 2.) Load Existing Lanuage File...
echo.
echo 3.) Settings...
echo ---------------------------------------------------------
SET /p CHOICE= Select a Function:
IF %CHOICE%== 1 GOTO CREATE
IF %CHOICE%== 2 GOTO LOAD
IF %CHOICE%== 3 GOTO SETTINGS
GOTO MAIN
:CREATE
cls
title Step 1
echo.
echo.
echo.
echo =================================================================================
echo.
set /p name= please type a name for your new language file:
echo.
echo =================================================================================
cls
echo. > %name%.txt
echo.
echo.
echo.
echo ==============================================================
echo ##############################################################
echo #============================================================#
echo # #
echo # - After you hit enter you will be redirected #
echo # to a Live Typer. so anything you type into #
echo # it will be sent to %name%.txt. #
echo # #
echo # #
echo # - Next, select load language File For Encoding! #
echo # #
echo #============================================================#
echo ##############################################################
echo ==============================================================
set /p line1= :
echo %line1% >> %name%.txt 2> nul
echo %name% > Language_File.txt
attrib +h Language_File.txt
set /a foo+ =1
)
echo.
echo ==========================================================
goto LOAD
:LOAD
set /a foo+ =1
IF %foo%== 2 goto loadexternal
goto LOAD23
:loadexternal
echo.
echo language file is loading now!
set /p name=<Language_File.txt
timeout /t 4 /nobreak > nul
echo.
echo.
echo Language_File Loaded!
pause >nul
goto LOAD23
:LOAD23
cls
echo.
echo.
echo.
echo.
echo.
echo Encoding Your Language File... Please Wait...
echo.
echo.
echo.
for /f "delims=" %%i in (!name!.txt) do (
echo translating "%%i"
set var=%%i
set var=!var:a=1 !
set var=!var:b=2 !
set var=!var:c=3 !
set var=!var:d=4 !
set var=!var:e=5 !
set var=!var:f=6 !
set var=!var:g=7 !
set var=!var:h=8 !
set var=!var:i=9 !
set var=!var:j=10 !
set var=!var:k=11 !
set var=!var:l=12 !
set var=!var:m=13 !
set var=!var:n=14 !
set var=!var:o=15 !
set var=!var:p=16 !
set var=!var:q=17 !
set var=!var:r=18 !
set var=!var:s=19 !
set var=!var:t=20 !
set var=!var:u=21 !
set var=!var:v=22 !
set var=!var:w=23 !
set var=!var:x=24 !
set var=!var:y=25 !
set var=!var:z=26 !
echo !var!
)
echo !var! > !name!.txt
pause >nul
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo Terminating service stream...
echo.
echo.
echo.
echo.
echo Done! Thank you for using this program!
TIMEOUT /t 5 /nobreak > nul
::(%xx%) -1 I/O Stream= "SHELL.dll"
:: IF EXIST [&1[Parser_2009]] exit
Exit
:: #####################################################################################
You've got a few problems. First, the access denied problem is from you redirecting to a hidden file.
echo %name% > Language_File.txt
attrib +h Language_File.txt
Note that the first time you run the script, it will work because Language_File.txt won't exist and therefore won't be hidden. The second time you run it, you'll get access denied. I don't know why Windows doesn't let you do that. You can solve this problem in a couple ways.
1. Save your file to the user's temp directory. With this approach your directory won't get cluttered.
echo %name% > %TMP%\Language_File.txt
2. Save your file to a subdirectory that you own so that it doesn't clutter the script's directory.
if not exist workspace mkdir workspace
echo %name% > workspace\Language_File.txt
3. Unhide the file before you use it. Since the file may not exist the first time you run the script, perhaps you should only attrib -h if it exists.
if exist Language_File.txt attrib -h Language_File.txt
echo %name% > %TMP%\Language_File.txt
attrib +h Language_File.txt
4. Don't use Language_File.txt at all! I don't see why you need it. Just use variables to hold the name of the language file. In fact, you already have the name in %name%, right?
Second, you should check the value of your variables to see what they really hold. When you load the contents of Language_File.txt into your variable, it's loading all the contents. That includes the hidden newline characters \r\n, although the script seems to bring them into the variable as spaces. See:
c:\batch\t>echo language file is loading now!
language file is loading now
C:\batch\t>set /p name= <Language_File.txt
C:\batch\t>echo -%name%-
-langfile -
If you echo %name% surrounded by hyphens, you can see that there are 2 spaces after it from (presumably) the newline characters. To solve this problem, you can use set to trim the trailing characters.
C:\batch\t>echo language file is loading now!
language file is loading now
C:\batch\t>set /p name= <Language_File.txt
C:\batch\t>set name=%name:~0,-2%
C:\batch\t>echo -%name%-
-langfile-
In the second example, `%name% doesn't have the hidden characters.
Finally, you only need to use ! to access variables that you set inside the for loop. So all references to !name! should be %name% instead. That's probably your "cannot find file" error.
heres the "stringparsing.bat" file:
#echo off
setlocal enabledelayedexpansion
title BETA
cls
cd C:\script\st
echo.
echo.
echo.
echo Setting Variables...
echo Loading Language Database...
:: ###################################################################################
:: CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:MAIN
set foo=0
cls
echo.
echo.
echo.
echo.
echo ===================================
echo #################################
echo ####### Main Menu: #######
echo #################################
echo ===================================
echo.
echo.
echo 1.) Create New Language File...
echo.
echo 2.) Load Existing Lanuage File...
echo.
echo 3.) Settings...
echo ---------------------------------------------------------
SET /p CHOICE= Select a Function:
IF %CHOICE%== 1 GOTO CREATE
IF %CHOICE%== 2 GOTO LOAD
IF %CHOICE%== 3 GOTO SETTINGS
GOTO MAIN
:CREATE
cls
title Step 1
echo.
echo.
echo.
echo =================================================================================
echo.
set /p name= please type a name for your new language file:
echo.
echo =================================================================================
cls
echo. > %name%.txt
echo.
echo.
echo.
echo ==============================================================
echo ##############################################################
echo #============================================================#
echo # #
echo # - After you hit enter you will be redirected #
echo # to a Live Typer. so anything you type into #
echo # it will be sent to %name%.txt. #
echo # #
echo # #
echo # - Next, select load language File For Encoding! #
echo # #
echo #============================================================#
echo ##############################################################
echo ==============================================================
set /p line1= :
echo %line1% >> %name%.txt 2> nul
echo %name% > Language_File.txt
attrib +h Language_File.txt
set /a foo+ =1
)
echo.
echo ==========================================================
goto LOAD
:LOAD
set /a foo+ =1
IF %foo%== 2 goto loadexternal
goto LOAD23
:loadexternal
echo.
echo language file is loading now!
set /p name=<Language_File.txt
timeout /t 4 /nobreak > nul
echo.
echo.
echo Language_File Loaded!
pause >nul
goto LOAD23
:LOAD23
cls
echo.
echo.
echo.
echo.
echo.
echo Encoding Your Language File... Please Wait...
echo.
echo.
echo.
for /f "delims=" %%i in (!name!.txt) do (
echo translating "%%i"
set var=%%i
set var=!var:a=1 !
set var=!var:b=2 !
set var=!var:c=3 !
set var=!var:d=4 !
set var=!var:e=5 !
set var=!var:f=6 !
set var=!var:g=7 !
set var=!var:h=8 !
set var=!var:i=9 !
set var=!var:j=10 !
set var=!var:k=11 !
set var=!var:l=12 !
set var=!var:m=13 !
set var=!var:n=14 !
set var=!var:o=15 !
set var=!var:p=16 !
set var=!var:q=17 !
set var=!var:r=18 !
set var=!var:s=19 !
set var=!var:t=20 !
set var=!var:u=21 !
set var=!var:v=22 !
set var=!var:w=23 !
set var=!var:x=24 !
set var=!var:y=25 !
set var=!var:z=26 !
echo !var!
)
echo !var! > !name!.txt
pause >nul
TIMEOUT /t 5 /nobreak > nul
goto MAIN
:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo Terminating service stream...
echo.
echo.
echo.
echo.
echo Done! Thank you for using this program!
TIMEOUT /t 5 /nobreak > nul
::(%xx%) -1 I/O Stream= "SHELL.dll"
:: IF EXIST [&1[Parser_2009]] exit
Exit
:: #####################################################################################
I Finally learned how to format the code snippet.
(heres a link to another copy of it if you need it.)
how to replace a string on the second line in a text file using a batch file?