I'm facing the following problem: In Windows AD every user logging in at a machine for the first time, shall get copied some program links on his desktop. Therefore desktop-pc and notebook are member of the AD and the desktops use serverbased-profiles while notebook use local profiles, it is necessary to differ the runonce-script.
My plan/script was the following one:
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders" /v "Desktop" /f "R:\Profile\Desktop"
if %ERRORLEVEL% EQU 0 goto Domain
if %ERRORLEVEL% EQU 1 goto Notebook
:Domain
ECHO off
xcopy "c:\UserApps\Desktop-Verknuepfungen\*.lnk" "R:\Profile\Desktop\*.lnk" /Y > nul
exit
:Notebook
ECHO off
xcopy "c:\UserApps\Desktop-Verknuepfungen\*.lnk" "%USERPROFILE%\Desktop\*.lnk" /Y > nul
exit
The shell-folder desktop string should be examined if it's the ad-path or the local path to decide: desktop or notebook. Unfortunately in every case, although it is a notebook, the errorlevel 0 returns and the script uses the wrong jumplabel. Normally it should return for a local path errorlevel 1.
Maybe someone can help out?
Thank you so much in advice,
Chris
CodePudding user response:
here you have a solution that should solve your problem.
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\explorer\Shell Folders" /v "Desktop" | find /i "R:\Profile\Desktop" && goto Domain
:Notebook
ECHO off
xcopy "c:\UserApps\Desktop-Verknuepfungen\*.lnk" "%USERPROFILE%\Desktop\*.lnk" /Y > nul
exit
:Domain
ECHO off
xcopy "c:\UserApps\Desktop-Verknuepfungen\*.lnk" "R:\Profile\Desktop\*.lnk" /Y > nul
exit
If the registry key is existent its content will be sent to find
. Then find /i
will search within the output without case sensitivity. if the string R:\Profile\Desktop
is found the success can be used with &&
to trigger the goto Domain
. Just had to switch :Notebook
and :Domain
so that in error (searchstring not found) he will choose :Notebook
.
Andi
CodePudding user response:
With the following builtin alternative you might solve this problem as well, but it doesn't need batch files. Microsoft tries to remove the need for that kind of skripts
Use GPP (Group Policy Preferences) with WMI filtering and let that do the copy job. You can define paths where files are and where they should be copied to. If you just need a fixed source / target definition or can use environmental variables that should be a good alternative.
Microsofts details about that:
Files extension:
Group Policy includes the Files preference extension.
For computers or users, this extension allows you to:
- Copy a file (or multiple files in one folder) to a new location and then configure the attributes of those files. New subfolders are created as necessary.
- Delete a file (or multiple files in one folder) and replace it with a copy of a file from a source folder.
- Modify the attributes of a file (or multiple files in one folder).
- Delete a file (or multiple files in one folder).
- Modify the attributes of, replace, or delete all files with a particular extension in one folder.
- Modify the attributes of, replace, or delete all files in a particular folder.
Note:
To configure folders rather than individual files, use the Folder extension.You can create and configure File preference items for any domain-based Group Policy object (GPO). You configure the settings by editing a GPO using the Group Policy Management Console. When editing a GPO, you can find this preference extension at the following location:
Computer Configuration or User Configuration
** └ Preferences
**** └ Windows Settings
****** └ Files
You have a lot more options there including some good filtering options.