本文介绍了如何在控制台中更改登录壁纸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个代码,它是改变壁纸。但它不起作用。它在一个控制台中,每当我尝试时,堆栈就会失去平衡。有人能帮助我吗?
谢谢,
iProgramIt
我的代码:
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
''' <summary>
''' Returns the path of the windows installation directory.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetPath() As String
On Error Resume Next
'Create Buffer [
GetPath = Space(255)
']
'Return Windows Directory Path [
Call GetWindowsDirectory(GetPath, Len(GetPath))
End Function
Public Function ApplyStyles(ByVal EnableStyles As Boolean, ByVal ImageToUse As String)
'Check OS Version [
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
']
'Get Windows Directory [
Dim WindowsInstallPath As String
WindowsInstallPath = GetPath().Trim().TrimEnd(Chr(0)) & "\"
']
'Create Missing Folders [
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
']
'Check For Blank Box [
If ImageToUse.Trim = "" Then
'Ask To Select [
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)
']
'Confirmation [
Select Case MyResult
Case Windows.Forms.DialogResult.Yes
End Select
']
'Exit Method [
Exit Function
']
End If
']
'Check File Exists [
If Not My.Computer.FileSystem.FileExists(ImageToUse) Then
'Show Error And Abort [
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
'Create Temporary File [
Dim TemporaryName As String = FileIO.FileSystem.GetTempFileName
']
'Reformat [
Dim ChangeToJPEG As New Bitmap(ImageToUse)
']
'Save Reformatted File [
ChangeToJPEG.Save(TemporaryName, System.Drawing.Imaging.ImageFormat.Jpeg)
']
'Release Bitmap [
ChangeToJPEG.Dispose()
']
'Get Temporary File Size [
Dim MyInformation As New IO.FileInfo(TemporaryName)
If MyInformation.Length > 262144 Then
'Delete Temporary File [
If MyInformation.Exists() Then
MyInformation.Delete()
End If
']
'Error [
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
']
'Delete Temporary File [
If MyInformation.Exists() Then
MyInformation.Delete()
End If
']
Catch MyException As Exception
'Format Error [
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
'Enable Or Disable Background [
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)
']
'Finally Change Screen [
Try
'Reformat [
Dim MyFinalPath As String = WindowsInstallPath & "System32\oobe\info\backgrounds\backgroundDefault.jpg"
Dim ChangeToJPEG As New Bitmap(ImageToUse)
']
'Delete Old File [
If My.Computer.FileSystem.FileExists(MyFinalPath) Then
My.Computer.FileSystem.DeleteFile(MyFinalPath)
End If
']
'Save Reformatted File [
ChangeToJPEG.Save(MyFinalPath, System.Drawing.Imaging.ImageFormat.Jpeg)
']
'Release Bitmap [
ChangeToJPEG.Dispose()
']
'Set Registry File Containing Path [
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
']
'Show Success [
MessageBox.Show("The changes were successfully applied.", "Changes Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
']
Return "good"
End Function
推荐答案
这篇关于如何在控制台中更改登录壁纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!