Date of the publication of article: 09.08.2005 13:42

New Page 1

Valery Shmelyov
We write the program on VB for automatic change of wall-paper of Windows

  • Preface

  • Description

  • Module [1]

  • Module installer [2]

  • How to remove service

  • [To download]

  • [To download]

  • To discuss [forum] in a forum

  • Preface

    For programmers on Visual Basic the guide to development of the program for automatic change of registration of Windows Desktop is offered. Process of development of an installer, the work module with wallpapers is step by step described and program scopes – in particular, for advertizing are considered. The management is focused on programmers with the initial level of preparation.


    Actually the task consists in writing not of one, but two programs – the module located on the computer of the user [1] and in certain dates of the registration of a desktop of Windows and the module installer [2] placing the main module on the computer and making installation of necessary parameters making change.
       Each of modules can be written in different programming languages – Visual Basic, Delphi, Java Script, Windows Script, C ++. In this manual process of development of modules on Visual Basic 6.0 is described – for Windows 2000 and Windows XP OS there is no need with programs to extend huge dynamic library to VB – all calls are processed by the most operating system (OS). The module [1] located on the computer of the user and which is carrying out registration replacement is carried out once at start of OC Windows and finishes the work.

    Module [1]

    The module [1] located on the computer of the user and which is carrying out replacement of registration very simple. In it check of the current date and if it coincides with set is made, registration of a desktop of Windows is replaced.

    Private Sub Form_Load()
    rundate = Date 'Получить ДАТУ на компьютере
    If Mid(rundate, 1, 2) = "30" Then 'Т.е. записывать выполнять каждое 30-е число каждого месяца
    ChangeWallPaper "c:\oflameron-1024.bmp", "Center" 'Разместить картинку по центру экрана
    End If
    End 'Выйти из программы
    End Sub

    The ChangeWallPaper function is caused from the Module1.bas module (see the file). Pay attention that the graphic file for Desktop has to be in the .bmp format.
       Here the simplest option of the placed module is offered. For a commercial product it is necessary to provide the text file of parameters containing the list of files of wall-paper, dates of loading, parameters of placement of image on the screen (on the center, in all screen, etc.) Besides, it is possible to provide check of the current video mode (the screen size) and to connect the graphic images corresponding to the established permission.

    Module installer [2]

    The installer places the module [1] on the computer of the user and carries out record in the register of Windows for its loading at start of an operating system. Placement of the module [1] is carried out at once when loading the Form1 form.

    Private Sub Form_Activate()
    AutoSet ' Сделать запись в реестре Windows XP (смотрите далее)
    'Создать BAT-файл для копирования и переименования загружаемого модуля
    indx = 1
    Str1(0) = "copy demo.ttl c:\demo.ttl" 'Скопировать модуль[1] на диск C:\
    Str1(1) = "c:"
    Str1(2) = "cd c:\"
    Str1(3) = "ren demo.ttl demo.exe" 'Переименовать модуль[1] в EXE
    For i = 0 To 3 ‘В файле setup.bat будет 4 строки команд
    Str1(i) = Str1(i) + Chr$(13) + Chr$(10)
    Open "setup.bat" For Binary As #1 Len = Len(Str1(i)) ‘Создать файл setup.bat
    Put #1, indx, Str1(i) 'Записать BAT-файл надиск
    indx = indx + Len(Str1(i)) 'Номер следующей записи
    Close #1 ‘Закрыть setup.bat файл
    Next i
    Shell ("setup.bat") 'Запустить BAT-файл на исполнение
    End Sub

    Initially installed module (program [1]) - demo.ttl. The installer (program [2]) writes down on a disk the command setup.bat file writes down in it standard teams (known with MS DOS):

    copy demo.ttl c:\demo.ttl - to copy the module (program [1]) on a disk C:
    c: - to replace the current disk with C:
    cd c:\ - to replace the current catalog (if it is supposed to place the module in the subdirectory)
    ren demo.ttl demo.exe - to rename the module (program [1]) into the executed file

    Now it is enough to execute the command setup.bat file:

    Shell ("setup.bat")

    This procedure correctly will work only in the compiled option. In the mode of the VB interpreter the incorrect way on a disk (a way to the interpreter) will be used by default. The problem of placement of the module [1] on the computer can be solved also in other ways, without use of BAT files. But the code shown here is universal and can be easily copied on other programming languages – Delphi, C ++.

    Now it is necessary to make entry in the register of Windows for automatic loading of the module [1].

    Private Sub AutoSet()
    'Создать запись в реестре Windows XP или 2000 для запуска модуля при старте Windows
    LSkey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" ' Auto RUN
    secattr.nLength = Len(secattr) ' size of the structure
    secattr.lpSecurityDescriptor = 0 ' default security level
    secattr.bInheritHandle = True ' the default value for this setting
    retval = RegCreateKeyEx(HKEY_LOCAL_MACHINE, LSkey, 0, "", 0, KEY_WRITE, secattr, hregkey, neworused)
    If retval <> 0 Then ' error during open
    Debug.Print "Error opening or creating registry key -- aborting."
    End ' terminate the program
    End If
    stringbuffer = "C:\demo.exe" & vbNullChar ' Путь, где располагается модуль (после исполнения setup.bat)
    retval = RegSetValueEx(hregkey, "Demo", 0, REG_SZ, ByVal stringbuffer, Len(stringbuffer)) ' write the string
    ' Close the registry key
    retval = RegCloseKey(hregkey)
    End Sub

    Work with the register of Windows is performed in the standard way. A way for automatic loading of the module [1].

    stringbuffer = "C:\demo.exe" & vbNullChar

    On it the description of the minimum configuration of an installer of the module [2] it is complete.

    The full project with listing of the module installer – in the file.

    How to remove service

    For removal of record of automatic loading of the module of [1] demo.exe it is necessary to use the same listing on Visual Basic, but with "empty" record of a name of the started program. Or to use the following JAVA script (the text file with the .js expansion, for example clear.js):

    var WSHShell = WScript.CreateObject("WScript.Shell");
    WSHShell.Popup("Снимаем Автозагрузку");
    WSHShell.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\Demo", "");

    It is rather simple to create such file and to execute it.

     Valery Shmelyov