Hi all,
I have a code and it is to change the wallpaper. But it does not work. It is in a console and whenever I try, the stack unbalances. Could someone help me?
Thanks,
iProgramIt
My code:
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Function GetPath() As String
On Error Resume Next
GetPath = Space(255)
Call GetWindowsDirectory(GetPath, Len(GetPath))
End Function
Public Function ApplyStyles(ByVal EnableStyles As Boolean, ByVal ImageToUse As String)
If Not My.Computer.Info.OSFullName.StartsWith("Microsoft Windows 7") Then
MessageBox.Show("You must be running Microsoft Windows 7 in order to use this program", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Exit Function
End If
Dim WindowsInstallPath As String
WindowsInstallPath = GetPath().Trim().TrimEnd(Chr(0)) & "\"
If Not My.Computer.FileSystem.DirectoryExists(WindowsInstallPath & "System32\oobe\info") Then
My.Computer.FileSystem.CreateDirectory(WindowsInstallPath & "System32\oobe\info")
End If
If Not My.Computer.FileSystem.DirectoryExists(WindowsInstallPath & "System32\oobe\info\backgrounds") Then
My.Computer.FileSystem.CreateDirectory(WindowsInstallPath & "System32\oobe\info\backgrounds")
End If
If ImageToUse.Trim = "" Then
Dim MyResult As DialogResult = MessageBox.Show("There is no picture file selected, would you like to select one now?", "No File Selected", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
Select Case MyResult
Case Windows.Forms.DialogResult.Yes
End Select
Exit Function
End If
If Not My.Computer.FileSystem.FileExists(ImageToUse) Then
MessageBox.Show("The image file specified does not exist, please ensure that it is present on your computer.", "Error - File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
Try
Dim TemporaryName As String = FileIO.FileSystem.GetTempFileName
Dim ChangeToJPEG As New Bitmap(ImageToUse)
ChangeToJPEG.Save(TemporaryName, System.Drawing.Imaging.ImageFormat.Jpeg)
ChangeToJPEG.Dispose()
Dim MyInformation As New IO.FileInfo(TemporaryName)
If MyInformation.Length > 262144 Then
If MyInformation.Exists() Then
MyInformation.Delete()
End If
MessageBox.Show("The image file specified would be over 256KB when converted to a JPG file and too large to use. Please select another file.", "Error - File Too Large", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
If MyInformation.Exists() Then
MyInformation.Delete()
End If
Catch MyException As Exception
MessageBox.Show("The image file specified is not of the correct format. Logon Background Changer cannot convert it to JPG format for use as a logon screen. Please select another file.", "Error - Incorrect Format", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End Try
Dim MyEnableSelection As Integer
If EnableStyles Then
MyEnableSelection = 1
Else
MyEnableSelection = 0
End If
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background", "OEMBackground", MyEnableSelection)
Try
Dim MyFinalPath As String = WindowsInstallPath & "System32\oobe\info\backgrounds\backgroundDefault.jpg"
Dim ChangeToJPEG As New Bitmap(ImageToUse)
If My.Computer.FileSystem.FileExists(MyFinalPath) Then
My.Computer.FileSystem.DeleteFile(MyFinalPath)
End If
ChangeToJPEG.Save(MyFinalPath, System.Drawing.Imaging.ImageFormat.Jpeg)
ChangeToJPEG.Dispose()
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\LogonBackgroundChanger", "PersistFile", ImageToUse)
Catch MyException As Exception
MessageBox.Show("The image file specified is not of the correct format. Logon Background Changer cannot convert it to JPG format for use as a logon screen. Please select another file.", "Error - Incorrect Format", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End Try
MessageBox.Show("The changes were successfully applied.", "Changes Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return "good"
End Function