Computing.Net > Forums > Programming > Vista Delete user profiles prompt

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Vista Delete user profiles prompt

Reply to Message Icon

Name: naimc
Date: July 2, 2009 at 08:29:29 Pacific
OS: Vista,2008
CPU/Ram: na
Product: N/a / NA
Subcategory: Batch
Comment:

Hello I'm writing a batch that will connect to a remote vista computer, list the roaming profiles and enable user to select the profile they want deleted. (using wmic and Win32_UserProfile)

I have already a script that deletes all of the Roaming profiles,

that script is here :

TITLE %~nx0
@Echo on
cls
color f0

@echo .
Set /p TargetCmp=Enter computername on which we will delete all the roaming profiles:

echo Target computer name equ %TargetCmp%

for /f "tokens=1,2" %%a in ('wmic /node:"%TargetCmp%" path win32_UserProfile get RoamingConfigured^,Sid^|find "TRUE"') do (
echo %%a echo %%b
wmic /node:"%TargetCmp%" path win32_UserProfile where Sid="%%b" Delete
)
pause

Exit

I know would like to create a new script that will basical 1st display the profile and lets the operator just select one profile to be deleted.

the following cmd : wmic /node:%computername% path win32_UserProfile where RoamingConfigured="TRUE" get Localpath,sid,loaded

gives the following output :

Loaded LocalPath SID
FALSE C:\Users\user1 S-1-5-21-594694905-1720275925-1234779376-33861
FALSE C:\Users\User2 S-1-5-21-594694905-1720275925-1234779376-28753
FALSE C:\Users\User3 S-1-5-21-594694905-1720275925-1234779376-11962

My question is : I've added the following changed the script to the following :

TITLE %~nx0
@Echo on
cls
color f0

setlocal ENABLEDELAYEDEXPANSION

@echo .
Set /p TargetCmp=Enter computername on which we will delete all the roaming profiles:

echo Target computer name equ %TargetCmp%

for /f "tokens=1-3" %%a in ('wmic /node:"%TargetCmp%" path win32_UserProfile where RoamingConfigured^="TRUE" get Loaded^,LocalPath^,sid') do (
echo %%a echo %%b %%c
Choice /M "Press Y to delete the user profile for %%b or N for NO"
Echo the choice is %ErrorLevel%
if %ErrorLevel% == 1 wmic /node:"%TargetCmp%" path win32_UserProfile where Sid="%%c" Delete
)

pause

Exit
The problem I'm having is that used the ErrorLevel result for the choice cmd is always Zero in when it should be 1 for Y or 2 for N. Any ideas of what I'm going wrong ?

thank you.

Naim.



Sponsored Link
Ads by Google

Response Number 1
Name: naimc
Date: July 2, 2009 at 14:49:39 Pacific
Reply:

I solved my problem by using !ErrorLevel! instead of %ErrorLevel%

Here is the final verison of my script

TITLE %~nx0
@Echo off
cls
color 74


setlocal ENABLEDELAYEDEXPANSION

@echo .
@echo This script will connect will prompt for a remote computer
@echo and give you the option to delete all users profile or prompt to delete selected profiles.
@echo .
@echo You must be part of the Desktop User AD group for this script to work.
@echo This script will only work on Target Vista and 2008 Servers.
@echo .

@echo .
Set /p TargetCmp=Enter the remote computer name:

echo Target computer name equ %TargetCmp%

@echo .
@echo Press A to delete all roaming profiles on %TargetCmp%
@echo Press P to prompt before deleting Profiles one at a time.
@echo .

Choice /C AP
if %ErrorLevel% == 2 Goto DelPrompt
if %ErrorLevel% == 1 Goto DelAll


:DelPrompt

for /f "tokens=1-3" %%a in ('wmic /node:"%TargetCmp%" path win32_UserProfile where RoamingConfigured^="TRUE" get Loaded^,LocalPath^,sid^|find "C:"') do (
Choice.exe /C YN /M "Press Y to delete the user profile for %%b or N for NO"
if !ErrorLevel! == 1 wmic /node:"%TargetCmp%" path win32_UserProfile where Sid="%%c" Delete
)

EndLocal
pause
Exit


:DelAll
for /f "tokens=1-3" %%a in ('wmic /node:"%TargetCmp%" path win32_UserProfile where RoamingConfigured^="TRUE" get Loaded^,LocalPath^,sid^|find "C:"') do (
echo Deleting user profile for : %%b with SID : %%c
wmic /node:"%TargetCmp%" path win32_UserProfile where Sid="%%c" Delete
)

EndLocal
pause
Exit


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Vista Delete user profiles prompt

creating a temp file in user profil www.computing.net/answers/programming/creating-a-temp-file-in-user-profil/10663.html

Create a user profile in Visual C++? www.computing.net/answers/programming/create-a-user-profile-in-visual-c/1996.html

I need to copy a file to each users www.computing.net/answers/programming/i-need-to-copy-a-file-to-each-users/15923.html