Jump to content

Registry Change and System32 problems


ct253704
 Share

Go to solution Solved by jguinch,

Recommended Posts

Can anyone tell me what's going on with the script below. I am logged in as domain admin on an admin PC for testing. Maybe all the weird conflicting errors have to do with it being in use or protected? Just trying to update the login screens with the new company logo as asked.

#include <File.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>

Call ("RegChange")
Call ("DefaultSet")

Func RegChange ()

$RegExists = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") ;returns 1
MsgBox ($MB_SYSTEMMODAL, "Output", $RegExists)

$RegDelete = RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") ;returns BOTH value deleted and error deleting Value as specified below.
If $RegDelete = 1 Then MsgBox (0, "Success", "Value Deleted")
If $RegDelete = 0 or 2 Then Msgbox (0, @error, "Error Deleting Value")

$RegCreate = RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", "REG_DWORD", "1") ;returns success even though it isn't changed to 1 after refresh
If $RegCreate = 0 then msgbox (0, "Failure", "Unable to set background registry value at HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background")
If Not($RegCreate=0) Then msgbox (0, "Success", "Background registry value set")

Exit

EndFunc

Func DefaultSet ()

$Exists = FileExists (@windowsdir & "\system32\oobe\INFO\backgrounds") ;returns 1 as the directory does exist.
If $Exists=1 Then $Copy = FileCopy ("\\fileserver01\backgroundDefault.jpg", @windowsdir & "\system32\oobe\INFO\backgrounds", $FC_OVERWRITE + $FC_CREATEPATH)
If $Exists=0 Then MsgBox ($MB_SYSTEMMODAL, "No Path", "Backgrounds path non-existent") 
If $Copy = 1 Then MsgBox ($MB_SYSTEMMODAL, "Success", "Login Image Set")
If Not ($Copy=1) Then Msgbox ($MB_SYSTEMMODAL, "Failure", "Unable to copy login image") ;Get this error even though i'm 100% sure on the path of the image and the destination.
ShellExecute(@windowsdir & "\system32\oobe\INFO\backgrounds") ;This confuses me as, even though FileExists finds the directory, ShellExecute will not open it and instead asks "Which Program would you like to use..."

EndFunc
Edited by ct253704
Link to comment
Share on other sites

Also you should not add constants together like this:

If $Exists=1 Then $Copy = FileCopy ("\\fileserver01\backgroundDefault.jpg", @windowsdir & "\system32\oobe\INFO\backgrounds", $FC_OVERWRITE + $FC_CREATEPATH)

;

Instead you should use BitOr()

If $Exists=1 Then $Copy = FileCopy ("\\fileserver01\backgroundDefault.jpg", @windowsdir & "\system32\oobe\INFO\backgrounds", BitOr($FC_OVERWRITE, $FC_CREATEPATH))

;

This might not fix everything, but making these changes will help with further debugging.

Edited by czardas
Link to comment
Share on other sites

Also, you have a Exit call at the end of RegChange()...

 

This was just something I forgot to remove. Originally I had it opening regedit to the value so I could see if it was changed. Just forgot to remove it.

 

Also you should not add constants together like this:

If $Exists=1 Then $Copy = FileCopy ("\\fileserver01\backgroundDefault.jpg", @windowsdir & "\system32\oobe\INFO\backgrounds", $FC_OVERWRITE + $FC_CREATEPATH)

;

Instead you should use BitOr()

If $Exists=1 Then $Copy = FileCopy ("\\fileserver01\backgroundDefault.jpg", @windowsdir & "\system32\oobe\INFO\backgrounds", BitOr($FC_OVERWRITE, $FC_CREATEPATH))

;

This might not fix everything, but making these changes will help with further debugging.

 

Thanks for the tips czardas, made the changes. In the help file it actually is ($FC_OVERWRITE + $FC_CREATEPATH)

so I didn't think to use BitOr.

After making the  changes. All of the same problems still persist except for $Regdelete returning both errors now since the OR syntax was fixed.

Current code:

#include <File.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>

Call ("RegChange")
Call ("DefaultSet")

Func RegChange ()

$RegExists = RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") ;returns 1
MsgBox ($MB_SYSTEMMODAL, "Output", $RegExists)

$RegDelete = RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") ;now only returns success even though it isn't deleted.
If $RegDelete = 1 Then MsgBox (0, "Success", "Value Deleted")
If $RegDelete = 0 or $RegDelete = 2 Then Msgbox (0, @error, "Error Deleting Key")

$RegCreate = RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", "REG_DWORD", "1") ;returns success even though it isn't changed to 1 after refresh
If $RegCreate = 0 then msgbox (0, "Failure", "Unable to set background registry value at HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background")
If Not($RegCreate=0) Then msgbox (0, "Success", "Background registry value set")

EndFunc

Func DefaultSet ()

