Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Environment Variables on Windows 7 when using Folder Redirection

Posted on 2014-07-23
5
Medium Priority
?
2,063 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 1500 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

688 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