"Access is denied." in batch file when hiding user input - batch-file

Where I work, I maintain some sensitive data that I like to be able to backup at the click of a batch file. This batch file scans through the files and only copies new and modified files, and deletes files that are no longer in the source. It is probably overkill, but I'm paranoid, so I wanted to mask my input when I type in the password for this script. I found this
echo hP1X500P[PZBBBfh#b##fXf-V#`$fPf]f3/f1/5++u5>hide.com
on the internet, and incorporated it, and it does exactly what I wanted it to do. The only problem is that right above where I enter the password, it says "Access is denied." I have it narrowed down to the line above, but I cannot figure out why it says
"Access is denied. Enter password:"
Here is my entire script:
#echo off
Title blahblahblah
echo This batch file is designed to backup the "blahblahblah" folder.
echo Upon entering the correct password, all new or modified files and directories
echo will be backed up in drive:\destination. If you want to quit, type exit.
echo WARNING: Any files deleted from the source will be deleted from the destination!
echo ---
echo hP1X500P[PZBBBfh#b##fXf-V#`$fPf]f3/f1/5++u5>hide.com
:retry
set /p password=Enter password: <nul
for /f "tokens=*" %%i in ('hide.com') do set password=%%i
if /i %password%==blahblahblah goto main
if /i %password%==exit goto exit
cls
echo Try again. You are not logged in!
goto retry
:main
robocopy "drive:\source" "drive:\destination" /E /Purge
del %USERPROFILE%\Desktop\hide.com
pause
Any help with this would be much appreciated. I don't know if I'm the only one getting the message, or just the only one who is annoyed by it, but I will fully admit that I am not savvy enough at this to be able to decipher that line of code.

It seems, you are starting your batchfile in a directory without write access (for example starting it as administrator would do that)
Try this line:
echo hP1X500P[PZBBBfh#b##fXf-V#`$fPf]f3/f1/5++u5>%USERPROFILE%\Desktop\hide.com
PS: the desktop might not be the best place to hide a file.

Related

How to copy file from file location list in Batch?

If you don't want to read the whole story, you can skip to the next paragraph.
So I found a YouTube video of how to make file in usb drive to autorun when the usb is inserted. Then I found and program that shows you all passwords saved in the browser (these passwords are stored in a database file on your computer). So the program gets the file with the passwords and writes them on another file. But the problem is that the antivirus is blocking it every time. It's saying that there is unwanted app and I have to allow it.
So I started writing my own code:
#echo off
setlocal
rem change to the correct directory
cd /d C:\Users\MyName\AppData\Local\Microsoft\Edge
rem count the files
dir /b "Login Data" /s 2> nul | find "" /v /c > %temp%\count
set /p _count=<%temp%\count
rem cleanup
del %temp%\count
rem output the number of files
echo Files found : %_count%
rem list the files
echo Files Paths :
dir /b "Login Data" /s > D:\Folder\dir.txt
pause
endlocal
So what this does is finding all the files with specific name and writes their paths to a txt file. But I can't seem to understand how to make it reading these paths from the file and copying the files to the usb drive.
The count and pause functions are just to know if the program is really finding all the files called "Login Data"
I watched YouTube tutorials, searched in google, asked friends and nothing worked.
You could use the for command to handle each file found by the dir command. Note the for documentation (for /?), %%i will only work in batch files, at command line you would use %i instead.
for /f %%i in ('dir /b "Login Data" /s') do copy "%%i" "f:\path\"
f:\path\ would be the target path at the USB drive.
On the other hand you do not need the dir command as the copy command can filter by itself. Bye the way I do not understand the filter Login Data as is seems to be only one file. Eg. dir "Login Data*" would result in a list of files starting with "Login Data".

Renaming file using batch over network

I am working on creating a backup program using python and batch scripts. The entire program will work if I don't have the program export a copy of the incremental backup to a shared network folder(I want to have redundancy so I have it save to server and two other terminals). I can manually go into cmd prompt and type out the ren cmd and it will do it without any issue. The problem arises when I attempt to use a variable with the ren cmd.
Example of set /p
REM Load text file with first variable
set loadDD002=C:\Backup\Bin\DD002.txt
SET /p back1Directory=<%LoadDD002%
REM Show the Defined Variable
echo back1Directory
Example of contents of DD002.txt
//SERVER/NetShare
example of cleanup/renaming
del "%back2Directory%\backup7.zip"
ren "%back2Directory%\backup6.zip" backup7.bak
ren "%back2Directory%\backup5.zip" backup6.zip
ren "%back2Directory%\backup4.zip" backup5.zip
ren "%back2Directory%\backup3.zip" backup4.zip
ren "%back2Directory%\backup1.zip" backup2.zip
ren "%back2Directory%\backup.zip" backup1.zip
Error receiving
The syntax of the command is incorrect
I apologize for any editing faux pas as I am very new to this site.
Thank you,
Nvm.. I figured it out. See below:
set "network1=%back1Directory:* =%
Then
set "network1=%back1Directory:* =%
WOOO

Batch program, runs a program, opens a file, new version opens a main directory to open sub directory file

im having a little issue, I currently made a simple batch script to open this program and a specific file so that users dont have to go into the directory and open it that way, they only enter the file folder name and file name and it opens that specific file straight away, however I need it so that the user enters just the file name, I will show the simple working version which you have to type in the folder name aswell. I will also show the version I am trying to get to work without having to type the folder name, however the if statement is not working as it always runs both parts of it.
#echo off
set /p id2=Enter folder name for the label.
echo %id2%
set /p id=Enter Label Code, please use this format E.G. AA-01:
echo %id%
Start "" "C:\Program Files (x86)\EuroPlus\NiceLabel 6\bin\NicePrint.exe" "J:\MYFOLDER\%id2%\%id%.lbl"
^ This is the working version however it is tedious as you have to type the folder name.
#echo off
set STARTDIR="J:\MYFOLDER"
set /p id=Enter Label Code, please use this format E.G. AA-01:
echo %id%
for /f "delims=" %%a in ('dir /s /b "J:\MYFOLDER"') do echo %%a
if exist %id% in ('dir /s /b "J:\MYFOLDER"') (
echo File found, starting NicePrint.
/! set current folder where file was found
The file path is %~dp1
Start "" "C:\Program Files (x86)\EuroPlus\NiceLabel 6\bin\NicePrint.exe" "J:\MYFOLDER\%~dp1\%id%"
) else exit
pause
Problems with the second part: If statement always prints file found starting nice print even if user input doesnt match a file and launches the program, further more, I need the directory of that file from this so that I can then set the program to launch that file after it starts as you can see I have attempted but I am still a novice to things like this as I am not too good at programming/scripting etc.
Thank you for help in advance.

Create Batch File that prompts user for File path in DOS 6.22

I am trying to create a .BAT file in DOS 6.22 that will copy the contents of a floppy disk in A: over to C:\ and then set the folder created as a system variable. I tried using something like "SET /P VARIABLE=Enter a path" however DOS will just add "/P VARIABLE" as a variable with the value of "Enter a path" so using the /P isn't an option as /P wasn't a switch in DOS 6.22
I tried using something like a for loop to set a variable to the file however where I hit a speed bump is that I have no idea what the folder is going to be called in drive A:\ as it will change all the time but only ever contain one folder, so basically I am just trying to find a way a way to copy the first directory found in drive A over to C:\ and set that as a system variable. As once the user is done making changes I will have to copy that folder back over to A:\ and overwrite the old files so it can be stored on the network once changes have been made.
I did try experimenting with some If/for statements through a .BAT file but I didn't have much luck with theses, if anyone could point me in the right direction that would be awesome.
At this point I'm probably making this way more complicated than I have to.
something like this should work too:
#echo off
:INPUT.BAT puts what is typed next in environment variable INPUT
set input=
echo INPUT.BAT
echo Type in something and press [Enter]
fc con nul /lb1 /n|date|find " 1: ">temptemp.bat
echo :Loop>>enter.bat
echo if not (%%input%%)==() set input=%%input%% %%5>>enter.bat
echo if (%%input%%)==() set input=%%5>>enter.bat
echo shift>>enter.bat
echo if not (%%5)==() goto Loop>>enter.bat
for %%x in (call del) do %%x temptemp.bat
del enter.bat
echo The string you just entered:
echo %input%
echo has been stored in an environment variable named INPUT
:End
I ended finding a solution after doing some more research from what #Squashman linked. Turns out there was a breakdown in communication and this wasn't even the original issue that the user had (a simple way to copy the files off A:\ and all that)
I used the following.
echo Type "set myvar="name of the folder" replacing name of the folder with
echo the name of the folder containing the files on A:\ example if you were
echo on "example" you would type: set myvar=example
copy con answer.bat
echo Type the words "set myvar=" (don't type the quote marks)
echo and then immediately after the = sign, press Control-Z then enter
call answer.bat
mkdir C:\%myvar%
xcopy A:\%mvar% C:\%myvar%
DEL answer.bat
This is a modified version of a guide I found here. http://www.pement.org/sed/bat_env.htm#4dos
Hopefully this is able to help someone, this isn't pretty by any stretch of the imagination but it worked.
I think this would be easier for your users if they actually need to only copy one directory.
#echo off
if "%1" == "" goto syntax
md C:\%1
xcopy/E A:\%1 C:\%1
goto end
:syntax
echo Please input a directory after %0
:end

Batch file to search through a folder and delete specific files

Firstly, this is the first batch file I've ever written and I really don't know the syntax.
This code should search and delete all the files, except that it doesn't actually delete them, they are still there. If someone could help me out, I would really appreciate it.
My script is as follows:
#echo off
color a
echo.
For /R "E:\" %%G IN (*.onetoc2) do Echo del "%%G"
echo.
timeout 10
You just need to remove the Echo before del "%%G". The Echo is there to show you what will be deleted before you actually do it. Most of the people that answer questions here will add that in as a safeguard.
remove the Echo.
Echo tells the computer to write things to the screen.
It's a good idea to do this for testing.
Once you are satisfied with the output and are sure, that it will do what you want, simply remove the echo
echo format c:
will not format your drive, but simply writes "format C:"
Remove the echo and you are in trouble. (well not really, because modern OS is too smart to do that)

Resources