Solved

folder delete

Posted on 2011-03-23
11
509 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
Comment Utility
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
Comment Utility
that didn't work
0
 
LVL 8

Expert Comment

by:MarkieS
Comment Utility
If you run a CMD prompt and just type

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

What do you get?  
0
 
LVL 8

Expert Comment

by:MarkieS
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 4

Expert Comment

by:MaximumIQ
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!!!!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

10 Experts available now in Live!

Get 1:1 Help Now