+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Windows 7 Thread, Delete registry key with wildcard in Technical; We seem to be having a few issues with windows backing up registry keys for profiles - this means when ...
  1. #1

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,786
    Thank Post
    272
    Thanked 1,129 Times in 1,025 Posts
    Rep Power
    348

    Delete registry key with wildcard

    We seem to be having a few issues with windows backing up registry keys for profiles - this means when the user next logs in on that machine windows i loading a temporary profile.

    I've seen this fix from Microsoft A temporary profile is loaded after you log on to a Windows Vista-based system

    anybody know a way/have a script for deleting a registry key with a wildcard?

    something along the lines of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%wildcard%.bak

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Code:
    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
         
    	Result = InStr(objSubkey, ".BAK") 
    	if Result <> 0 then
    		"insert deletly line here"
    	else
    		
    	End If
    Next
    Should work fine, scans through it finding anything with a .BAK in it (not sure if you need to make it lower case), then just add your delete regkey line.

    Don't have any .baks so can't try it but should be good.

    Steve

  3. #3

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,786
    Thank Post
    272
    Thanked 1,129 Times in 1,025 Posts
    Rep Power
    348
    Cheers will have a go next machine which crops up.

    as its vbs i need to use cscript don't i?

  4. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by glennda View Post
    Cheers will have a go next machine which crops up.

    as its vbs i need to use cscript don't i?
    Aye, generally. Just remember to add the delety line else it'll do nothing

    Steve

  5. #5

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,786
    Thank Post
    272
    Thanked 1,129 Times in 1,025 Posts
    Rep Power
    348
    what do you mean by delety line?

  6. #6

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by glennda View Post
    what do you mean by delety line?
    Well depending how you were planning to delete it, whether by an external program/script, or just in this script you'd need to delete:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ & objSubkey

    (Which makes up the filepath to the key you want deleted).

    Steve

  7. #7

    Join Date
    Jan 2012
    Location
    California
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by Steve21 View Post
    Well depending how you were planning to delete it, whether by an external program/script, or just in this script you'd need to delete:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ & objSubkey

    (Which makes up the filepath to the key you want deleted).

    Steve
    Hello, I realize this thread is somewhat old, but I'm trying to use this script on my workstations connected to a domain (we have quite a few machines with the "temporary profile" error). However, I get an error at the line "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ & objSubkey". I'm assuming there has to be some sort of delete command in front of that path but I'm not sure of the exact syntax. I've been searching a while on my own and tried a number of different ways to no avail. Any help you can provide would be greatly appreciated.

    Thanks,
    JB

  8. #8


    Join Date
    Feb 2007
    Location
    51.405546, -0.510212
    Posts
    8,706
    Thank Post
    220
    Thanked 2,615 Times in 1,926 Posts
    Rep Power
    777
    Would forced mandatory profiles be an option? These would prevent the temp profile from being loaded.

    Forced Mandatory Profiles (a.k.a. Super-Mandatory)
    Mandatory Profiles might not always be so—if the server is down or a user unplugs their network cable, the Mandatory Profile does not load. Indeed, the user will get the Local Default User Profile. This could be a potential security problem and possibly a violation of your corporate policy.

    In instances like this, you need to determine if it’s more important that a user logs on (and gets the Default Local User Profile) or that, if they don’t get the Mandatory Profile, they don’t get to log on at all. Microsoft calls this type of profile “Super-Mandatory.” In Figure 9.30 earlier, we used a folder named allnurses as our Mandatory Profile folder. We can take this to the next step and ensure that no users using the allnurses folder can log on unless they can connect to the share on the server.

    Don’t forget: profiles are different for Type 1 (pre–Windows Vista) and Type 2 (Windows Vista and later). To that end, you’ll need to set up Mandatory Profiles that fit for each type.

    To force users who log onto Windows Vista and later to use a Mandatory Profile or lose logon capability, you need to first rename the allnurses.v2 folder so that it has .man.v2 instead. So, the final folder name will be allnurses.man.v2.

    To force users to use the Mandatory Profile, or lose logon capability, simply follow these steps:

    • Create a Mandatory Profile as described earlier, including renaming the NTUSER.DAT to NTUSER.MAN.
    • For Windows XP machines, rename the entire folder from allnurses to allnurses.man. For Windows Vista machines, rename the entire folder from allnurses.v2 to allnurses.man.v2
    • Change the affected users’ Profile tabs to point to the new location, such as \\Dc01\profiles\allnurses.man, as shown in Figure 9.34.


    Once the forced Mandatory Profile is introduced onto a system, the system always checks to see if the profile is available. If the forced Mandatory Profile is unavailable, the user is not permitted to log on.

    Note. Technically, you can couple a Mandatory Profile with the "Log users off when roaming profile fails" policy setting to create the same effect. However, the method detailed here is preferred. (Source, p611)

  9. #9

    Join Date
    Jan 2012
    Location
    California
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    No unfortunately that would be to easy! We are a college and specific policies are in place. The script mentioned above would be the perfect fix, (we could add it to the logon script) but the actual "delete" line is giving me trouble with the exact syntax. Just need to get line 17 right and problem solved (hopefully). Wish I had more VB chops.

  10. #10

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by jbragg01 View Post
    No unfortunately that would be to easy! We are a college and specific policies are in place. The script mentioned above would be the perfect fix, (we could add it to the logon script) but the actual "delete" line is giving me trouble with the exact syntax. Just need to get line 17 right and problem solved (hopefully). Wish I had more VB chops.
    It'd be something along the lines of:
    Code:
    objRegistry.DeleteKey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ & objSubkey, strKeyPath
    But can't test it I'm afraid. Not sure if it'll accept the "&" within the delete, or if it needs merging before the delete is fired off.

    Steve

  11. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,677
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by Steve21 View Post
    It'd be something along the lines of:
    Code:
    objRegistry.DeleteKey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\ & objSubkey, strKeyPath
    But can't test it I'm afraid. Not sure if it'll accept the "&" within the delete, or if it needs merging before the delete is fired off.

    Steve
    Would the first part of the key need to be enclosed in quotes ?? So that it treats it as a string so that you can use the ampersand ( & ) to join / concatenate the two or three variables together in the delete command ?

    Code:
    objRegistry.DeleteKey "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & objSubkey, strKeyPath

  12. #12


    Join Date
    Feb 2007
    Location
    51.405546, -0.510212
    Posts
    8,706
    Thank Post
    220
    Thanked 2,615 Times in 1,926 Posts
    Rep Power
    777
    Quote Originally Posted by jbragg01 View Post
    Wish I had more VB chops.
    DeleteProfiles.vbs?

  13. #13
    Patrickv's Avatar
    Join Date
    Jan 2012
    Location
    New Zealand
    Posts
    59
    Thank Post
    4
    Thanked 3 Times in 3 Posts
    Rep Power
    6
    I had a lab with windows 7 enterprise and windows 2003 network which had roaming profiles which some users get loaded with a temporary profiles. Never figured out the problem. This takes ages to load up. I had a look in the registry location and you need to know what sids to delete.

  14. #14

    Join Date
    Feb 2013
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi,

    I know this is an old thread. But how can i delete every Key that will be found with this script? e.g. i search for test at apath and want do delete every Key with the Name Test under that Path.

    regards
    Cornulio

  15. #15

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,677
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Would delprof2 not cover or resolve this ?

    Post on @PeteLong's website : http://www.petenetlive.com/KB/Article/0000033.htm
    Last edited by mac_shinobi; 5th February 2013 at 03:37 PM.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. VB Delete registry keys with sub keys
    By cookie_monster in forum Scripts
    Replies: 1
    Last Post: 6th November 2009, 08:57 AM
  2. logoff script to delete registry key
    By ICMC in forum Scripts
    Replies: 3
    Last Post: 26th January 2009, 10:37 PM
  3. Batch file to remove registry key doesnt work
    By sidewinder in forum Windows
    Replies: 4
    Last Post: 7th December 2007, 04:48 PM
  4. Deleted a registry key - help!
    By mrcrazy04 in forum Windows
    Replies: 1
    Last Post: 19th July 2007, 07:26 AM
  5. Script To Change A Registry Key
    By DaveP in forum Windows
    Replies: 6
    Last Post: 7th March 2007, 12:57 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •