Solved

Environment Variables on Windows 7 when using Folder Redirection

Posted on 2014-07-23
5
1,908 Views
Last Modified: 2014-07-25
I am using Folder Redirection in a windows 2008 domain. Redirecting Desktop and Documents to a server share via a folder redirection group policy.

I want to reference the path to the desktop of users via a batch file. But when I use echo %userprofile%/Desktop I get c:\users\username instead of \\server\users\username. But the desktop of coarse is on the server. Verified the desktop is on the server.

So guessing there is another way to get the path to the redirected desktop, but Dr google has given me no good answers.
0
Comment
Question by:Jay Walker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 

Author Comment

by:Jay Walker
ID: 40215446
Learning the experts exchange. Apparently 500 is the number to use.
0
 

Author Comment

by:Jay Walker
ID: 40215507
So I figured out part of my issue. But not my original question.

I was trying to delete a shortcut (.lnk file) from the desktop of all users desktop which were redirected. Luckly we use DFS and have the home directory in the DFS.

So I was able to do something like this:
del /Q "\\%userdomain%\fs1%homepath%\Desktop\App.lnk"

%userdomain% is of coarse the DFS Root
fs1 is the share of our DFS root
%homepath% gives me the users\[username]
Desktop well thats the folder redirected desktop folder name

So I was able to achieve my end goal, but still curious on why I can't find an environment variable for the folder redirected desktop, or some shortcut to it.

So instead of
del /Q "\\%userdomain%\fs1%homepath%\Desktop\App.lnk"
I wanted to use something like
del /Q "\\%RedirectDesktop%\Desktop\App.lnk"

Of coarse I could manually create a domain wide variable, push that to all the PC's so the variable existed, then used the made up one, but  was hoping that one existed.
0
 
LVL 25

Accepted Solution

by:
Coralon earned 500 total points
ID: 40218434
You won't be able to do that in a batch easily on straight Windows.
However, if you have access to the appropriate version of Terminal Server/Remote Desktop Services, you could copy the utility acregl.exe from that system. (It is located in %systemroot%\application compatibility scripts).  

You would do something like this:
acregl.exe MyDesktop.cmd DesktopLoc "HKCU\Software\Microsoft\WIndows\CurrentVersion\Explorer\User Shell Folders" Desktop ""
MyDesktop.cmd
del /q "%DesktopLoc%\app.lnk"

Open in new window


This is totally untested, and I can't even be sure it would work.

However -- you could easily use either vbscript or powershell to get that same information to pull your value for your script or for whatever function you want.

VBScript
dim wshShell
set wshShell = CreateObject("wscript.shell")
sMyDesktop = wshShell.RegRead("hkcu\software\microsoft\windows\currentversion\explorer\user shell folders\desktop")

dim fso
set fso = CreateObject("scripting.filesystemobject")
fso.DeleteFile(sMyDesktop & "\app.lnk", vbTrue)
set fso = nothing
set wshShell = nothing

Open in new window


Powershell
$MyDesktop = (get-itemproperty -path 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' -name Desktop).Desktop
remove-item -path "$MyDesktop\app.lnk"

Open in new window


Coralon
0
 

Author Comment

by:Jay Walker
ID: 40219518
You got me on the right track. I dont know why I didnt search the registry first.

Desktop Folder Redirection is here
HKEY_Current_user/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Desktop

And My Documents Folder Redirection is here
HKEY_Current_user/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/Personal

Please note this is not only folder redirection, but rather what ever your desktop or my documents points to is reflected here. The GPO for folder redirection simple updates this registry key, then performs copying or what ever your GPO folder redirection preferences which where set commanded.

All I have to do now, is use powershell or VBS to grab those key values into variables, then use my scripts to do whatever I want with the variables.

Thanks for pointing me in the right direction.
0
 

Author Closing Comment

by:Jay Walker
ID: 40219522
Thanks for pointing me in the write direction.
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question