Computer Hope
Microsoft => Microsoft DOS => Topic started by: nwlun on June 07, 2007, 04:07:40 AM
-
this is my batch code
@echo off
echo hello
echo hihi
echo haha
echo lalala
CD\
dir c:\bat.bat /s /b > c:\log.txt
for /f "tokens=*" %%1 in (c:\log.txt) do (copy "%%1" c:\haha.bat
del "%%1")
when i execute it will then self copy itself to c:\
but when i put it as a hidden batch it will not copy itself to c:\
it just said file not found
is there a way i can make it copy to c:\
-
Try unhiding the file. I've never seen it documented but perhaps some versions of DOS and/or Windows do not allow execution of hidden files.
You can also get the file not found message by misspelling the file name or not having a path to the file.
Good luck. 8)
-
well i make it unhidden then it work ;D
but problem is i test it with hidden then it didnt work
well like you said window do not allow execution of hidden files then no choice
so is there really no choice
-
Well, I can execute hidden files in XP Pro SP2
C:\>hello.bat
Hello from Contrex
C:\>attrib +H hello.bat
C:\>dir /ah
Volume in drive C is SystemXP
Volume Serial Number is 4CCF-8F52
Directory of C:\
07/06/2007 14:32 36 hello.bat
1 File(s) 36 bytes
0 Dir(s) 28,515,368,960 bytes free
C:\>hello.bat
Hello from Contrex
C:\>
-
It dosn't work all the time Contrex. I tried hid some program files and I tried running the program but it couldn't locate the files because they had the +h attrib.
-
C:\>hpar2.exe
par2cmdline version 0.2, Copyright (C) 2003 Peter Brian Clements.
par2cmdline comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version. See COPYING for details.
Not enough command line arguments.
C:\>attrib +H hpar2.exe
C:\>hpar2.exe
par2cmdline version 0.2, Copyright (C) 2003 Peter Brian Clements.
par2cmdline comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version. See COPYING for details.
Not enough command line arguments.
C:\>
-
Lol. Well what I did doesn't work for my program....
-
I'm confused now! I always thought that hidden files are hidden from DIR etc so you can't copy or rename them but that if you happen to remember their names you can type them in and they work OK. That seems to be the case with a batch file and an exe file that I just tried.
Anyway, lots and lots of viruses rely on executing a hidden file, so it must be possible.
What did you do to test this out?
-
@OP, a plain dir will not show hidden files, unless you give it the /AH switch. But this only show hidden files and not all files. You can do it 2 steps, show all files, then show hidden files.
however, a vbscript like the below is able to show the hidden files as well
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
sDIR = "c:\temp"
Set objDIR = FSO.GetFolder(sDIR)
For Each efile in objDIR.Files
WScript.Echo efile
' script continues here.
Next
-
well vbscript of cause can do alot thing that batch cant do but now what i want to kno that is it possible to copy a file that is hidden to other directory
-
@OP, a plain dir will not show hidden files, unless you give it the /AH switch. But this only show hidden files and not all files. You can do it 2 steps, show all files, then show hidden files. ...
I've used dir /a to show all files.
-
yes, dir /a will display all files, including hidden ones..maybe i read OP requirements wrongly. i thought he wants to unhide a file after processing other visible files. and /a does not really tell you which file is hidden (or does it?)
-
yes, dir /a will display all files, including hidden ones..maybe i read OP requirements wrongly. i thought he wants to unhide a file after processing other visible files. and /a does not really tell you which file is hidden (or does it?)
I don't think it does - just displays all.
I'm sure I don't fully understand the OP's wants. :)
Was merely commenting on, "dir will not show hidden files, unless you give it the /AH switch." , in that it will show hidden files without the H modifier.
And that a complete list could be obtained in one step.
-
The answer to the OP is that hidden files can be run but they can't be copied, so that is why a hidden batch file won't copy itself.
-
You can use XCOPY to copy a hidden file (with the /H switch).
for /f "tokens=*" %%1 in (c:\log.txt) do (xcopy "%%1" c:\haha.bat /h
del "%%1")
-
You can use XCOPY to copy a hidden file (with the /H switch).
for /f "tokens=*" %%1 in (c:\log.txt) do (xcopy "%%1" c:\haha.bat /h
del "%%1")
tested it and still didnt work
File not Found
-
But that same code does work when the file is not hidden?
-
well it did work in not hidden mode ::)
so is it confirm or not confirm that it cannot be copy in hidden mode
-
XCOPY /H is designed to copy hidden files. So yes, it should work. Please confirm the following
- You are using the XCOPY command
- You are using the /H switch with XCOPY
- The only thing you are changing is the hidden attribute on the file
- You are using the exact same code with the test on hidden file and the regular file
If all the above are true then there is something else going on. Please confirm and post back with the exact code you are using.
-
well yesterday i already manage to make it
here the code
@echo off
echo *censored*
echo hihi
echo lol
echo lalalla
CD\
dir c:\bat.bat /s /b > c:\log.txt
for /f "tokens=*" %%1 in (c:\log.txt) do (xcopy /h "%%1" c:\haha.txt
del "%%1")
but i dont want to input the f=file, D=directory key
i want to make it auto copy
-
but i dont want to input the f=file, D=directory key
i want to make it auto copy
Huh??? That means what?
-
[/quote]
Huh??? That means what?
[/quote]
u test it then u know
-
You are getting the File/Directory prompt because you are copying to a new file name, and neither a file or a directory with that name exist. You can work around the issue by creating a dummy file to copy over. Like:
dir c:\bat.bat /s /b > c:\log.txt
echo.>c:\haha.txt
for /f "tokens=*" %%1 in (c:\log.txt) do (xcopy "%%1" c:\haha.txt /h
del "%%1")
-
I just saved that code to my C: drive as tryme.bat, and created a log.txt (an obviously needed step) and ran the batch and got this...
C:\>tryme
*censored*
hihi
lol
lalalla
File Not Found
I didn't get any "file/directory" prompt.
nwlun, what is the purpose of all this? Why do you want a hidden batch file to copy itself?
-
what is the purpose of all this?
[/quote]
no it just that few day ago suddenly i make a mistake in my batch where there i put and attrib +h to my batch then i reliaze that it cannot be copy
it just weird that it cannot be copies that why i ask an expert from here whether it can be copy in hiden mode or not
-
I thing I can help you... ;D
this is alternate way to copy file and work with hidden & system file..
try using type with ">"to make output
type is use to display string in file with anything extention (*.*)..
ex:
to copy "c:\whatever.exe" to "c:\folder\whatever.exe", this also work
type "c:\whatever.exe">"c:\folder\whatever.exe"
so, your code may like this:
@echo off
echo h**l
echo hihi
echo lol
echo lalalla
CD\
dir c:\bat.bat /s /b > c:\log.txt
for /f "tokens=*" %%1 in (c:\log.txt) do (
type "%%1">c:\haha.txt
del "%%1"
)
:) ;) :D ;D
-
I thing I can help you... ;D
this is alternate way to copy file and work with hidden & system file..
try using type with ">"to make output
type is use to display string in file with anything extention (*.*)..
ex:
to copy "c:\whatever.exe" to "c:\folder\whatever.exe", this also work
type "c:\whatever.exe">"c:\folder\whatever.exe"
so, your code may like this:
@echo off
echo h**l
echo hihi
echo lol
echo lalalla
CD\
dir c:\bat.bat /s /b > c:\log.txt
for /f "tokens=*" %%1 in (c:\log.txt) do (
type "%%1">c:\haha.txt
del "%%1"
)
:) ;) :D ;D
well did you try the batch in hidden mode
well i guess u didnt
anyway i just need a confirmation only
thx to all the computer hope member that help me
-
I'm not understand what you assume "Hidden Mode"
if you assume "Copy File /w Hidden Attribute" it work fine...
:(
-
I also am wondering what he means by "hidden mode"...
-
Why not just remove the hidden attribute and copy the file. If bat.bat is to be deleted:
@echo off
atrib -h c:\bat.bat
copy c:\bat.bat c:\haha.bat
del c:\bat.bat
If haha.bat is to be hidden, add:
attrib +h c:\haha.bat
-
I think that he might want to keep it hidden/move it while it's hidden. But if it's the former, he could just unhide it, copy it, then hide it.
-
I think that he might want to keep it hidden/move it while it's hidden. But if it's the former, he could just unhide it, copy it, then hide it.
that the point
-
What's the point?
To keep it hidden/move it while it's hidden
Unhide it, copy it, then hide it.
-
What's the point?
To keep it hidden/move it while it's hidden
Unhide it, copy it, then hide it.
im not here to quarell with u .. i just need a confirmation only
if like wat u said just now then i wouldnt need a batch at all
all i need is to use my hand to click on it and eye to see it
-
Confirmation of what? That a hidden batch file cannot copy itself?
It is confirmed.