B4J Code Snippet Grab Windows 10's pretty lock screen images for your desktop background.

Grab Windows 10's pretty lock screen images for your desktop background.

The Images saved in your local temp Folder

for me: '"C:\Users\knoppi\AppData\Local\Temp\Wallpaper"

B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    'http://www.schieb.de/731289/windows-10-versteckte-anmelde-bilder-als-wallpaper-nutzen
End Sub

Sub AppStart (Args() As String)
    CopyWallpaper
    ExitApplication
End Sub

Sub CopyWallpaper
    If GetSystemProperty( "os.name", "").ToLowerCase.Contains( "win") = False Then Return
   
    Dim LocalAppData As String = GetEnvironmentVariable( "LOCALAPPDATA", "")
    If LocalAppData = "" Then Return
   
    Dim Count As Int = 0
    Dim PathFrom As String = File.Combine( LocalAppData, "Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets")
    Dim PathTo As String = File.Combine( File.DirTemp, "Wallpaper")
    '"C:\Users\knoppi\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
    '"C:\Users\knoppi\AppData\Local\Temp\Wallpaper"
   
    File.MakeDir( PathTo, "")
    Dim li As List = File.ListFiles( PathFrom)
   
    For i=0 To li.Size -1
        ' Find JPG's
        ' get first 4 bytes
        ' if JFIF then JPG
        Dim bytes() As Byte = FileToBytes( PathFrom, li.Get( i))
        Dim b() As Byte = Array As Byte( 0xFF, 0xD8, 0xFF, 0xE0)
        Dim s1, s2 As String
        For j=0 To b.Length -1
            s1 = s1 &" "&  b(j)
            s2 = s2 &" "&  bytes(j)
        Next
        'Log( s1 &"    "& s2)
        If s1 = s2 Then
            File.Copy( PathFrom, li.Get( i), PathTo, li.Get( i) &".jpg")
            Count = Count +1
        End If
    Next
   
    Log( "PathFrom: "& PathFrom)
    Log( "PathTo:   "& PathTo)
    Log( "Files:    "& Count)

End Sub

Sub FileToBytes (Dir As String, FileName As String) As Byte()
   Return Bit.InputStreamToBytes(File.OpenInput(Dir, FileName))
End Sub
 
Top