Cybex
-
Total Posts
:
415
- Scores: 0
-
Reward points
:
0
- Joined: 9/14/2005
- Location: Florida
-
Status: offline
|
Help needed reading registry keys and formatting output.
Wednesday, February 01, 2012 10:00 AM
( permalink)
First off, long time no post... Sorry it's been so long. I have the following code working on a local machine and have altered it here to show my final intent to fun against remote machines, however, I don’t know if my code is 100% correct yet for remote action… Option Explicit Dim strComputer, objReg, strKeyPath, arrSubKeys, SubKey, arrComputers arrComputers = Array("PC001","PC002","PC134","PC014","PC098","PC076","PC178") For Each strComputer In arrComputers Const HKEY_LOCAL_MACHINE = &H80000002 'strComputer = "." Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Windows Portable Devices\Devices" 'strKeyPath = "SYSTEM\CurrentControlSet\Services" objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys For Each Subkey In arrSubKeys WScript.Echo Subkey Next Next Output from run on local machine (call it PC001)… WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_SD#VID_03&OID_5344&PID_SU04G&REV_8.0#5&52A46A&0&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_&PROD_USB_DISK2.0&REV_1.09#0742150000CF&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_HTC&PROD_ANDROID_PHONE&REV_0100#HT1AYMA06874&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_KINGSTON&PROD_DT_BLACKBOX&REV_6.61#0D91A380E2E35A29&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_KINGSTON&PROD_DT_VAULT&REV_104#07005B831B000429&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_PNY&PROD_USB_2.0_FD&REV_PMAP#6E6807002ECA&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_SANDISK&PROD_CRUZER_MINI&REV_0.1#SNDK8C1B340CC1F08506&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_SONY&PROD_STORAGE_MEDIA&REV_0100#2A07031925256&0# WPDBUSENUMROOT#UMB#2&37C186B&0&STORAGE#VOLUME#_??_USBSTOR#DISK&VEN_CHEAP&PROD_Gen_STORAGE&REV_0100#6&26c97b61&0&0# Keys with USBSTOR (the ones that I want returned) broken out into their different array sections… (Del) Manufacture (Del) Device Name (Del) Device Serial Number (Del) &VEN_ USB_DISK2.0 &REV_1.09# 0742150000CF &0# &VEN_ HTC &PROD_ ANDROID_PHONE &REV_0100# HT1AYMA06874 &0# &VEN_ KINGSTON &PROD_ DT_BLACKBOX &REV_6.61# 0D91A380E2E35A29 &0# &VEN_ KINGSTON &PROD_ DT_VAULT &REV_104# 07005B831B000429 &0# &VEN_ PNY &PROD_ USB_2.0_FD &REV_PMAP# 6E6807002ECA &0# &VEN_ SANDISK &PROD_ CRUZER_MINI &REV_0.1# SNDK8C1B340CC1F08506 &0# &VEN_ SONY &PROD_ STORAGE_MEDIA &REV_0100# 2A07031925256 &0# &VEN_ CHEAP &PROD_ GENERIC_STORAGE &REV_0100# 6&26c97b61&0 &0# Sudo code: If key name contains “USBSTOR#DISK&VEN” then If second character in device serial number is not “&” then Print machine name, Manufacture, Device Name, Device Serial Number End if End if Desired output text file: Machine Name Manufacture Device Name Device Serial Number PC001 USB_DISK2.0 0742150000CF PC002 HTC ANDROID_PHONE HT1AYMA06874 PC134 KINGSTON DT_BLACKBOX 0D91A380E2E35A29 PC014 KINGSTON DT_VAULT 07005B831B000429 PC098 PNY USB_2.0_FD 6E6807002ECA PC076 SANDISK CRUZER_MINI SNDK8C1B340CC1F08506 PC178 SONY STORAGE_MEDIA 2A07031925256 Doing this in Windows seems much harder than it should be. I am guessing this is user induced pain… I am so used to doing this stuff in unix with sed and awk I don’t even know when to start being limited to native windows capabilities. Thanks, Cybex
Common sense is not so common.
|
|
|
|
59cobalt
-
Total Posts
:
972
- Scores: 91
-
Reward points
:
0
- Joined: 7/17/2011
-
Status: online
|
Re:Help needed reading registry keys and formatting output.
Wednesday, February 01, 2012 11:14 AM
( permalink)
When in doubt, read the documentation. If InStr(subkey, "USBSTOR") > 0 Then
arr1 = Split(subkey, "#")
If Mid(arr1(6), 2, 1) <> "&" Then
serial = Replace(arr1(6), "&0")
arr2 = Split(arr1(5), "&")
vendor = Replace(arr2(1), "VEN_")
name = Replace(arr2(2), "PROD_")
output.WriteLine strComputer & vbTab & vendor & vbTab & name & vbTab & serial
End If
End If output could be STDOUT (if you run the script with cscript.exe): Set output = WScript.StdOut or a handle to an open file: Set fso = CreateObject("Scripting.FileSystemObject")
Set output = fso.OpenTextFile("\PATH\TO\output.txt", 2, True)
' do stuff
output.Close Or, you could stick with sed and awk. They're available for Windows, too.
|
|
|
|