Solved

Environment Variables on Windows 7 when using Folder Redirection

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

To effectively work with Diskpart on a Server Core, it is necessary to write some small batch script's, because you can't execute diskpart in a remote powershell session. To get startet, place the Diskpart batch script's into a share on your loca…
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…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now