PhoxNet

home programming links about

VBScript: Obtaining Registry Data Part 2

The boss wants this done now. This means the change has to happen remotely as we can't wait for a user to logon to apply the change locally. Unfortunately, the WScript.Shell object does not allow for remote access to the registry. In this case, we'll to instantiate another method of registry access. One that allows for remote access.

The Standard Registry Provider is exactly that object. It allows us to connect to the remote registry by establishing a Windows Managment Instrumentation (WMI) connection with the remote computers StdRegProv.

set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

Using the Standard Registry Provider (objReg) is a robust way of accessing a computers registry. However, this method requires low level specific. Notice, in the example below, that we can no longer use literals to access different hives. Instead, a HEX representaiton of where the hive can be found is required. Below is a list of hives, their abbreviation (commonly used with objShell's registry method), and HEX address.

Hive Abbreviation HEX
HKEY_CLASSES_ROOT HKCR &H80000001
HKEY_CURRENT_USER HKCU &H80000002
HKEY_LOCAL_MACHINE HKLM &H80000003
HKEY_USERS HKU &H80000004
HKEY_CURRENT_CONFIG HKCC &H80000005

Let's say for the sake of simplicity that we have an array, arrComputers, that has the name of all the computers on the network. Let's remove all mapped drives from all computers in arrComputers.

Because the network drive mappings are located in the HKEY_CURRENT_USER hive, we need to use the HEX address for the HKEY_CURRENT_USER hive. You can use the HEX directly with the objReg methods but it's advisable that you create a constant and assign the HEX value to it for use with objReg.

CONST HKEY_CURRENT_USER = &H80000001 'HEX that represents the HKEY_CURRENT_USER hive.

set objNetwork = WScript.CreateObject("WScript.Network")

for each strComputer in arrComputers
    set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    colDrives = objNetwork.EnumNetworkDrives()
    for i = 0 to (colDrives.count - 1) step 2
        if (colDrives.item(i) <> "U:") then
            objReg.DeleteStringValue HKEY_CURRENT_USER, "Network", left(colShared.item(i), 1)
        end if
    next
next

Looks good, right? Wrong! The network object, objNetwork, only works on the local machine. Even though we established a connection to the remote registry, objReg, the network object doesn't have remote functionality.

How, then, can we enumerate the mapped drives? Fortunately, objReg has a nice little function called .EnumKey which we can use to enumerate the current user's network reg key.

CONST HKEY_CURRENT_USER = &H80000001 'HEX that represents the HKEY_CURRENT_USER hive.

for each strComputer in arrComputers
    set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    objReg.EnumKey HKEY_CURRENT_USER, "Network", arrDrives
    for each strDrive in arrDrives
        if (strDrive <> "u") then
            objReg.DeleteKey HKEY_CURRENT_USER, "Network", strDrive
        end if
    next
next

Notice that our method of deleting the drive mappings is different that before. This is because objNetwork.EnumNetworkDrives() returns a single collection object that we must iterate in order to obtain the data we want. objReg.EnumKey, on the other hand, simply returns the name of the keys - no objects.

The boss's mind is running wild and he is now concerned about ANY AND ALL drive mapping. Therefore, he wants all drive mappings for all users on all computer to be removed immediately. What to do!?

We'll need to discover the SIDs of all the users that have a profile on a particular machine. Once obtained, we can use that with HKEY_USERS to indirectly access the HKEY_CURRENT_USER hive. But how do we discover which users have a profile on the machine? There are actually several ways but the easiest and simplest way is to enumerate the ProfileList reg key located in the HKEY_LOCAL_MACHINE hive.

CONST HKEY_LOCAL_MACHINE = &H80000002 'HEX that represents the HKEY_LOCAL_MACHINE hive.
CONST HKEY_USERS = &H80000003 'HEX that represents the HKEY_USERS hive.

for each strComputer in arrComputers
    'connect to remote computer registry
    set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    
    'discover user SIDs
    objReg.EnumKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", arrSIDs
    
    for each strSID in arrSIDs
        'We only care about user SIDs - those that begin with S-1-5-21-
        if (left(strSID, 9) = "S-1-5-21-") then
            'Enumerate the user's drive mappings
            objReg.EnumKey HKEY_USERS, strSID & "\Network", arrDrives
            for each strDrive in arrDrives
                objReg.DeleteKey HKEY_USERS, strSID & "\Network", strSID
            next 
        end if
    next
next

After you run this, the boss gives you a raise. Good job!



Comments















































































































































































































































Your web site provided us with valuable info to

weed safety delivered

Robin

Dann

Floyd

Coy

Trisha

Erna

Vera

Imogene

Nichole

Mora

Katharina

Sonya

Alanna

Julia

Julia

Ardis

Sabina

Isla

Isla

Janet

Oscar

Isabella

Michael

Wallace

Murray

James

Evelyne

Horacio

Frank

Alejandrina

Kandace

Elouise

Roland

Valentin

Octavio

Nona

Jerrod

Iris

Finley

Eric

Georgiana

Hollis

Corey

Carma

Arden

Arden

Arden

Arden

Bailey

August

Benito

Leoma

Terra

Mari

Allie

Elsie

Katia

Finlay

Christopher

Callum

Jamal

Cliff

Leslie

Phillis

Zora

Bruno

Ima

Pam

Louella

Margie

Eartha

Mark

Jerry

Jerry

Marco

Sima

Jasmin

Arnette

Demetrius

Dewey

Lino

Minda

Mora

Ramona

Chassidy

Roderick

Santos

Debbra

Rosalyn

Rosalyn

Bruno

Aundrea

Larae

Adele

Jeana

Thad

Geneva

Eunice

Ella

Quyen

Brianna

Leon

Felicitas

Leon

Darren

Chante

Leonida

Leonida

Leonida

Kerry

Adan

Jessika

Beau

Robbin

Jayden

Penny

Viola

Sherita

Prince

Kim

Caroline

Jonas

Lela

Damien

Loretta

Renee

Winfred

Edwin

Angelina

Mohammed

Tatiana

Santiago

Yetta

Phillis

Christy

Winifred

Miranda

Roger

Erika

Louisa

Ute

Bernadine

Oren

Carroll

Lina

Natasha

Deneen

Albertina

Adelaida

Ladonna

Ryder

Aaron

Aaron

Aaron

Lorena

Aimee

Yasmin

Bea

Nelle

Nicolas

Abraham

Carri

Bettie

Grant

Jennie

Stephen

Albertina

Albertina

Albertina

Louise

Tara

Tara

Maximilian

Cleveland

Charissa

Charissa

Charissa

Linnea

Jamaal

Jamaal

Nigel

Kisha

Lizette

Homer

Oliver

Deborah

Marianne

Irwin

Brandy

Johnathan

Archie

Natalie

Latonya

Fanny

Kandi

Hermine

Reuben

Herbert

Gavin

Clement

Chong

Wilburn

Keith

Margareta

Willy

Raina

Dong

Nilda

Debra

Herbert

Mellissa

Thad

Barb

Tracey

Annmarie

Kendrick

Kendrick

Belle

Alfred

Alberto

Carl

Trent

Glenna

Virgilio

Dina

Thao

Thao

Damien

Darrin

Valentin

Cassandra

Ramona

Kristeen

Bess

Casey

Ophelia

Florrie

Steven

Odessa

May

Cathy

Lenore

Jenni

Martha

Ahmed

Mayra

Aracelis

Luke

Gayle

Bert

Mable

Claire

Leora

Dewitt

Emanuel

Garrett

Desiree

Federico

Carlton

Homer

Horacio

Chanel

Hildegarde

Chiquita

Edgar

Aracely

Steffen

Melva

Julieta

Julieta

Shana

Cinda

Lonny

April

Muhammad

Brad

Mark

Dedra

Monserrate

Torsten

Boris

Barry

Gonzalo

Sally

Justina

Justina

Billy

Keith

Glory

Ethan

Jesus

Millard

Veda

Vanessa

Gerald

Jesse

France

Star

Princess

Eartha

Maria

Marcelino

Hildegarde

Ulrich

Guadalupe

Elmer

Gerard

Buck

Dominic

Winnie

Malcolm

Eve

Zandra

Sophie

Joanna

Jasper

Melvin

Elsa

Ulysses

Harry

Valentin

Andrew

Andrew

Deneen

Clarissa

Belle

Phillipp

Lester

Romaine

Jacquie

Anita

Shoshana

Kennith

Elizbeth

Brittany

Trey

Joesph

Maxie

Mathew

Taj

Elana

Andreas

Kassandra

Halley

Adrian

Quincy

Felix

Seymour

Jillian

Terry

Jodie

Greg

Fannie

Lora

Titus

Magda

Jasper

Antonia

Terese

Rudy

Roosevelt

Jay

Chau

Elke

Lan

Errol

Aline

Chance

Georgiana

Georgiana

Phyllis

Kira

Joel

Damian

Rosalinda

Piper

Johnson

Raquel

Gilda

Delmar

Maritza

Kandice

Mose

Mose

Erwin

Dominga

Marian

Louis

Duane

Nida

Williemae

Madge

Walker

Kendrick

Ann

Maisie

Julius

Isabelle

Aiden

Evita

Christopher

Gidget

Leslie

Beulah

Elisa

Christi

Raphael

Christa

Fawn

Elana

Annmarie

Clarissa

Danny

Vincent

Ola

Hermelinda

Nikole

Imogene

Fredericka

Anna

Anna

Hugh

Cortney

Johanna

Darnell

Meredith

Meredith

Jaclyn

Abby

Mark

Rosella

Erin

Alison

Zac

Fannie

Darcy

Richelle

Fredericka

Jeffery

Marcela

Cheryl

Billie

Gilbert

Rosetta

Aurora

Leonora

Gabrielle

Mario

Mira

Frances

Jann

Nick

Connie

Linda

Klaus

Austin

Thomas

Cory

Jeremy

Shona

Maurine

Johnathan

Johnathan

Jaxon

Carmelo

Danilo

Leonardo

Maryanne

Elaine

Niklas

Tiffiny

Leanna

Virgil

Gladys

Monty

Jeanette

Derrick

Zulma

Phillip

Luann

Ernestina

Henry

Jonelle

Beatris

Loren

Frederick

Angus

Renee

Carrie

Colby

Kurt

Mikayla

Gregorio

Lashawnda

Concepcion

Miquel

Trudy

Corine

Micki

Micki

Geoffrey

Claude

Virgil

Gonzalo

Gonzalo

Shannon

Kian

Yetta

Kermit

Reina

Flossie

Eileen

Graig

Vaughn

Reva

Blanche

Donette

Mira

Jeffry

Mike

Toney

Sue

Christa

Elbert

Pasquale

Jayne

Marty

Lydia

Don

Shari

Arianne

Juliann

Jason

Allan

Nickolas

Rafaela

Annette

Maik

Sharyl

Fernando

Hayden

Tessa

Stephan

Alphonse

Flossie

Gretchen

Noreen

Aliza

Hildegarde

Octavio

Alexandra

Jason

Lacy

Zita

Trey

Frances

Letha

Evonne

Melodee

Ambrose

Michell

Karma

Gabrielle

Porter

Caroline

Alison

Lillian

Florine

Julienne

Justina

Alycia

Kris

Iris

Luis

Luis

Lilla

Derick

Terry

Esteban

Juliane

Roy

Rocky

Curtis

Boyd

Jett

Angeline

Monica

Leopoldo

Rickie

Darrell

Trent

Malcolm

Blake

Maryann

Lashunda

Candra

Duane

Zita

Cristina

Lucy

Onita

Antoinette

Tracee

Maik

Reagan

Alethea

Lola

Sommer

Bennie

Gabriela

Alica

Jeramy

Oren

Sima

Finlay

Maurice

Maurice

Sherri

Faith

Faith

Carla

Laurinda

Cooper

Luigi

Forest

Allison

Graig

Vernita

Galen

Mel

Cora

Jorja

Gladys

Nick

Blanca

Bennie

Jacki

Lashonda

Gertie

Phillis

Octavio

Murray

Wilhemina

Penney

Kassie

Kassie

Mercedes

Kandi

Carmen

Josette

Dyan

Abbey

Rowena

Sabrina

Tomoko

Tomoko

Sheldon

Clifton

Yvette

Olive

Wilhemina

Velva

Jed

Dallas

Jed

Reyna

Les

Florene

Leandra

Raymon

Sanora

Tilly

Roxanne

Napoleon

Bobbye

Dell

Benito

Jesus

Niki

Lurlene

Charline

Brittny

Megan

Christa

Dolly

Lien

Wolfgang

Jeanna

Brenton

Jordan

Boris

Erika

Doyle

Latesha

Dominga

Myles

Hunter

Jane

Antonetta

Candra

Tahlia

Elinor

Olga

Prince

Ciara

Kacey

Santo

Santo

Santo

Kathy

Ruby

Oscar

Emmett

Waylon

Kraig

Santo

Tiffany

Lorenza

Ngan

Finn

Randy

Arron

Martina

Luke

Uta

Barb

Cecelia

Colleen

Gail

Waldo

Roberto

Andres

Carmela

Amee

Theron

Shirleen

Mac

Fannie

Fannie

Fannie

Sung

Sung

Sung

Edward

Greta

Jayme

Dorine

Kacey

Mathew

Phillip

Alvin

Donnie

Victoria

Effie

Angelika

Lakesha

Fausto

Malissa

Lyle

Vicki

Sharyl

Gidget

Arletha

Magnolia

Klaus

Hester

Kimberly

King

Mabel

Mabel

Gretchen

Alton

Lavonne

Derek

Andre

Kristeen

Bettie

Kelle

Summer

Marie

Marie

Marie

Klaudia

Adell

Gia

Gia

Edison

Christopher

Helena

Jina

Jamal

Carlos

Carlos

Charmain

Charla

Clarissa

Bettina

Shannan

Launa

Shannon

Chana

Frederick

Reinaldo

Mia

Katie

Ladonna

Wayne

Delphia

Deloris

Connie

Connie

Larue

Jamison

Odette

Stephen

When it comes to accessories like this, the old advice \"you get what you pay for\" applies.

Fred

Keesha

Una

Rosaura

Mason

Jacinto

Ciara

Shalanda

Rafael

Carlos

Efren

Penelope

Lesley

Rodrick

taxes due within the last three years, and debts that resulted

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-30-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

Mobile Homes Park Modl Homes, BC Alberta - Mobile Home Towing, Travel Trailer

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-29-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-28-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-27-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-26-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-25-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-24-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-23-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-22-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16

05-21-16