Delete file from C:\Windows folder - batch-file

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

Related

Windows CE7 | Move and replace directory from the command prompt

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.

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

scheduled batch file fail moving file to google drive

i'm trying to move file from 1 server to an other with schedule batch file, for that i use google drive as a third part where i store my files. i have made some script
#echo "executed %date:~-10,2%%date:~-7,2%%date:~-4,4%" >> Logs.txt
copy /y "C:\backup\Portal2%date:~-10,2%%date:~-7,2%%date:~-4,4%.bak" "c:\users\administrator\google drive\"
this script move a file from a directory to an other, it works fine if i click it,but if i try to schedule it doesn't work.
I tried to change path to a random path in my computer and scheduled it, it worked perfectly.
its like my computer doesn't recognize google drive at all.
When copying over a network you need to use credentials in the scheduled task that have access to the network resource.
This is probably a bit late for you but might be helpful to others who follow in your footsteps. I had this problem and it came down to security. When you run something in batch it doesn't have the correct permissions. I can't remember the exact solution but you need to set the batch task to run with your username.

Batch file doesnt run after deploying from SCCM

I have a batch file which uses gpresult /v and saves the output in a text file and copy that text file to a shared folder. This batch when i run on my local machine works perfectly fine but once i deploy it through SCCM it says can not open file with error code 4. I dont know what is wrong in the file.
the code is Like this:
#echo off
gpresult /v >%computername%.txt
xcopy %computername%.txt \some path
Error 4 is "The system cannot open the file.", as if the path is invalid or the open() fails for some other reason.
Do you know what directory the program is running in (CWD)?
That's where the results of gpresult are going (if the output redirection succeeds).
gpresult is not going to produce meaningful user-level data for the SYSTEM user.
Perhaps you should use gpresult /v scope computer.
Why are you using xcopy when you're only copying one file? xcopy really only has added value (over copy) if you are copying directories.
xcopy's behavior changes depending on how you specify the target. If the target ends with the directory separator (backslash), xcopy treats it like it's a directory. If it doesn't and the target doesn't exist, xcopy asks you what to do, which causes automated processes to pause indefinitely waiting for user input.
SCCM Programs Run as 'NT Authority\SYSTEM'
When SCCM (2007) runs a program, the program doesn't run as a regular user. It runs as the highest privilege user (sort of), SYSTEM.
This account is not a regular account, and many settings and environment variables that exist and are predictable for a regular user are different or do not exist for SYSTEM.
One particularly frustrating "feature" of the SYSTEM account's profile is that it is nestled away under %WINDIR%\System32, and so it is subject to filesystem redirection whenever you refer to anything relative to the profile.
Try this: use psexec -s (sysinternals) to get shell access as the SYSTEM account and run the command in that environment to see how it behaves. This is as close as we can get to an environment like the one SCCM programs run under.
When SCCM runs the command, the CWD will probably be somewhere under %WINDIR%\SysWOW64\CCM\ and may be invoked with the 32-bit version of CMD.EXE.
I have a question in regards to something similar to this. So I have an uninstall bat that runs. Due to the vendors uninstall it causes a force close of the windows explorer UI. So in haste to solve that issue I added a call to open explorer.exe. There is a problem with this as someone pointed out to me. Actually as soon as he said I knew exactly what he was saying and where he was going with his statement. Calling explorer.exe would be fine except that the bat is running under the system context not the user so when explorer is restarted it will start under the guise of the system desktop profile not the user's. I know there is way to still run under the guise of system but to restart explorer under the currently logged in user's profile.

Updating SVN remotely via batch file

I tried searching relevant threads, it didn't worked. So here are the detailed question / situation, where I am looking for help.
I have 30 client nodes where I have setup SVN and checked out two folders (which needs to be updated) exactly when I want (forcefully).. e.g : "d:\gbv\textures" and "d:\gbv\characters"
then I put svnUpdate.bat file in main d: drive with relevant command e.g: "svn update blabla"
if I run this bat file by double clicking, it works fine ( it updates )
now I thought, I should create a batch file, where I type all 30 nodes IP, and set of commands, to run that batch file from local d: and it should work.
PROBLEM: I am unable to do this.
because I am unable to do this, from my cmd panel.
because I am not sure, how I can access network pc and tell it to run "d:\svnUpdate.bat" from its drive from dos prompt. ( obviously, I can do this via win explorer visually ).
Hopefully the question will make sense.
You can execute files on remote machines in a network using PsExec. I use it to execute batch files and pass parameters to them.
You'll probably need the -w option to set the working directory.
Of course this is a lot easier with powershell remoting, but since you already set it up with batch, PsExec works fine.

Resources