Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2214
  • Last Modified:

Environment Variables on Windows 7 when using Folder Redirection

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
Jay Walker
Asked:
Jay Walker
  • 4
1 Solution
 
Jay WalkerAuthor Commented:
Learning the experts exchange. Apparently 500 is the number to use.
0
 
Jay WalkerAuthor Commented:
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
 
CoralonCommented:
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
 
Jay WalkerAuthor Commented:
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
 
Jay WalkerAuthor Commented:
Thanks for pointing me in the write direction.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now