$Exists = FileExists (@windowsdir & "\system32\oobe\INFO\backgrounds") ;returns 1 as the directory does exist.
If $Exists=1 Then $Copy = FileCopy ("\\fileserver01\disks\cody\backgroundDefault.jpg", @windowsdir & "\system32\oobe\INFO\backgrounds", BitOr($FC_OVERWRITE, $FC_CREATEPATH))
If $Exists=0 Then MsgBox ($MB_SYSTEMMODAL, "No Path", "Backgrounds path non-existent")
If $Copy = 1 Then MsgBox ($MB_SYSTEMMODAL, "Success", "Login Image Set")
If Not ($Copy=1) Then Msgbox ($MB_SYSTEMMODAL, "Failure", "Unable to copy login image") ;Get this error even though i'm 100% sure on the path of the image and the destination.
ShellExecute(@windowsdir & "\system32\oobe\INFO\backgrounds") ;This confuses me as, even though FileExists finds the directory, ShellExecute will not open it.

EndFunc
Link to comment
Share on other sites

  • Solution

Are you using a X64 Windows ? If it is the case, you should replace HKEY_LOCAL_MACHINE by HKEY_LOCAL_MACHINE64...

Edit :

Also, the System32 folder that you access with a x86 script and a x64 OS is c:windowssyswow64, not c:windowssystem32. You can use @WindowsDir & "sysnative" to point to the native System32 folder.

Here is an example of what your script could be :

RegChange()
DefaultSet()

Func RegChange ()
    If RegWrite ("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", "REG_DWORD", "1") Then
        MsgBox (0, "Success", "Background registry value set")
    Else
        MsgBox (0, "Failure", "Unable to set background registry value at HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background")
    EndIf

EndFunc

Func DefaultSet ()
    $sSystem32 = @SystemDir
    If StringInStr(@OSArch, "64") Then $sSystem32 = @windowsdir & "\sysnative"
    
    If NOT FileExists ($sSystem32 & "\oobe\INFO\backgrounds") Then DirCreate($sSystem32 & "\oobe\INFO\backgrounds")

    If FileExists ($sSystem32 & "\oobe\INFO\backgrounds") Then
        If FileCopy ("\\fileserver01\disks\cody\backgroundDefault.jpg", $sSystem32 & "\oobe\INFO\backgrounds", 1) Then
            MsgBox (0, "Success", "Login Image Set")
            ShellExecute($sSystem32 & "\oobe\INFO\backgrounds") ;This confuses me as, even though FileExists finds the directory, ShellExecute will not open it.
        Else
            Msgbox (16, "Failure", "Unable to copy login image") ;Get this error even though i'm 100% sure on the path of the image and the destination.                
        EndIf
    Else
        MsgBox (16, "No Path", "Unable to create the Backgrounds path")
    EndIf
EndFunc
Edited by jguinch
Link to comment
Share on other sites

Are you using a X64 Windows ? If it is the case, you should replace HKEY_LOCAL_MACHINE by HKEY_LOCAL_MACHINE64...

 

No, this is a 32-bit machine. However, that made me curious so I took the script to a 64 bit machine and added the 64 suffix and the first function actually worked on the 64 bit machine. Second function still non-functional on both machines, however and both still not functional on a 32bit machine.

Link to comment
Share on other sites

your account have enough rights ? You can add #RequireAdmin at the top of the script

When you say oit doesn't work, which MsgBox are displayed  ?

Edited by jguinch
Link to comment
Share on other sites

Thanks for your patience jguinch. I moved to the 64-bit laptop for testing at the moment and with your suggestions it's almost fully functional. The only part that isn't functional is the actual opening of the background folder with ShellExecute. (Edit: This part honestly isn't that big of a deal, I could just Windows Key + L to see if it took effect..) However, the image DOES copy after setting the native directory properly (didn't think about that when swapping machines earlier, thank you).

In terms of rights, I have full rights as a domain admin and signed in with the domainadministrator account.

Current code with comments:

#RequireAdmin
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>

Call ("RegChange")
Call ("DefaultSet")

Func RegChange ()

$RegExists = RegRead ("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") ;returns 1
MsgBox ($MB_SYSTEMMODAL, "Output", $RegExists)

$RegDelete = RegDelete ("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground") ;success
If $RegDelete = 1 Then MsgBox (0, "Success", "Value Deleted")
If $RegDelete = 0 or $RegDelete = 2 Then Msgbox (0, @error, "Error Deleting Key")

$RegCreate = RegWrite ("HKEY_LOCAL_MACHINE64\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", "REG_DWORD", "1") ;success
If $RegCreate = 0 then msgbox (0, "Failure", "Unable to set background registry value at HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background")
If Not($RegCreate=0) Then msgbox (0, "Success", "Background registry value set")

EndFunc

Func DefaultSet ()

$sSystem32 = @SystemDir
If StringInStr(@OSArch, "64") Then $sSystem32 = @windowsdir & "\sysnative"

If NOT FileExists ($sSystem32 & "\oobe\INFO\backgrounds") Then DirCreate($sSystem32 & "\oobe\INFO\backgrounds") ;success

If FileExists ($sSystem32 & "\oobe\INFO\backgrounds") Then
   If FileCopy ("\\fileserver01\backgroundDefault.jpg", $sSystem32 & "\oobe\INFO\backgrounds", 1) Then ;success
      MsgBox (0, "Success", "Login Image Set")
      ShellExecute($sSystem32 & "\oobe\INFO\backgrounds") ;This still fails with the error "Location is unavailable"
   EndIf
Else
   MsgBox (16, "No Path", "Unable to create the Backgrounds path")
EndIf

EndFunc
Edited by ct253704
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...