Solved

folder delete

Posted on 2011-03-23
11
512 Views
Last Modified: 2012-05-11
We are switching our users from local signatures to a server based system.  Some users are ignoring this request so we want to send out a batch file to delete the signature folder on their machines so they have to switch:

to do this we need a wildcard command line:

so far i have this working except for the %username% part

rmdir /s /q  "C:\Documents and Settings\%username%\Application Data\Microsoft\Signatures"

we are on 95% windows xp machines.

thanks.
0
Comment
Question by:randy672
  • 4
  • 4
  • 3
11 Comments
 
LVL 8

Expert Comment

by:MarkieS
ID: 35199250
Use "%userprofile%\Application Data\Microsoft\Signatures"

This takes into account users who have married so the profile is still under the maiden name..
0
 

Author Comment

by:randy672
ID: 35199321
that didn't work
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35199413
If you run a CMD prompt and just type

cd "%userprofile%\Application Data\Microsoft\Signatures"

What do you get?  
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 8

Expert Comment

by:MarkieS
ID: 35199448
How are you running your batch file?  If it's running under the system account there is no user profile involved.  Is it part of an account login script or Group policy login script?
0
 

Author Comment

by:randy672
ID: 35199464
i am just running the command in CMD right now to test it.

when i type in cd "%userprofile%\Application Data\Microsoft\Signatures"  it give me can't find path specified, which makes sense since how would it know which profile i wanted to see.

All of our pcs have multiple profiles on them. I want to delete that folder on all of the profiles for each PC.
0
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 35199466
the Envirnoment Variable MarkieS provided should work. the only thing I can think of is if the Signature folder or it's files have special persmissions assigned for some reason and the users don't have the access rights to remove it.

Have you tried running this manually in command line on one of your systems to see what's happening?
0
 

Author Comment

by:randy672
ID: 35199487
i am logged into the pc as a domain admin and I am running that line manually from the cmd prompt.

when i run this line it deletes the folder for that user:

rmdir /s /q  "C:\Documents and Settings\joeshmo\Application Data\Microsoft\Signatures"

when i run this one it doesn't work:

rmdir /s /q  "C:\Documents and Settings\%userprofile%\Application Data\Microsoft\Signatures"
0
 
LVL 4

Expert Comment

by:MaximumIQ
ID: 35199543
when you use %userprofile% it will return the current logged on use's profile path. Domain admins in most cases don't cache a local profile, which might explain why it's not finding that folder.

If you want to delete all users, you can write VB Script to look in the registry for all cached users and do a For...Next loop on each one.

Give me about 15 minutes I'll try to write you something.
0
 
LVL 8

Expert Comment

by:MarkieS
ID: 35199625
rmdir /s /q  "%userprofile%\Application Data\Microsoft\Signatures"

The %userprofile% is c:\documents and settings\<profilename"
0
 
LVL 4

Accepted Solution

by:
MaximumIQ earned 500 total points
ID: 35199777
Here is a script that I tweaked a bit for your case. Paste this code in a VBS File.

You just need to set a path to where you want a log file to save. If you dont want a log file just remove the "Set log =...." line and all "logfile.write..." lines

On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set objRegistry=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

Dim strUserProfile
Dim FSO, WshNetwork, WshShell, Log

Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("Wscript.Network")
Set WshShell = Wscript.CreateObject("Wscript.Shell") 

'Put a path on this next line where you want a log file to save
Set log = fso.getFile("Log Path Here")
Set logfile = log.OpenAsTextStream (ForAppending, TristateUseDefault)

strWinFolder =  fso.GetSpecialFolder(WindowsFolder)
strSysFolder =  fso.GetSpecialFolder(SystemFolder)

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys

logfile.write WSHNetwork.UserName
logfile.write " ;"
logfile.write WSHNetwork.ComputerName
logfile.write " ;"
logfile.write time
logfile.write " ;"
logfile.write date
logfile.write " ;"

For Each objSubkey In arrSubkeys
    strValueName = "ProfileImagePath"
    strSubPath = strKeyPath & "\" & objSubkey
    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue

	'Here is your line		
		If fso.FolderExists(strValue & "\Application Data\Microsoft\Signatures") Then 
			fso.deletefolder(strValue & "\Application Data\Microsoft\Signatures")
			logfile.write strValue & "\Application Data\Microsoft\Signatures"
		end if
Next

Open in new window

0
 

Author Closing Comment

by:randy672
ID: 35200366
Thanks!!!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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