Im working on over 700 computers in a school district and have written a small program that i intend to write to a cd. The program is set to autorun when the disk is inserted and prompt the screen resolution of the computer and what computer the building is in (the different school buildings). Afterwards the program will run a batch file that copies a default desktop from the disk and into the windows\web\wallpaper directory. It also replaces other files that have been customized for the school district.
To finish changing the theme of the computer, i need to have the file make a few edits to the group policy and the registry. How would i be able to use the program to makes these changes? Would it all be written into the batch or would the batch have to initiate another file (like a registry file)?
All the group policy editor does is set registry keys. If you can identify what keys are being set for the policy you want, you can use reg.exe to set those keys.
reg.exe add HKCU\Software\path\to\regkey\ /v valuename /d newvalue
Registry will work for the first user, but after a new user logs in, GP will change those settings for the new user.
To make deployment gp, do this: Set one machine's GP to the way you want it. Once you are done, goto C:\windows\System32\GroupPolicy and copy the contents. (note: this is a hidden file). On the next machines you want, just paste back in the file.
If you do this in a batch, you will have to run the batch as administrator to touch the C:\windows\system32 folder. (UAC, the bane IT)
Related
Hi Sorry to ask another question regarding robocopy but by its very nature it is quite diverse so I need to be clear on what I am trying to achieve.
Scenario.
Moving from a Nas to a windows file Share , Completely New ACL's will be created and inherited from the new share already setup . SO this is a straight file and folder copy with mirroring.
I decided to use powershell to run the command - it felt right at the time and achieved the desired result on a few shares .
I mapped the drive and ran the following .
robocopy z:\"Dept Folder 1"\ E:\Shares\deptdata\"New dept folder" /e /LOG+:file /v /TEE
robocopy z:\"Dept Folder 2"\ E:\Shares\deptdata\"New dept folder2" /e /LOG+:file /v /TEE
The files and folders copied as expected inheriting the new ACL's The first Job finished and then moved on to the second copy and again completed successfully.
What I would like to do now on some of the larger shares is incorporate the mir command as I need to keep a constant mirror on all folders until such time as I have tested the new ACL's and I have mapped the new drive via GPO.
My First Question knowing the behaviour when having batched commands is this .
When using the Mir command will the first command in the batch continue to mirror
the share and move onto the next Mirror command and so forth. or will it just sit their mirroring the first command and not move onto the second?
If it wont move on to the next command how do I achieve that is it possible? would i have to run multiple mirror commands at the same time and not batch them up in one?
When the Mir command is running if I add new files into the New destination will those files get deleted, or is it only mirroring the source and doesn't care about new files in the destination?
Where would I specify the MIR command?
Is there a way to build a batch file to delete all *.auc files in %LOCALAPPDATA% for a specified user. Like maybe to have it ask for a username and then use that as the target for the delete function?
I tried to look around but couldn't figure out a way to do it with both the wildcard and a specified user. In all fairness I am pretty new at this. We have users who pretty regularly have to delete these files, while we are troubleshooting the underlying cause, it would be nice to simplify this process as much as possible.
Try something like below (not TESTED though but should work fine)
#echo off
set /p uname="Enter user ID: "
set path_firstpart = "C:\Users\"
set path_secondpart = "\AppData\Local"
set pathtodeletein = %path_firstpart%%uname%%path_secondpart%
del "%pathtodeletein%\*.auc" /S /Q
If you want to provide this batch for the current user you can use %LOCALAPPDATA% as the path to delete in or use %username% in order to avoid asking for the username.
If you want more fancy user interaction you could switch to windows scripting host and vbscript (phew ...) which allows you to open input boxes.
I am writing a batch file on my Windows 8.1 machine. In one section of my batch file I need to start a command prompt in the "current working directory".
So far, this is what my batch file looks like:
#echo OFF
set WORKING=%cwd%
start cmd.exe /K pushd %WORKING%
exit
Let's say the batch file is located in the folder C:\Temp\Utilities. If I open an explorer window and double click the batch file to run it everything works great. A new command prompt is created in the directory C:\Temp\Utilities. However, if I right-click the batch file and select Run as administrator the working directory is no longer the location of the batch file, it's C:\Windows\System32.
Similarly, if I create a shortcut to the batch file in a different folder (for example. C:\Temp) and repeat the two steps above the results are the same. If I double click the shortcut and run it as a normal user the working directory is what I would expect. (Note, the working directory for the shortcut it's whatever is set for "Start in" of the shortcut properties, not the location of the batch file.) If I right click the shortcut and run it as administrator I again get a command prompt opened to the folder C:\Windows\System32.
I assume this is a "bug" or "feature" (if you want to call it that) in Windows 8.1 and it probably happens because execution environments for programs run as administrator are forced to run in the System32 folder? (I remember with Windows 7 this did not happen so it must be a new feature to Windows 8.)
I found one way to fix the issue and stop the command prompt from starting in C:\Windows\System32. I did this by modifying the following line in the batch file:
set WORKING=%~dp0
Doing it this way sets the working directory to the location of the batch file. With this change, no matter how I run the batch file or the shortcut (administrator or normal) the working directory ends up being the same, C:\Temp\Utilities.
The problem with this solution is I don't want the working directory to always be the location of the batch file. If the batch file is run directly then it's okay but if I run it from a shortcut I need the working directory to be whatever is set in the "Start in" property of that shortcut. For example, if the batch file is located in the folder D:\Temp\Utilities this is what I need to happen regardless of whether I run as administrator or not:
Shortcut Location Start In Property Command Prompt Working Directory
-------------------- ------------------- ------------------------------------------
C:\Temp <undefined> D:\Temp\Utilities
C:\Data\bin C:\Data\bin C:\Data\bin
C:\Data\bin D:\Temp\Utilities D:\Temp\Utilities
What this means is I can't always use %~dp0 to set the working directory in my batch file. What I need is some way for the batch file to know if it was run either directly or by a shortcut. If the batch file is run directly then the working directory is easy to get, it's just the value of %cwd%. If the batch file is run by using a shortcut, I don't know how to get the "Start in" property inside the batch file.
Does anyone know how I can do these two things inside my batch file:
1. Check whether it was run directly or by a shortcut.
2. If run by a shortcut, get the "Start in" property of the shortcut that started it.
Thank you,
Orangu
UPDATE
I found sort-of a "hackish" way to fix the issue. For the shortcut I edited the "Target" field and changed it to the following:
cmd.exe /k pushd "C:\Temp" && "D:\Temp\Utilities\batchfile.bat"
Now the working directory can be obtained by calling %CD% in the batch file and this works for both administrator and normal users. It does not, however, work for the case when I run the batch file directly. I still need to use %~dp0 in that case.
I don't like this solution, however, because it requires me to manually change all shortcuts I make and it also makes the icon look like a cmd prompt icon rather than a batch file.
Have you already considered to not use shortcuts at all?
You could e.g. create a batchfile_exec.bat containing your call
REM optionally do
REM cd /D working_directory
REM if you want to force a special working directory
D:\Temp\Utilities\batchfile.bat
and replace all the shortcuts with batchfile_exec.bat. If you double-click batchfile_exec.bat, the working directory will be the one containing batchfile_exec.bat.
I personally don't like Windows shortcuts that much, because they are hard to handle within a revision control system. As you also noticed, it is very time consuming if you want to modify a lot of them.
By the way: If batchfile.bat was designed/written to be always run from the direcory where it is located, you might also consider to modify batchfile.bat to force that behaviour:
setlocal
cd /D %0\..
REM your original content
endlocal
In %0 the path to the batchfile is stored.
The trick is to assume that %0 is a directory and then to change one level lower based on that directory. With /D also the drive letter is changed correctly.
The cd command doesn't care if %0 is really a directory. In fact %d doesn't even have to exist (%0\dummy\..\.. would also work).
The setlocal command is to have the working directory being restored when batchfile.bat has finished (this would be good if batchfile.bat was called form another batch file).
I noticed that the endlocal command is not really necessary in this context since it is applied implicitly when batchfile.bat finishes.
I'm a Mac user, but I need to write a script on Windows, and I'm not sure how I should go about that.
Here's the scenario:
Someone adds photos to a USB drive. The drive is then inserted into a digital picture frame.
In order for the photos to autoplay, a 'playlist.asb' file must be present on the drive. I want to create a script that can be clicked on and executed to auto create the playlist file based on the image files added to the USB. The script would do something like this:
Check if there are images in the 'slideshow' folder.
Check if file called 'playlist.alb' exists, if not create it. If so, overwrite it.
Loop through available images.
Add each image name and extension on a new line.
Save (and overwrite any existing playlist file) and exit.
I'm comfortable with AppleScript for Macs, but I'm not sure if a Windows equivalent would make sense, or if some kind of command line script would work better.
Any help is greatly appreciated.
Something like this should do it:
#echo off
setlocal
cd /d %~dp0Slideshow
if exist playlist.alb del playlist.alb
for %%a in (*.jpg *.gif *.png) do (
echo %%~nxa>>playlist.alb
)
I have a user, which couldn’t get along with AutoCAD so he switched back to InterCAD. He’s not too computer literate so now when he tries’s to open a DWG file (AutoCAD native file extension) by double clicking it he’s register settings look for the AutoCAD program to open it.
I know that we can tweak the register settings for a .dwg file to open the file automatically with InterCAD rather then AutoCAD.
I’m not too un-familiar with tweaking the registry keys and when I do I like to automate this using batch script.
What is the best procedure to do this, I'm namely worried I will miss a key or is the following the only key I need to tweak
HKEY_CLASSES_ROOT\.dwg\OpenWithprogids
The extension to execute Intercad in Intercad.exe
How do I successfully achieve my desired result?
The key you need to edit will be this one:
HKEY_CLASSES_ROOT\dwgfile\shell\open\command
That controls the program the file opens with.
To do this in a batch file use this:
reg add HKCR\dwgfile\shell\open\command /v "" /d "programpath.exe" /f
Hope this helps.