Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

folder delete

Posted on 2011-03-23
11
Medium Priority
?
517 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
 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

 
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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

It all started with a phone call.  The then acting director of the Office of Research Computing, called to ask me to remotely shutdown my computer, it was Yom Kippur, Wednesday October 12, 2016.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

782 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