i want to copy a file to system32 folder using a batch file. but when i try to do this it says "Access denied" i also can not copy anything to my C:\ drive also. i tried using xcopy and copy to do this. i don't know what is the parameter to get the administrator permission. so, can anyone help me?
program:
#echo off
xcopy abc.dll "C:\Windows\System32\" -y
pause
output:
D:abc.dll
Access denied
Press any key to continue . . .
Should be doable one of two ways.
The first is to make a shortcut to your batch file, right click -> properties and on the Shortcut tab of the properties, click the Advanced button to find a checkable "run as admin" option.
The second (NOT TESTED) is to add a bunch of stuff to the top of your batch file (Reference) - I don't want to include it in the answer because I have not tested it.
#echo off
copy /Y abc.dll "C:\Windows\System32\"
pause
right click the batch file and run as administrator
and make sure the abc.dll is in the same folder as your batch file.
hope this helps.
Related
Hi i need to change folder permisions (and the contained files) from a bat file using a variable..
something like :
icacls "%dat%" /T /C /grant *S-1-1-0:(f)
but that does not seem to work as expected..
The %dat% variable works fine as the rest of the bat works for people who do not have permission issues with the folder,
the bat file i created starts off
set root=%~dp0
ECHO DRAG YOUR T.O.P FOLDER HERE
ECHO the one With "textures" folder inside.
set /p top= Then press Enter
ECHO Drag your fallout 4 Data folder here
set /p dat= then press enter
ECHO Drag your Archive2 folder here
set /p arc= then press enter
goto :choice1
(that part works fine)
It then goes to a selection of choices which also work fine.
The only issue is some people do not have permisions to modify the data folder. And the bat file needs to create folders, and move files within that folder.
I think the issue my be that:
icacls "%dat%" /T /C /grant *S-1-1-0:(f)
is settng permissions for the contents of the data folder but not the data folder itself.
its worth noting that the bat file needs to be run from inside the data folder to eliminate variables. so whilst moving it one folder up in the directory tree could allow me to use it as is and eliminate the issues of he few. It would undoubtedly cause more issues for the many.
As it stands right now everything that NEEDS to work does work, the only issue being that i cannot seem to set folder permissions on the dat folder. And i do not really want to add an extra variable unless i have too..
(i could add a "set /p new=" section to the startng sequence, but i swear i should be able to do it without that.)
Any help welcome.
i would post the entire bat file here, but i dont see it is needed. it is just a repeating list of go to: commands wich process a file inddividually.
(move a file to a created folder, extract that file to a second created folder. add extra files to the extracted files, recompress the extracted files to the same file name as the origional, moves the new file to the origional location, deletes the 2 working folders, recreates the 2 working folders with the same name, and then goes on to the next fiile)
All of that works fine. and im sure you can imagine how it is done.
-=edit=-
Just wondering if its my execution of the icals thats wrong..
would this be crrect?
icacls "%dat%" /grant:r *S-1-1-0:f /T /C
or is the 1st way i am structuring it fine?
the answer was :
icacls %dat% /grant:r *S-1-1-0:(OI)(CI)F /T /C
...
( %dat% ) being a variable directory address which was inputed earlier in the bat file.
/grant:r was needed as without :r it was giving special permissions instead of setting the actual permissions. (i thought you needed /l to do that)
/t sets the permission from the variable to all subfolders and files.
F is Full permission. (for some reason it does not need a /
/c lets the thing continue running even if there were errors.
(OI) is Object inherit.
(CI) is container inherit.
and *S-1-1-0: is the user. (that is the ID for "everyone" that way it works on any language.
"everyone" may fail on non english versions"
I create portable QGIS. It is done by copy QGIS2 folder in other computer. I have startup file so that QGIS will do the command. I can run QGIS in batch file. The code :
echo D | xcopy /s/e/y "%~dp0DATA\.qgis2" C:\Users\%username%\.qgis2
start /d "Running QGIS2" /D "%~dp0DATA\QGIS2\bin" qgis.bat
Then I want to open 1.qgs project. Then I add the code :
start /d "Running QGIS2" /D "%~dp0DATA\QGIS2\bin" qgis.bat "%~dp0DATA\PROJECT" 1.qgs
But, there is a message. Unable to open D:/./././1.qgs. So, what's wrong in my code?
Since you are starting the process, there is no guarantee that the directory that qgis sees as "current" is the same as the batch directory.
Fully-qualify the parameter 1.qgs - prefix it with the the appropriate directoryname.
Alternatively, modify qgis.bat to display %cd% and pause. That will show you where qgis believes its current directory is. That information should allow you to make appropriate adjustments.
I need a batch file which will do the following:
1. Open CMD and navigate to a location C:/Users/...../program.exe
2. Run the program.exe with an additional command to point it to a config file:
e.g. "program.exe C:/Users/..../configFile.bgi"
How can I do this?
I tried this but with no luck:
start "C:\Users\Ben\Desktop\BGInfo\bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi"
pause
Update
I've used the solution provided by Ganesh (below) and came up with this:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi
I've tested it on a local machine (changing the directories) but on the server (with the directory above) it does not work...
The folder directory with batch file:
The error
in batch file abc.bat
cd c:\user\ben_dchost\documents\
executible.exe -flag1 -flag2 -flag3
I am assuming that your executible.exe is present in c:\user\ben_dchost\documents\
I am also assuming that the parameters it takes are -flag1 -flag2 -flag3
Edited:
For the command you say you want to execute, do:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe dc_bginfo.bgi
pause
Hope this helps
You can use
start "" "%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
start "" /D "%USERPROFILE%\Desktop\BGInfo" bginfo.exe dc_bginfo.bgi
or
"%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
cd /D "%USERPROFILE%\Desktop\BGInfo"
bginfo.exe dc_bginfo.bgi
Help on commands start and cd is output by executing in a command prompt window help start or start /? and help cd or cd /?.
But I do not understand why you need a batch file at all for starting the application with the additional parameter. Create a shortcut (*.lnk) on your desktop for this application. Then right click on the shortcut, left click on Properties and append after a space character "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi" as parameter.
Found another solution for the same. It will be more helpful.
START C:\"Program Files (x86)"\Test\"Test Automation"\finger.exe ConfigFile="C:\Users\PCName\Desktop\Automation\Documents\Validation_ZoneWise_Default.finger.Config"
finger.exe is a parent program that is calling config solution.
Note: if your path folder name consists of spaces, then do not forget to add "".
I have the following code in the batch-file:
#echo on
regedit.exe /S abc.reg
If I run it, I get an error.
I searched the google for this and found nothing. Can someone help me please?
I tried:
- removing /S (the I can read (of course) the errormessage
- Run the file as administrator (I'm admin per default)
I am using windows 8.
The erros message: "Cannot import C:\users....abc.reg". Error opening the file. There may be a disk or a file system error.
Both Files are in the same folder.
The problem was, that I handled the %~dp0 in a false way. %~dp0 stands for the default path, but you don't have to set a backslash after it!
If you want to run a .reg file in the same folder as the .bat file, just write it like this:
#echo on
REGEDIT /S "%~dp0ABC.reg"
This will run the file ABC.reg in the same folder.
If you wan't to run something in a subfolder, you have to do it like this:
#echo on
REGEDIT /S "%~dp0SUBFOLDER\ABC.reg"
The brackets ("") are only needed, if there are whitespaces in the pathname.
Much easier way is run it as a Scheduled task.
In this way you can get your batch file to run as admin without annoying password prompts.
For more valuable information, please read here...
http://forums.whirlpool.net.au/archive/2037875
http://social.technet.microsoft.com/Forums/systemcenter/en-US/be854b0a-5d41-4b03-9a84-8fe79732f33c/run-bat-file-to-call-reg-file-in-sccm?forum=configmgrswdist
http://www.myitforum.com/articles/1/view.asp?id=12036
Right click on aix2_mm.bat and select "Run As Administrator", you will get a full screen UAC prompt that you must agree with, then it will work.
If you don't see 'Run As Administrator' as an option, hold the shift key prior to right clicking.
and it wouldn't hurt to make your batch more portable. The %~dp0 parameter will expand to the full path to ABC.reg if it's in the same folder as the .bat file.
#echo on
regedit.exe /S "%~dp0abc.reg"
Be careful the working directory
My bat file always has the code on first line
cd /d %~dp0
It can safely change current directory to your bat file directory
Is it possible to create a batch file to copy a folder to another location everytime I login, or when the folder is updated?
It could be written in VB or Java as well if not an easy solution.
Any ideas?
Two approaches:
When you login: you can to create a copy_my_files.bat file into your All Programs > Startup folder with this content (its a plain text document):
xcopy c:\folder\*.* d:\another_folder\.
Use xcopy c:\folder\*.* d:\another_folder\. /Y to overwrite the file without any prompt.
Everytime a folder changes: if you can to use C#, you can to create a program using FileSystemWatcher
#echo off
copy con d:\*.*
xcopy d:\*.* e:\*.*
pause
Open Notepad.
Type the following lines into it (obviously replace the folders with your ones)
#echo off
rem you could also remove the line above, because it might help you to see what happens
rem /i option is needed to avoid the batch file asking you whether destination folder is a file or a folder
rem /e option is needed to copy also all folders and subfolders
xcopy "c:\New Folder" "c:\Copy of New Folder" /i /e
Save the file as backup.bat (not .txt)
Double click on the file to run it. It will backup the folder and all its contents files/subfolders.
Now if you want the batch file to be run everytime you login in Windows, you should place it in Windows Startup menu. You find it under: Start > All Program > Startup
To place the batch file in there either drag it into the Startup menu or RIGH click on the Windows START button and select Explore, go in Programs > Startup, and copy the batch file into there.
To run the batch file everytime the folder is updated you need an application, it can not be done with just a batch file.
It's easy to copy a folder in a batch file.
#echo off
set src_folder = c:\whatever\*.*
set dst_folder = c:\foo
xcopy /S/E/U %src_folder% %dst_folder%
And you can add that batch file to your Windows login script pretty easily (assuming you have admin rights on the machine). Just go to the "User Manager" control panel, choose properties for your user, choose profile and set a logon script.
How you get to the user manager control panel depends on which version of Windows you run. But right clicking on My Computer and choosing manage and then choosing Local users and groups works for most versions.
The only sticky bit is "when the folder is updated". This sounds like a folder watcher, which you can't do in a batch file, but you can do pretty easily with .NET.
Batch file to copy folder is easy.
xcopy /Y C:\Source\*.* C:\NewFolder
Save the above as a batch file, and get Windows to run it on start up.
To do the same thing when folder is updated is trickier, you'll need a program that monitors the folder every x time and check for changes. You can write the program in VB/Java/whatever then schedule it to run every 30mins.
robocopy yourfolder yourdestination /MON:0
should do it, although you may need some more options. The switch at the end will re-run robocopy if more than 0 changes are seen.
#echo off
cls
echo press any key to continue backup !
pause
xcopy c:\users\file*.* e:\backup*.* /s /e
echo backup complete
pause
file = name of file your wanting to copy
backup = where u want the file to be moved to
Hope this helps
#echo off
xcopy ...
Replace ... with the appropriate xcopy arguments to copy what you want copied.