HighTechTalks DotNet Forums  

Deleting profile folder through UNC path with WMI?

Dotnet Framework (WMI) microsoft.public.dotnet.framework.wmi


Discuss Deleting profile folder through UNC path with WMI? in the Dotnet Framework (WMI) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
sandra@familiejansenonline.nl
 
Posts: n/a

Default Deleting profile folder through UNC path with WMI? - 12-10-2007 , 09:27 AM






Hello,

I want to delete user profiles with C# code and running into the
problem that some files in the profile are read only.

Therefor, I want to use WMI to delete the profile folder, but somehow
I can't find the correct path string to use. I don't want to use a
drive letter for accessing the folder to delete, but an unc path.

Can someone tell me what I'm doing wrong?

Thanks in advance,
Sandra

My code:

private void button3_Click(object sender, EventArgs e)
{
DeleteProfileFolder(@"\
\CP-1001VS03\TSPROFILE204\ML00033");
}
private bool DeleteProfileFolder(string Path)
{
bool result = false;

try
{
string path = @"Win32_Directory.Name='" + Path + "'";
ManagementObject mo = new ManagementObject(path);
mo.Get();
ManagementBaseObject outParams =
mo.InvokeMethod("Delete", null, null);

if ((uint)(outParams.Properties["ReturnValue"].Value) !
= 0)
{
AddToLog("-- ERROR deleting profile folder [" +
Path + "] with return value: " +

outParams.Properties["ReturnValue"].Value.ToString());
}
else
{
result = true;
}
}
catch (Exception ex)
{
AddToLog("-- ERROR deleting profile folder [" + Path +
"]: " + ex.Message);
}
return result;
}

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.