Solved

Environment Variables on Windows 7 when using Folder Redirection

Posted on 2014-07-23
5
1,622 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
  • 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 24

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

825 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