Question

Enumerate registry keys and change a REG_SZ value

Asked by: ednetman

I had posted the same thing before for DWORD values and "vinnyd79" was able to come up with something for me in post number:

"http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21617347.html"

In the end of the post he mentioned that to change a string value you would need to add routines for that.  The form looks great as it is, but I would like to have to input fields where you can type in the key name and the new value you want to search for, also have it accept those values from a command line when run in silent mode.  This part can be either from a switch or from a text file.

Something like /Key:Wallpaper /Value:%windir%\CompanyLogo.BMP
or from a text file:
Wallpaper,%windir%\CompanyLogo.BMP

The last post fixed so much for us last time, that the team is BEGGING for more!  I will award 500 points for an answer on this one.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-12-13 at 09:28:38ID21663144
Tags

enumerate

,

registry

Topic

Visual Basic Programming

Participating Experts
1
Points
500
Comments
61

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Write Double Dword to registry?
    I need to write a double-long dword value to the registry from a VB app. I am using a modregistry.bas file from the following link http://www.freevbcode.com/code/mkcRegistry.zip which allows me to add normal long variables to the registry without any problem. Unfortunately ...
  2. Set wallpaper
    Hi, I am currently using the SystemParametersInfo API to set my wallpaper. How can I use an alternative that will work on all operating system but I can specify how the wallpaper is changed. For exmaple, centered, stretched, tiled. Thanks
  3. Dword usage?
    I know this may sound like a dumb question but can someone tell what a DWord is used for? Thanks, -John
  4. How do i store a REG_MULTI_SZ value to the registry?
    How do i store a REG_MULTI_SZ value to the registry? (String data)
  5. Can't change wallpaper.
    I have just been messing with my desktop. And after using TweakXP, or something (sorry I'm not sure of what caused it). I lost the tab to change my desktop's wallpaper in the display configuration set :-/

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: vinnyd79Posted on 2005-12-14 at 10:11:05ID: 15484196

If nobody gets to this I should be able to help you with this later.Right now I have a project I need to finish.

 

by: ednetmanPosted on 2005-12-15 at 07:11:28ID: 15490618

Sounds like a plan!  I can wait if nobody else wants to take a shot.

 

by: ednetmanPosted on 2005-12-19 at 11:48:19ID: 15513599

Anyone else want to give this a try?

 

by: vinnyd79Posted on 2005-12-20 at 13:18:59ID: 15521919

Sorry for the delay,My job keeps hitting me with projects that needed to be done yesterday.
Ok,be careful with this. It would be wise to backup the registry before testing.The gui now has inputs for value to search for and the value data to set.You can specify these with the /v switch for valuename and the /d switch for value data. For example

regsearch /q /v Wallpaper /d C:\Clouds.bmp /L C:\logfile.txt

The logfile will now also show the value before and after replacing.Also keep in mind that certain changes might require a logoff or reboot to become effective.


Here is the new Regsearch.vbp file.


'************* ReegSearch.vbp ***********************
Type=Exe
Form=frmMain.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\System32\stdole2.tlb#OLE Automation
Class=cRegSearch; cRegSearch.cls
IconForm="frmMain"
Startup="frmMain"
ExeName32="RegSearch.exe"
Path32="..\..\..\.."
Command32=""
Name="RegSearch"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="SND"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1
'***************** End RegSearch.vbp *********************



Here is the new frmMain.frm file


'**************** frmMain.frm *****************************
VERSION 5.00
Begin VB.Form frmMain
   Caption         =   "Search Registry"
   ClientHeight    =   1890
   ClientLeft      =   1260
   ClientTop       =   2715
   ClientWidth     =   9360
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   1890
   ScaleWidth      =   9360
   Begin VB.TextBox txtValData
      Height          =   375
      Left            =   3600
      TabIndex        =   7
      Top             =   720
      Width           =   3135
   End
   Begin VB.TextBox txtValName
      Height          =   375
      Left            =   480
      TabIndex        =   6
      Top             =   720
      Width           =   2655
   End
   Begin VB.CommandButton cmdSearch
      Caption         =   "&Search"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   7080
      TabIndex        =   0
      Top             =   720
      Width           =   1695
   End
   Begin VB.Label Label2
      Caption         =   "Value Data to Set :"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3600
      TabIndex        =   9
      Top             =   480
      Width           =   2535
   End
   Begin VB.Label Label1
      Caption         =   "Value Name to Search For :"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   480
      TabIndex        =   8
      Top             =   480
      Width           =   2655
   End
   Begin VB.Label lblOccur
      Caption         =   "0"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8280
      TabIndex        =   5
      Top             =   120
      Width           =   615
   End
   Begin VB.Label lblProf
      Caption         =   "0"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5280
      TabIndex        =   4
      Top             =   120
      Width           =   615
   End
   Begin VB.Label lblDsp
      Caption         =   "Occurrences Found :"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   1
      Left            =   6240
      TabIndex        =   3
      Top             =   120
      Width           =   1935
   End
   Begin VB.Label lblDsp
      Caption         =   "Profiles Scanned :"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Index           =   0
      Left            =   3480
      TabIndex        =   2
      Top             =   120
      Width           =   1695
   End
   Begin VB.Label lblProg
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   1320
      Width           =   8895
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1
Private Const REG_DWORD = 4

Dim WithEvents creg As cRegSearch
Attribute creg.VB_VarHelpID = -1
Dim UserProfileList As Collection
Dim CurrentProfile As String, LogFile As String
Dim Silent As Boolean

Public Sub SearchRegistry(SearchHive As ROOT_KEYS, SearchStr As String)
Set creg = New cRegSearch
creg.RootKey = SearchHive
creg.SubKey = ""
creg.SearchFlags = 1
creg.SearchString = SearchStr
CurrentProfile = "Local & Current Logged on User (" & Environ("Username") & ")"
If Silent = False Then lblProf = Val(lblProf) + 1
' search Loaded registry files
creg.DoSearch
Set creg = Nothing

Set creg = New cRegSearch

CurrentProfile = ""

' get list of profiles and put in UserProfileList Collection
Call LoadProfileList
Dim Item As Variant, UserName As String
' loop through collection checking for users ntuser.dat file
For Each Item In UserProfileList
    UserName = Mid$(Item, InStrRev(Item, "\") + 1)
    If Dir(Item & "\ntuser.dat", vbHidden) <> "" Then
        If UserName <> Environ("UserName") Then
            If UserName <> "All Users" Then
                CurrentProfile = UserName
                If Silent = False Then lblProf = Val(lblProf) + 1
                ' load users ntuser.dat file
                Call creg.LoadUsersHive(Item & "\ntuser.dat")
                ' search users loaded hive
                creg.RootKey = HKEY_USERS
                creg.SubKey = "keyLoaded"
                creg.SearchFlags = 1
                creg.SearchString = SearchStr
                creg.DoSearch
                ' unload users loaded hive
                Call creg.UnloadDatFile("keyLoaded")
                       
            End If
        End If
    End If
    DoEvents
Next

Set creg = Nothing

If Silent = False Then
    lblProg = "Search Complete!"
    Dim ViewLog As VbMsgBoxResult
    ViewLog = MsgBox("Process has completed. Would you like to view the log file?", vbExclamation + vbYesNo, "Process Complete!")
    If ViewLog = vbYes Then
        Call Shell("Notepad.exe " & LogFile, vbNormalFocus)
    End If
Else
    Unload Me
End If

End Sub

Private Sub cmdSearch_Click()
If Trim$(txtValName) = "" Then
    MsgBox "No Value to Search for has been specified.", vbCritical, "No Search Value Specified!"
    Unload Me
End If

If Trim$(txtValData) = "" Then
    MsgBox "No Value to Set has been specified.", vbCritical, "No Value Specified!"
    Unload Me
End If
lblProf = 0: lblOccur = 0
Call SearchRegistry(HKEY_ALL, txtValName)
End Sub

Private Sub cReg_SearchFound(ByVal sRootKey As String, ByVal sKey As String, ByVal sValue As Variant, ByVal lFound As FOUND_WHERE)
Dim sTemp As String
Dim sValName As String

sValName = Mid$(sKey, InStrRev(sKey, "\") + 1)

If sValName <> txtValName Then Exit Sub

   Select Case lFound
         Case FOUND_IN_KEY_NAME
              sTemp = "KEY_NAME"
         Case FOUND_IN_VALUE_NAME
              sTemp = "VALUE NAME"
         Case FOUND_IN_VALUE_VALUE
              sTemp = "VALUE VALUE"
   End Select
   
   If Silent = False Then lblOccur = Val(lblOccur) + 1
   
    Dim ff As Integer
    ff = FreeFile
    Open LogFile For Append As #ff
    Print #ff, Trim$(CurrentProfile), "," & sRootKey & "," & sKey & "," & sValue & "," & txtValData
    Close #ff
   
    Dim RegHive As Long
    Select Case sRootKey
        Case "HKEY_CLASSES_ROOT"
            RegHive = &H80000000
        Case "HKEY_CURRENT_USER"
            RegHive = &H80000001
        Case "HKEY_LOCAL_MACHINE"
            RegHive = &H80000002
        Case "HKEY_USERS"
            RegHive = &H80000003
        Case "HKEY_CURRENT_CONFIG"
            RegHive = &H80000005
    End Select
   
If IsNumeric(txtValData) = True Then
    Call SaveDword(RegHive, Left$(sKey, InStrRev(sKey, "\") - 1), txtValName, txtValData)
Else
    Call SaveString(RegHive, Left$(sKey, InStrRev(sKey, "\") - 1), txtValName, txtValData)
End If

End Sub

Private Function SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim keyhand As Long, r As Long
r = RegCreateKey(hKey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strData, Len(strData))
r = RegCloseKey(keyhand)
End Function

Private Function SaveDword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
Dim lResult As Long, keyhand As Long, r As Long
r = RegCreateKey(hKey, strPath, keyhand)
lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
r = RegCloseKey(keyhand)
End Function

Private Sub Form_Load()
Dim arrArgs() As String, i As Integer
Silent = False
' check if app is in root dir
If Right$(App.Path, 1) <> "\" Then
    LogFile = App.Path & "\MyLog.txt"
Else
    LogFile = App.Path & "MyLog.txt"
End If

If Trim$(Command$) <> "" Then
    arrArgs = Split(Command$, " ")
   
    For i = 0 To UBound(arrArgs)
        Select Case arrArgs(i)
            Case "/q", "/Q"
                Silent = True
            Case "/l", "/L"
                LogFile = arrArgs(i + 1)
            Case "/v", "/V"
                txtValName = arrArgs(i + 1)
            Case "/d", "/D"
                txtValData = arrArgs(i + 1)
            Case "/?", "/help", "/HELP"
                Call MsgBox("Command Line Switches:" & vbCrLf & _
                            "/q or /Q  - Quiet Operation. Displays no Dialogs." & _
                             vbCrLf & "/v or /V  - [Value Name] - Value Name to Search For." & _
                             vbCrLf & "/d or /D  - [Value Data] - Value Data to Add." & _
                             vbCrLf & "/l or /L [logfilename] - Specify Log FileName." & _
                             vbCrLf & Space$(35) & "Filename must not contain spaces." & _
                             vbCrLf & Space$(35) & "Example: /L C:\MyLogfile.txt" & vbCrLf & _
                             "/? or /help or /HELP - Displays Help.", vbQuestion, "Help")
        End Select
    Next i
  If Trim$(txtValName) = "" Then
    MsgBox "No Value to Search for has been specified.", vbCritical, "No Search Value Specified!"
    Unload Me
    End
  End If

  If Trim$(txtValData) = "" Then
    MsgBox "No Value to Set has been specified.", vbCritical, "No Value Specified!"
    Unload Me
    End
  End If
End If

If Dir$(LogFile) <> "" Then Kill LogFile

If Silent = True Then
    Call SearchRegistry(HKEY_ALL, txtValName)
End If
End Sub
 
Private Sub LoadProfileList()
Set UserProfileList = New Collection
Dim BaseDir As String, strFolder As String
BaseDir = Environ("UserProfile")
BaseDir = Left$(BaseDir, InStrRev(BaseDir, "\") - 1) & "\"
strFolder = Dir(BaseDir, vbDirectory)
Do While strFolder <> ""
    If strFolder <> "." Or strFolder <> ".." Then
        If (GetAttr(BaseDir & strFolder) And vbDirectory) Then
            UserProfileList.Add BaseDir & strFolder
        End If
    End If
    strFolder = Dir()
    DoEvents
Loop
End Sub

Private Sub cReg_SearchKeyChanged(ByVal sFullKeyName As String)
   If Me.WindowState <> vbMinimized Then lblProg = sFullKeyName
End Sub
'*************** End frmMain.frm *************************


I don't think I made any changes to the .cls file so that one should be the same.

Try it out and let me know how it goes.


 

by: ednetmanPosted on 2005-12-20 at 13:46:25ID: 15522141

THANKS!!!!!!

This is going to be great!  I'll compile this and run it on a test box today.  I have a quick question though.  

The first line of: frmMain.frm says: VERSION 5.00.  Is this the version of VB?  If so, is there any issue with compiling under VB6 or .Net?

Thanks again, I'll let you know how it goes!

 

by: ednetmanPosted on 2005-12-20 at 15:39:41ID: 15522849

ested the code and it works great for all profiles that have logged in before.  The only issue is it did not modify the default user profile or the current user (administrator).  I had to path out to the file, I wasn't able to use variables such as %windir%\test_image.bmp.

Oh, will this change only REG_SZ values or will it change others as well?

I wasn't sure because I saw:
Private Const REG_SZ = 1
Private Const REG_DWORD = 4

and then saw:
creg.SearchFlags = 1

and I figured that meant REG_SZ only.  Then I was thinking about trying to add one more switch that let you determine regesty key type, such as
/1 = REG_SZ
/2 = REG_MULTI_SZ
/3 = REG_BINARY
/4 = REG_DWORD

Or would there be a way to tell it to check all 4 types?  As before, exclude classes, since those values aren't affected.

Thanks again for the help, I know what you mean about the crazy due dates!  This fix is actually for a project of mine that was past due when it was assigned to me!

Oh well, at least we are employed!

Thanks,
Ed

 

by: vinnyd79Posted on 2005-12-22 at 13:21:16ID: 15537854

The code should find values of any type but the change depends on the value that is being added. The code checks the value data and if it is numeric it assumes DWORD. If the value is not numeric it assumes REG_SZ.

This line:

creg.SearchFlags = 1

specifies what to search for. 1 means to search Value Names. Here are the options:

     KEY_NAME = 0
     VALUE_NAME = 1
     VALUE_VALUE = 2
     WHOLE_STRING = 4

Also,the VERSION 5.00 line does not mean the version of VB. The above was written in VB6.

It is possible to add switches for the reg type,but implementing REG_MULTI_SZ and REG_BINARY could be difficult.

As far as environment variables a routine would be needed to check for the "%" so the app knows to lookup the env variable. I'll have to test to see why it did not change the default and current users profiles.I'll also see if I can add the environment variable check as well.


 

by: ednetmanPosted on 2005-12-22 at 20:30:56ID: 15539970

Thanks for the help, have a Happy Holidays!

This stuff seems so useful, I even signed up for a .net class in January!

Ed

 

by: ednetmanPosted on 2006-01-10 at 10:36:53ID: 15663448

Hey vinnyd79!

Hope you had a great New Years Eve!  Have you been able to get the current and default profiles to change yet?

Thanks,

Ed

 

by: vinnyd79Posted on 2006-01-16 at 11:02:37ID: 15713293

I was having a problem but I don't remember what it was. I was out of town for a while but I'll look into it again now that I am back. I should get a chance to work on it tomorrow morning.

 

by: ednetmanPosted on 2006-01-16 at 15:26:07ID: 15715563

Thanks!  I'm looking forward to hearing from you, this will make life so much easier!

Ed

 

by: vinnyd79Posted on 2006-01-20 at 08:12:42ID: 15750182

The above example is working for me on the Current Users profile but was not working on the Default User profile. To fix the Default User profile issue find the "LoadProfileList" routine on frmMain and replace it with this one:


Private Sub LoadProfileList()
Set UserProfileList = New Collection
Dim BaseDir As String, strFolder As String
BaseDir = Environ("UserProfile")
BaseDir = Left$(BaseDir, InStrRev(BaseDir, "\") - 1) & "\"
strFolder = Dir(BaseDir, vbDirectory + vbHidden)
Do While strFolder <> ""
    If strFolder <> "." And strFolder <> ".." Then
        If (GetAttr(BaseDir & strFolder) And vbDirectory) Then
            UserProfileList.Add BaseDir & strFolder
        End If
    End If
    strFolder = Dir()
    DoEvents
Loop

End Sub


I'm going to make a few more changes and will get back to you shortly.

 

by: ednetmanPosted on 2006-02-13 at 12:48:44ID: 15944921

Vinny,

Hey!  How's it going?  I finally had a free minute to sit down and work with this.  I ran the original version and the recompiled version.  I saved the log files so I could show you what was happening.

I am logged in to the machine as "egonzalez"

There is an administrator profile and a test account called "HATrain005."  My account and the test account are both domain accounts, the administrator account is a local account.  I ran the GUI so that I could watch the progress.  I chose to search for the key: Wallpaper and change the value to an old Compaq wallpaper that was located in the Winnt directory.

This i a Windows 2000 SP4 machine with all the current patches.

Here is the log file from the original version:

-------------------------------------------------------
Administrator ,HKEY_USERS,keyLoaded\Control Panel\Desktop\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\SafeMode\General\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\LocalUser\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Control Panel\Desktop\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\SafeMode\General\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper,C:\WINNT\CPQ1600h.bmp,C:\WINNT\CPQ1600h.bmp
-------------------------------------------------------
This is from the 2'nd build.

-------------------------------------------------------
Administrator ,HKEY_USERS,keyLoaded\Control Panel\Desktop\Wallpaper,C:\WINNT\BGInfo.bmp,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper,Temporary unsupported,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\SafeMode\General\Wallpaper,Temporary unsupported,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects\LocalUser\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper,C:\WINNT\BGInfo.bmp,C:\WINNT\CPQ1600h.bmp
Administrator ,HKEY_USERS,keyLoaded\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper,C:\WINNT\BGInfo.bmp,C:\WINNT\CPQ1600h.bmp
Default User  ,HKEY_USERS,keyLoaded\Control Panel\Desktop\Wallpaper,C:\WINNT\BGInfo.bmp,C:\WINNT\CPQ1600h.bmp
Default User  ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper,Temporary unsupported,C:\WINNT\CPQ1600h.bmp
Default User  ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\SafeMode\General\Wallpaper,Temporary unsupported,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Control Panel\Desktop\Wallpaper,C:\WINNT\BGInfo.bmp,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper,Temporary unsupported,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Software\Microsoft\Internet Explorer\Desktop\SafeMode\General\Wallpaper,Temporary unsupported,C:\WINNT\CPQ1600h.bmp
hatrain005    ,HKEY_USERS,keyLoaded\Software\Microsoft\Windows\CurrentVersion\Policies\System\Wallpaper,c:\image.bmp,C:\WINNT\CPQ1600h.bmp
-------------------------------------------------------

As you can see, the first time it only changed Adminitrator and Hhatrain005.  The second file shows that it changed the Default profile as well.  It still didn't change the wallpaper for the currently logged in user.

Thanks for the help with this!

Ed

 

by: ednetmanPosted on 2006-03-21 at 12:39:26ID: 16251248

Vinny,

Have you had a chance to look at this recently?

Ed

 

by: vinnyd79Posted on 2006-03-27 at 09:13:41ID: 16302129

Sorry ed, I havn't had much time for EE lately. I will take a look at this again in the next day or so.

Vinny

 

by: ednetmanPosted on 2006-04-19 at 08:25:42ID: 16488817

Vinny,

Any progress on the program?  Once you get the current users profile fixed, then this should be a done deal!

Again, thanks for the help.

Ed

 

by: ednetmanPosted on 2006-04-24 at 08:39:02ID: 16526034

My objection is that this is almost working.  There just a few minor tweaks that need to be made to make the profiles load.  I understand that Vinny is busy, so I would never press too hard for completion.  Please leave this question open until a resolution is reached.

Vinny,
I never noticed this last time, but it seems like the log file isn't working.  When the program completes. it asks if you want to view the log and then says that the file doesn’t exist if you choose yes.

Thanks!

Ed

 

by: vinnyd79Posted on 2006-04-26 at 18:45:29ID: 16549520

Hmmm, Im not really sure what the problem could be. Iv'e looked at this a few times and tried to replicate the problem but couldn't. It is working fine on the current profile for me. The currently loaded profile is the first thing that gets searched. From your log files it looks like it is not searching the current profile. The only thing I can think of is maybe you are missing the line that calls the search.

Look at the frmMain code and find the "SearchRegistry" Sub routine and verify it is searching the current profile. I marked the line to look for below.

Public Sub SearchRegistry(SearchHive As ROOT_KEYS, SearchStr As String)
Set creg = New cRegSearch
creg.RootKey = SearchHive
creg.SubKey = ""
creg.SearchFlags = 1
creg.SearchString = SearchStr
CurrentProfile = "Local & Current Logged on User (" & Environ(UserName) & ")"
If Silent = False Then lblProf = Val(lblProf) + 1
' search Loaded registry files
creg.DoSearch   '  <--------- MAKE SURE THIS LINE IS HERE !!!!!!
Set creg = Nothing

Set creg = New cRegSearch

CurrentProfile = ""

'................................................


If that line does exist,you can click to the left of it in VB and put a breakpoint in. Then run the program. The program will stop and the line will highlight in yellow.
You can then hit the F8 key to step the code though line by line.I would try stepping it through until it jumps to the DoSearch routine and verify it is hitting a line that is calling EnumRegKeys.

 

by: ednetmanPosted on 2006-04-26 at 20:09:48ID: 16549868

I set the breakpoint and tried to run the app, but I get a run-time error '9':
                                                                                 Subscript out of range

when I select DEBUG this is highlighted in yellow "LogFile = arrArgs(i + 1)"

 

by: vinnyd79Posted on 2006-04-26 at 20:37:34ID: 16549977

Thats strange. If it hits that line then it received the /L command line switch without a filename or without a space between the /L switch and the filename.

 

by: ednetmanPosted on 2006-04-27 at 07:01:11ID: 16552909

I may be doing this wrong, but here is what I am doing to get the error.

I go in to the frmMain (code) window and find he line "creg.DoSearch"

I click the grey area to the left of the line and this puts a red dot there.  It also highlights the line in red.

I then try the following methods:
 1.  Select the Debug menu item, then choose Run to Cursor.
 2.  Select the Run menu item, then choose Start.
 3.  Select the Run menu item, then choose Start With Full compile.

All three yield the same results.

Ed

 

by: ednetmanPosted on 2006-04-27 at 12:37:35ID: 16556466

Vinny,

I had one of the guys take a break from their busy schedule and take a look at the run time error.  From what Jose said, this area:

 Case "/l", "/L"
                LogFile = arrArgs(i + 1)

referanced an array that had a max value of 3, but it was equaling 3 + 1.

So he changed: For i = 0 To UBound(arrArgs)
                   to: For i = 0 To UBound(arrArgs) - 1

Now the log file works, but it isn't reporting with all the profiles.  For instance, the GUI will say that 4 profiles were found and 3 changes made, but there will be only 2 enties in the log file.

 

by: ednetmanPosted on 2006-04-27 at 20:46:34ID: 16559235

Thanks Darth,

May the force be with you....

 

by: vinnyd79Posted on 2006-04-28 at 15:52:19ID: 16566267

There is something strange going on here. The array holds the command line arguments that are passed to the exe. If the max value of the array was 3, then that must mean that it is receiving the /L switch as the last argument. The +1 was to get the next element after the /L which should be the filename.

Can you post what you have for the "Form Load" routine in frmMain.

 

by: ednetmanPosted on 2006-05-01 at 09:05:32ID: 16578192

Oh, I think I know what the problem here is.  It is my fault.  I was attempting to make it so that when you right clicked on the file and went to properties, the command line options would be displayed there.  I was looking aroun in the project properties, and thought I saw a field for that.  I was, however , a field that compiles the switches into the executable.  So, my ignorance of VB and the interface messed up the executable.  I am going to change the lines back, I've already clered out the switches, and I will test it again to day.

 

by: ednetmanPosted on 2006-05-02 at 14:16:59ID: 16590813

I recompiled the app and it still didn't change the current user.  I am testing with wallpaper so that I can see it.  The rgistry and the log file do not reflect the current user.

 

by: vinnyd79Posted on 2006-05-04 at 15:40:01ID: 16610610

I'm back. Was out of town for a couple of days. I knew there was something strange going on with the command line switches.

I don't see how it could be skipping the current profile though. Have you tried rebuilding the .vbp and .frm  files from the latest posts in this thread? If not,I would try that but remember to replace the "LoadProfileList" routine on frmMain with this one:


Private Sub LoadProfileList()
Set UserProfileList = New Collection
Dim BaseDir As String, strFolder As String
BaseDir = Environ("UserProfile")
BaseDir = Left$(BaseDir, InStrRev(BaseDir, "\") - 1) & "\"
strFolder = Dir(BaseDir, vbDirectory + vbHidden)
Do While strFolder <> ""
    If strFolder <> "." And strFolder <> ".." Then
        If (GetAttr(BaseDir & strFolder) And vbDirectory) Then
            UserProfileList.Add BaseDir & strFolder
        End If
    End If
    strFolder = Dir()
    DoEvents
Loop

End Sub

 

by: ednetmanPosted on 2006-05-11 at 12:30:23ID: 16661878

I tend to agree.  If it is working for you and not forme, then I probably fat fingured something.  I will rebuild today and opfully be able to post something by tomorrow.  Vacation next week, so if you don't here from me then it will be another week before I can test.

Thanks!

 

by: ednetmanPosted on 2006-06-02 at 14:54:57ID: 16820633

I rebuilt it twice now, still no luck.  Yould you be willing to send me a zip of your project folder?  We can use one of those large file email transfer services it is more that 5 or 10 megs.  Let me know.

 

by: vinnyd79Posted on 2006-06-07 at 10:58:39ID: 16854660

I can send the project folder in a zip file. I don't have it handy on this system but I believe it is only a few KB's. I was going to suggest that if you didn't have any luck re-building it. I'll grab the files from my home system tonight.

 

by: ednetmanPosted on 2006-06-07 at 14:28:26ID: 16856770

Sounds good to me.

 

by: ednetmanPosted on 2006-07-03 at 11:36:07ID: 17032786

Vinny,

When you get a chance, send the files to RegistryTool@bugmenot.com.  This is a dummy email account and will auto delete itself after a few days.  Just let me kow when you send it so I can grab the file before the account deletes itself.

Thanks,

Ed

 

by: ednetmanPosted on 2006-07-12 at 06:20:36ID: 17090213

Vinny,

Lets change that temp email address to 'RegistryTool@mytrashmail.com'  The email account will auto delete after a few days.

Thanks!

Ed

 

by: vinnyd79Posted on 2006-08-02 at 08:16:28ID: 17234112

Sorry Ed, I was away for a while. Is that e-mail address still good?

 

by: ednetmanPosted on 2006-08-03 at 10:42:21ID: 17243760

Vinny,

Yes, this address is still good.  It is a trashmail address, so it becomes active when it recieves an email adress to anything on that domain.

Thanks!

 

by: vinnyd79Posted on 2006-08-08 at 13:35:07ID: 17274538

Ok, sent it. Let me know how it goes.

 

by: ednetmanPosted on 2006-08-08 at 14:24:15ID: 17274875

I'll grab it when I get home tonight and compile it tomorrow!

Thanks!

 

by: ednetmanPosted on 2006-08-31 at 15:21:03ID: 17433019

Vinny,

Sorry it took so long to get back to you.  The file you sent (pre-compiled) work flawlessly on Windows XP.

I still get the same issues on Windows 2000.

It doesn't find all the profiles (Current User) and the log file errors out when it tries to open.  My temp variable is set to C:\Temp

Do you want a VM of a 2000 image?

Thanks!

 

by: vinnyd79Posted on 2006-09-21 at 06:12:18ID: 17568721

Actually I am using Windows 2000. Does the problem occur on more than 1 win2k system? What is the error you receive when it tries to open the log file? Could there be a policy in effect on that machine that is stopping it?

 

by: ednetmanPosted on 2006-10-02 at 11:46:45ID: 17645741

There is no policy stopping this from running, as I am testing on a box that is not joined to the domain.  After troubleshooting a little further, the error that says it cannot open the log file is only coming up if there were no entries found.   I guess it never creates the log, so there is nothing to open.

I can give you a vmware player image as well as a few of the keys I am trying to replace if you would like.

 

by: ednetmanPosted on 2006-10-02 at 12:14:40ID: 17645974

Also, it seems to have an issue with spaces.  Such as NV Domain = MyDomain.  When run from teh command line, you can see that all is loads is NV = MyDomain or "NV = MyDomain.

 

by: ednetmanPosted on 2006-11-28 at 10:10:50ID: 18029984

Vinny, I'm sending you a file.  Check this out when you get a chance.  I have an image file on the desktop that shows what the data I used is, and the error message that comes up.

Ed

 

by: ednetmanPosted on 2007-01-24 at 08:07:48ID: 18386939

Vinny,  did you have a chance to look at the file?

 

by: ednetmanPosted on 2007-01-28 at 10:33:07ID: 18415078

We've been busy.  Don't close the question yet.

Vinny, have you had a chance to look the Virtual Machne?

 

by: ednetmanPosted on 2007-02-07 at 15:43:00ID: 18489906

Vinny,

I will forward some info to you regarding this project.

 

by: ednetmanPosted on 2007-02-15 at 16:09:18ID: 18545130

Info forwarded privately, will wait for response...

 

by: vinnyd79Posted on 2007-02-22 at 04:08:49ID: 18586723

Hi Ed, I downloaded the file's but havn't had a chance to install VB6 so I can debug. I'll get to it tonight.

 

by: ednetmanPosted on 2007-02-28 at 16:32:39ID: 18630253

Thanks Vinny!

 

by: vinnyd79Posted on 2007-03-07 at 16:53:07ID: 18675533

Ok,had problems getting the cd drive working to install vb. I ended up just mapping to the pc from the vm to install vb6. I tested program and it seems to work. It picks up the current and default users. I added a few accounts for testing and cannot see what would cause the profiles to be skipped. Did you try the code on the same VM ?

 

by: ednetmanPosted on 2007-03-19 at 05:38:42ID: 18747572

Yes.  In fact the zip file you sent was on the desktop.  I'll test it again today, It has been a while and I suppose it could be user error.  I'll get back with you later today.

 

by: ednetmanPosted on 2007-04-24 at 15:00:27ID: 18969932

Download the file again...

 

by: ednetmanPosted on 2007-05-23 at 15:11:37ID: 19145434

Still testing, I haven't been able to log in latelty....

 

by: ednetmanPosted on 2007-05-31 at 16:54:30ID: 19192269

It must have been something with the value I was testing or else something wrong with the OS on the machine I imaged that VM from.  I tried it on an XP machine and a Win2K machine.  I tried changing the screensaver and the wallpaper.  They both work now.  I think you have been right, maybe there was something wrong with the way TEMP was defined in the registry.  I don't get the errors with the log file not opening anymore.  Looks great!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...