locked
Can a wild card be used for registry key value names in a script like this? RRS feed

  • Question

  • Basically I'm trying to create a script that when ran will look for any devices in the registry key that begin with a double slash and remove them. I can go into more detail but it would be lengthy and pointless. There are to many names to just write a script with all of them. I can handle writing the loop but I need help getting this part to work first. Thanks in advance for any help.

    REG DELETE HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices /v \\* /f

    Wednesday, July 22, 2015 1:35 PM

Answers

All replies

  • I can go into more detail but it would be lengthy and pointless.

    That depends entirely on whether the reasoning behind this exercise is valid.

    To directly answer the question in your subject line: You can find this out for yourself by trying it and seeing if it works.

    Also, be aware that HKCU literally means "current user" (you, when you are logged on). It does not mean "user that might be logged on interactively on a remote computer."


    -- Bill Stewart [Bill_Stewart]

    Wednesday, July 22, 2015 2:10 PM
  • I know what it means. The devices I'm try to remove only show up when that user is logged in which is why this script will be pushed out to all computers and run on whenever a user logs on to clear any printers they have added. The device name or registry value I want to remove starts with \\ since it is a network path and there are 8 different servers it can be and 100+ different printers. If it was added correctly it would simply be the printer name.
    Wednesday, July 22, 2015 4:00 PM
  • So the purpose is to remove all network printers a user might have added?

    Why?


    -- Bill Stewart [Bill_Stewart]

    Wednesday, July 22, 2015 4:03 PM
  • Group Policy can be set to disallow users from making printer connections "persist" so they do not persist across logons.

    In all cases using GP will be better even for registry changes.


    \_(ツ)_/

    Wednesday, July 22, 2015 4:05 PM
  • Because that isn't how our system is setup and again it would take to long to explain unless you want about 100 page post about how Meditech does print jobs. When the user has a mapped printer to a print server they shouldn't be accessing they end up sending bad print jobs that hold up all print jobs.
    Wednesday, July 22, 2015 4:24 PM
  • We have tested the group policies that would apply to this issue and they do not prevent the issue. If a user knows the full path to the printer they can still manage to add the printer.
    Wednesday, July 22, 2015 4:26 PM
  • It sounds to me like you have a user training problem rather than a technical problem.

    In any case, if you insist on removing printers added by a user, I would recommend approved techniques such as the WshNetwork object's RemovePrinterConnection method.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, July 22, 2015 4:47 PM
  • Because that isn't how our system is setup and again it would take to long to explain unless you want about 100 page post about how Meditech does print jobs. When the user has a mapped printer to a print server they shouldn't be accessing they end up sending bad print jobs that hold up all print jobs.

    That is what printer permissions are for.


    \_(ツ)_/

    Wednesday, July 22, 2015 5:15 PM
  • We have tested the group policies that would apply to this issue and they do not prevent the issue. If a user knows the full path to the printer they can still manage to add the printer.

    Again - That is what printer permissions are for.

    You are trying to re-invent printing because your print deployment is incomplete and/or not designed.  With many companies printing is just a thing without too much thought until things go wrong then someone is tasked with applying bandaids.  Don't patch.  Fix the underlying problem.  Messing with the registry will likely only create more problems.

    No - there is no wild card in registry maintenance.  You can delete a key and its contents but you cannot delete just the contents without enumerating the contents.

    GP can disallow persisting printers.  Printer permissions can eliminate unwanted usage.


    \_(ツ)_/

    Wednesday, July 22, 2015 5:21 PM
  • It's important to take a good approach and think about the actual goals instead of deciding that a scripting is the cure for everything. Sometimes a script is needed, but this depends on the scenario.

    Don't be like the person described here:

    The frustration of people who have already decided on the solution and won't let you derail them with your annoying questions


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Monday, July 27, 2015 7:28 PM
    • Marked as answer by Bill_Stewart Tuesday, August 25, 2015 11:48 PM
    Wednesday, July 22, 2015 5:22 PM
  • jrv you clearly have no idea what you are talking about and should take your trolling else where. I appreciate the help Bill and will look into that method. User training isn't an option because doctors don't care what you have to say because in their mind they are always right.
    Wednesday, July 22, 2015 5:31 PM
  • jrv you clearly have no idea what you are talking about and should take your trolling else where. I appreciate the help Bill and will look into that method. User training isn't an option because doctors don't care what you have to say because in their mind they are always right.

    Not trolling.  I have fought this battle sinceNT4 and usually win.  Once admins learn how to use print services, AD and GP as intended these issues go away and life gets easier.

    Refusal to actually consider solutions provided by many who clearly have greater experience is not a good way to solve technical problems.


    \_(ツ)_/

    Wednesday, July 22, 2015 6:05 PM
  • I didn't code Meditech and neither did you, you make assumptions that you know how things are and how they should be. You are just like the techs we get that remote into machine and change settings that they know nothing about and than oh gee now the PC has no network connection. I asked a simple question that neither of you answered, instead you avoided the question and went down a path you where more comfortable with. The print servers are the way they are because that is how Meditech a UNIX based system needs them to be. The system was fine till Windows 7 was introduced. Stick to the questions asked instead of assuming you know best.
    Wednesday, July 22, 2015 6:13 PM
  • Two easy ways

    powerShell.

    GWMI Win32_Printer -Filter 'Network=TRUE'|%{$_.Delete()}

    and BATCH

    WMIC printer where "Network-True" delete


    \_(ツ)_/

    Wednesday, July 22, 2015 6:15 PM
  • I didn't code Meditech and neither did you, you make assumptions that you know how things are and how they should be. You are just like the techs we get that remote into machine and change settings that they know nothing about and than oh gee now the PC has no network connection. I asked a simple question that neither of you answered, instead you avoided the question and went down a path you where more comfortable with. The print servers are the way they are because that is how Meditech a UNIX based system needs them to be. The system was fine till Windows 7 was introduced. Stick to the questions asked instead of assuming you know best.

    Now you are just trying a little CYA because you aren't getting what you want and think throwing Unix on the table will help.  I was building Unix systems before you were born.

    Anyway - don't bitch.  You have all possible solutions.  Just pick the one that best suits you.  In theendyou still have to write thescript and test it.


    \_(ツ)_/

    Wednesday, July 22, 2015 6:33 PM
  • Stick to the questions asked instead of assuming you know best.

    You seem to think you're entitled to something here.

    This is a free forum, staffed by volunteers. If you don't like the answers provided, you're always free to go elsewhere. We generally avoid hacky workarounds here, because they're not stable in the long term.


    Wednesday, July 22, 2015 6:44 PM