Windows CE7 | Move and replace directory from the command prompt - batch-file

I'm trying to write a batch file that should copy a directory from a USB stick and place it in another folder on the hard disk (if the folder already exists, the new one should replace it).
Currently I'm trying something like this:
COPY "\Hard Disk2\sourceFolder" "\Hard Disk\targetFolder"
which doesn't copy any the "sourceFolder" or any subfolders.
I want to move everything (including folders) from my sourceFolder to my targetFolder.
Anyone knows how to do this?
For a list of available commands in Windows CE 7, please see this picture.
More information about the commands: https://msdn.microsoft.com/en-us/library/ee505427(v=winembedded.60).aspx
Note:
I don't think XCOPY or ROBOCOPY works in CE. I've tried both, but I just get the following error:
"Cannot execute ROBOCOPY.exe / XCOPY.exe".

The Command prompt for Windows Embedded Compact 7 is very limited and is not intend to be used on a final product, but as a tool for the firmware development and tuning. So the option that you are looking is not available and therefore, you will probably have to develop your own version of the XCopy command.

Related

Delete file from C:\Windows folder

I'm working with an application that was poorly designed. When installed, it creates a .INI file (remember those?) in the C:\Windows folder. In order to get things working correctly in our environment, I don't use that .INI file. Instead, I have separate .INI files in a different location where I can properly management them within the framework of the application. The problem I'm running in to is users not running the application correctly so it picks up this default .INI file that doesn't work in our environment (remember I said the application is poorly designed).
To make sure that my users are running the correct configuration, I need to delete this pesky .INI from the C:\Windows folder. I have .BAT files that manage application launch and updates so I tried to just issue a delete in the .BAT file but it isn't working. When I try to run just the delete command in a command window, I get "Access Denied". I can't rename it or move it either. I would just go touch each computer but don't have the time to get to them all.
I have just spent the last two hours googling to find a solution and the only solutions are to use Windows Explorer which isn't an option. I know it has to be something simple that I haven't been able to find. Ideas?
for /f "usebackq delims=" %A in ("%userprofile%\Desktop\ComputerName.txt") do echo Del \\%A\C$\Windows\file.ini
Computername.txt is one computer per line, names or addresses.
127.0.0.1

Creating a C executable to run a installer

I'm looking to do a mass update on a large number of computers and would like to create a simple script that i can just click and run to complete the work much quicker.
I've never tackled anything like this before so im not really sure where to start.
The goal of the script is to take the files which i will be moving from a drive to each laptop, open cmd.exe execute a command and then run the installer that is generated from it. Any advice or pointers on where i can start would be greatly appreciated.
I can't comment yet so --
As other users have mentioned powershell would be a better alternative to C. Or you could use a batch file.
#echo off
XCOPY <source path> <destination path> /f /-y
start <your program.exe>
When copying it would display the locations it's copying to and from(/f), as well as as for confirmation for overwrites(/-y).
More switches can be seen here for the copy command.

Overwrting multiple file using NSIS Script (how Win Zip extractor does)

I am writing a script using Null Script which install around 6000 files in INSTALLDIR i.e. C:\ABC folder.
I have done this using
File /r "ABC"
in install section.
It is just a simple extractor (no registry entries and no uninstall.exe created during install).
Now, if I run the same exe again then I want my exe to display a message box to the user while overwriting the files containing the options
Yes,
Yes too all, or
exit the installer
i.e. How WinZip software does while extracting the same zip file in the same location multiple times.
If I set the SetOverwrite value to off then during install (2nd time) my EXE just skips the file installation without notifying the user. Also using IFFILEEXIST I can check a single file or *.* files but cannot do one to one mapping.
Please suggest how can I implement this. If this question is already posted then please send me the link.
Thanks in advance.
It is not possible to get this behavior in NSIS when using File /r. You might be able to pull off something similar by generating the file list at compile time by executing a batch file with !system and then check if each file exists and maybe delete the old one at run-time but you are not going to get the dialog without a custom plugin. NSIS itself only supports basic Abort/Retry/Cancel and Yes/No dialogs.
If you only want to use free tools, why not just use 7-Zip to create a self extracting archive?

Start batch after restart

I'm trying to make a batch start after a restart. Will this work?
This doupdate.bat is stored at a USB drive and is going to be used in many computers.
REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /V 1 /D "%~d0\cmd\DoUpdate.bat
So you want it start on startup? Since you cant use Autorun.inf since that needs to be manually clicked to start it up and ever since Win7 it doesnt allow you to change what file it opens on USB, it sounds like your only option is the startup folder. You could write a second batch script to copy the file into the computers startup folder. Here is the code to copy the file into the startup folder as a bat:
C:
copy doupdate.bat "C:\Users\%USERNMAE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\doupdate.bat"
(Note: Thats assuming the bat to move the file is on the USB, and also replace the 'C:' in the code with whatever drive it will be moving to, you cant simply have it move directly to the C drive or CD to it, you have the enter the name since interacting between different drives on batch it tricky, so you have to cd to them a special way first)
But that would only have the file auto-open on restart only on the user that you were currently using when you ran the file.
Also that method requires you to have the file installed to the users computer.
And if you dont want the file to stay on the users computer after its already done its job, simply add this code at the end of "doupdate.bat" for it to delete itself:
del "C:\Users\%USERNMAE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\doupdate.bat"
its as simple as that, that way when it gets run from the Startup folder, as soon as its done with all of its purpose, it will remove itself, and then to re-add it, simply re-run the bat to move the file.
I hope my info helped, and if any of the methods here wont work for your specific bat file just tell me and ill try to find a different method to do it and will edit this post to include that method.
This should work:
copy "doupdate.bat" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
Note: Make sure to use this in Windows 10. I am not sure if this will work in Windows 8, 7 but it should also work

psftp.exe get files from the server and delete

I'm using psftp.exe to download files from the server. Is there an easy way to delete these files once I have downloaded them but leave the new ones that might have appeared on the server when I was downloading to be downloaded next time?
Here's my command line:
psftp.exe domain.com -i keys\private.ppk
get *.xml
Edit: I want to download the files from a Linux box to a Windows PC.
There's no easy way to do this with psftp. You would have to parse its output to find files that were successfully downloaded.
Though you can do this easily with WinSCP. Just use get -delete *.xml command.
Full WinSCP script would be:
open sftp://domain.com/ -privatekey=keys\private.ppk -hostkey=...
get -delete *.xml
exit
See an introduction to WinSCP scripting.
See also a guide for converting PSFTP script to WinSCP.
You can also have WinSCP GUI generate script like this for you.
(I'm the author of WinSCP)
Martin's answer is good. The below is more industrial.
Moving them to a staging area before the download may be prudent.
Generally you would move/rename the files on the server as a starting point. They are going to be deleted anyway so nothing should miss them? nor would you want to fall back over a recent file.
(so restart after this point in the event of a subsequent failure)
Then perform the download.
Then perform the delete.
I would approach the issue differently. Instead of deleting the file from the server, add the downloaded filename to a local table of "Already downloaded files". Then when you scan the FTP again for new files, ignore any that are in that table.
That way the next time you run your download script you only get the new files, but the old files remain on the server.
You could have another script that runs periodically and deletes all files over a certain age.
WINSCP is alright, and Martin (the author) drops in to practically every PuTTy thread to recommend it, but it's a fully GUI-based app and not for me. If you really need everything to be done on the commandline then WINSCP is often not an option.

Resources