Prev: VB WMI script syntax
Next: objUser.SetPassword "object dose not support this property or method" error
From: JHP on 3 Feb 2006 16:29 Should also mention it works remotely as well: strFolder = """\\computername\C$\Documents and Settings\administrator(a)xxxxxxxx.com""" "JHP" <goawayspam(a)GFY.com> wrote in message news:e9elVdQKGHA.1676(a)TK2MSFTNGP09.phx.gbl... > This worked for me (as long as nothing is locked/used within the > directory): > > Option Explicit > > Dim strFolder, objShell, objWMIService, objFolders, rtnFolder, rtnCode > Const WindowStyle = 0 > Const WaitOnReturn = True > > strFolder = """C:\Documents and Settings\administrator(a)xxxxxxxx.com""" > Set objShell = WScript.CreateObject("WScript.Shell") > objShell.Run "CMD /c RMDIR /s /q " & strFolder, WindowStyle, WaitOnReturn > Set objShell = Nothing > > "SunRace" <sunracesuraj(a)rediffmail.com> wrote in message > news:eSKfwZQKGHA.208(a)tk2msftngp13.phx.gbl... >> Hello, >> >> Yes I did think of using it but my requirement is slightly different. I >> am using a logic based on deleted users. If the user is deleted then only >> his profile shall get deleted or else it can remain as long as the user >> does not get deleted. This is like that because we are in a very high >> employee attrition industry where in users leave within days also. This >> is the script which I have worked up.... >> >> ========================================== >> Function IsAccountDisabled( strDomain, strAccount ) >> Dim objUser >> Dim fso >> Dim tf >> Dim strTXT >> >> Set objUser = GetObject("WinNT://" & strDomain & "/" & strAccount & >> ",user") >> IsAccountDisabled = objUser.AccountDisabled >> End Function >> >> 'List User Profiles >> >> On Error Resume Next >> >> Const HKEY_LOCAL_MACHINE = &H80000002 >> >> strComputer = "." >> >> Set objRegistry=GetObject("winmgmts:\\" & _ >> strComputer & "\root\default:StdRegProv") >> >> strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" >> objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys >> >> For Each objSubkey In arrSubkeys >> strValueName = "ProfileImagePath" >> strSubPath = strKeyPath & "\" & objSubkey >> objRegistry.GetExpandedStringValue >> HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue >> >> strName = mid(strValue, instrrev(strValue, "\") + 1) >> if ucase(strName)<>"LOCALSERVICE" then >> if ucase(strName)<>"NETWORKSERVICE" then >> if ucase(strName)<>"SYSTEMPROFILE" then >> >> 'Check Account Status >> >> Dim strUser, strDomain, objComputer, objRegistry >> Dim fso, objFSO >> Dim tf >> Dim strTXT >> Set objComputer = CreateObject("Shell.LocalMachine") >> strUsr = strName >> strUser = strName >> strDom = "corp.domain.com" >> Set fso = CreateObject("Scripting.FileSystemObject") >> strTXT = Replace(CStr(Date),"/","-") & "_" >> strTXT = strTXT & Replace(CStr(Time),":","-") >> Set tf = fso.CreateTextFile("\\networkshare\" & objComputer.MachineName & >> ".txt", True) >> If( IsAccountDisabled( strDom, strUsr ) = -2147022675 ) Then >> >> Set objComputer = GetObject("WinNT://" & strComputer & ",computer") >> objComputer.Delete "user", strUser >> >> strComputer = "." >> >> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ >> strComputer & "\root\default:StdRegProv") >> >> strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" >> & objSubkey >> >> oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath >> >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> objFSO.DeleteFolder("C:\Documents and Settings\" & strName) >> >> Set WshShell = WScript.CreateObject("WScript.Shell") >> WshShell.Run "Explorer /select,C:\Documents and Settings\" & strName >> wscript.sleep 5000 >> wshShell.SendKeys "%F,D" >> wscript.sleep 5000 >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> wshShell.SendKeys "{ENTER}" >> >> tf.WriteLine (strUsr) + " user does not exist - Profile Deleted." >> Else >> tf.WriteLine (strUsr) + " user Exists." >> End If >> >> END IF >> END IF >> END IF >> Next >> >> ============================================================ >> >> "JHP" <goawayspam(a)GFY.com> wrote in message >> news:%23LKb$%23PKGHA.964(a)tk2msftngp13.phx.gbl... >>> Have you thought about using the delprof.exe utility? >>> >>> http://www.microsoft.com/downloads/details.aspx?FamilyID=901A9B95-6063-4462-8150-360394E98E1E&displaylang=en >>> >>> It deletes all (inactive) profiles on a computer - quiet mode or >>> prompt - you can also set which profiles to delete based on inactive >>> days... >>> >>> "SunRace" <SunRace(a)discussions.microsoft.com> wrote in message >>> news:261DB484-A8FD-4611-BD41-1AC8F61A8D56(a)microsoft.com... >>>> Hello, >>>> >>>> I am Domain Administrator for our domain. I am trying to delete one >>>> user's >>>> profile folder using following code. >>>> >>>> Dim objFSO >>>> Set objFSO = CreateObject("Scripting.FileSystemObject") >>>> objFSO.DeleteFolder("C:\Documents and Settings\Test1.Test1") >>>> >>>> When I run the vbscript I get following error. >>>> >>>> Script: pathname\111.vbs >>>> Line: 5 >>>> Char: 1 >>>> Error: Permission denied >>>> Code: 800A0046 >>>> Source: Microsoft VBScript runtime error >>>> >>>> Now when I try to delete the same folder using windows GUI I can delete >>>> the >>>> folder without any error. If I create a similar name folder in the same >>>> path >>>> I am able to delete the same using this same script. Now this is >>>> strange as I >>>> am domain administrator and I can delete the profile folder without >>>> using >>>> vbscript why can't I delete the same folder using vbscript? >>>> >>>> Please help..... >>>> >>> >>> >> >> > >
From: SunRace on 3 Feb 2006 17:08 Yes ................it worked .... thanks JHP.................. Working Script.................Well this is something achieved after 7 days in to it...heehaw....you know now I can deploy this script and relax.....1200 workstations will be taken care for profile maintenance .... let them come and go....we are ready....power of scripting.......hmmmmmmmmmmmmm ======================================================= Function IsAccountDisabled( strDomain, strAccount ) Dim objUser Dim fso Dim tf Dim strTXT Set objUser = GetObject("WinNT://" & strDomain & "/" & strAccount & ",user") IsAccountDisabled = objUser.AccountDisabled End Function 'List User Profiles On Error Resume Next Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objRegistry=GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys For Each objSubkey In arrSubkeys strValueName = "ProfileImagePath" strSubPath = strKeyPath & "\" & objSubkey objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,strValue strName = mid(strValue, instrrev(strValue, "\") + 1) if ucase(strName)<>"LOCALSERVICE" then if ucase(strName)<>"NETWORKSERVICE" then if ucase(strName)<>"SYSTEMPROFILE" then 'Check Account Status Dim strUser, strDomain, objComputer, objRegistry Dim fso, objFSO Dim tf Dim strTXT Set objComputer = CreateObject("Shell.LocalMachine") strUsr = strName strUser = strName strDom = "corp.domain.com" Set fso = CreateObject("Scripting.FileSystemObject") strTXT = Replace(CStr(Date),"/","-") & "_" strTXT = strTXT & Replace(CStr(Time),":","-") Set tf = fso.CreateTextFile("\\NetworkShare\" & objComputer.MachineName & ".txt", True) If( IsAccountDisabled( strDom, strUsr ) = -2147022675 ) Then Set objComputer = GetObject("WinNT://" & strComputer & ",computer") objComputer.Delete "user", strUser strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & objSubkey oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFolder("C:\Documents and Settings\" & strName) 'Option Explicit Dim strFolder, objShell, objWMIService, objFolders, rtnFolder, rtnCode Const WindowStyle = 0 Const WaitOnReturn = True strFolder = """C:\Documents and Settings\""" & strName Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run "CMD /c RMDIR /s /q " & strFolder, WindowStyle, WaitOnReturn Set objShell = Nothing tf.WriteLine (strUsr) + " user does not exist - Profile Deleted." Else tf.WriteLine (strUsr) + " user Exists." End If END IF END IF END IF Next ==================================================================
First
|
Prev
|
Pages: 1 2 Prev: VB WMI script syntax Next: objUser.SetPassword "object dose not support this property or method" error |