954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C# to VB.NET - Not changing Wallpaer Style

Good morning,

Here i am again, asking help to all of you that are able to help me, my problem is the following, i translated some code from C# to VB, mas the code in C3, what it does is change the wallpaper and it's style for Windows Starter, but mine in VB, the only thing it does is change the wallpaper but not the style, here are the codes :

void Button4Click(object sender, EventArgs e)
		{
			String wall = "";
			String temp = System.IO.Path.GetTempFileName();
			System.IO.TextWriter tw = new System.IO.StreamWriter(temp);
			
			tw.WriteLine("HKEY_CURRENT_USER\\Control Panel\\Desktop [10]"); //Full registry key access (for modification)
			tw.WriteLine("HKEY_CURRENT_USER\\Control Panel\\Desktop [7]");
			
				wall = openFileDialog1.FileName;
				tw.WriteLine("Wallpaper = REG_SZ " + openFileDialog1.FileName);
			
			if (radioButton1.Checked) //Stretch
			{
				tw.WriteLine("TileWallpaper = REG_SZ 0");
				tw.WriteLine("WallpaperStyle = REG_SZ 2");
			}
			else if (radioButton2.Checked) //Tile
			{
				tw.WriteLine("TileWallpaper = REG_SZ 1");
				tw.WriteLine("WallpaperStyle = REG_SZ 0");
			}
			else if (radioButton3.Checked) //Center
			{
				tw.WriteLine("TileWallpaper = REG_SZ 0");
				tw.WriteLine("WallpaperStyle = REG_SZ 0");
			}
			tw.Close();
			tw.Dispose();
			
			try { //Execute regini process to change background in registry
				System.Diagnostics.Process proc = new System.Diagnostics.Process();
				proc.StartInfo.FileName = "regini";
				proc.StartInfo.Arguments = "\"" + temp + "\"";
				proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
				proc.StartInfo.UseShellExecute = true;
				proc.StartInfo.Verb = "runas";
				proc.Start();
				proc.WaitForExit();
				if (proc.ExitCode != 0) //If regini failed
				{
					MessageBox.Show("Error setting background: " + proc.ExitCode, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
				System.IO.File.Delete(temp);
			}
			catch(System.ComponentModel.Win32Exception ex) //If UAC prompt canceled/failed
    		{
				System.IO.File.Delete(temp);
        		return;
    		}
			System.IO.File.Delete(temp);


Code in VB :

API

<DllImport("user32.dll", SetLastError:=True)> _
    Public Shared Function SystemParametersInfo(ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
    End Function
Dim RespostaMess As MsgBoxResult = MsgBox("Tem a certeza que quer mudar a imagem?", MsgBoxStyle.YesNo)
        Dim wall As String = ""
        Dim temp As String = System.IO.Path.GetTempFileName()
        Dim tw As System.IO.TextWriter = New System.IO.StreamWriter(temp)


        tw.WriteLine("HKEY_CURRENT_USER\Control Panel\Desktop [10]") REM Acesso Total ao registo
        tw.WriteLine("HKEY_CURRENT_USER\Control Panel\Desktop [7]")
        If RespostaMess = MsgBoxResult.Yes Then
            wall = OpenFileDialog1.FileName
            tw.WriteLine("Wallpaper = REG_SZ " + FundoITextBox.Text)
            tw.WriteLine("HKEY_CURRENT_USER\Control Panel\Desktop [8]")
            If FundoIComboBox.Text = "Esticar" Then
                tw.WriteLine("TileWallpaper = REG_SZ 0")
                tw.WriteLine("WallpaperStyle = REG_SZ 2")
            End If
            If FundoIComboBox.Text = "Mosaico" Then
                tw.WriteLine("TileWallpaper = REG_SZ 1")
                tw.WriteLine("WallpaperStyle = REG_SZ 0")
            End If
            If FundoIComboBox.Text = "Centrar" Then
                tw.WriteLine("TileWallpaper = REG_SZ 0")
                tw.WriteLine("WallpaperStyle = REG_SZ 0")
            End If
        End If

        tw.Close()
        tw.Dispose()
        Try
            Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process
            proc.StartInfo.FileName = "regini"
            proc.StartInfo.Arguments = "\" + temp + "\"
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            proc.StartInfo.UseShellExecute = True
            proc.StartInfo.Verb = "runas"
            proc.Start()
            proc.WaitForExit()
            If proc.ExitCode = 0 Then
                MsgBox("Erro ao mudar o fundo de ambiente de trabalho: " + proc.ExitCode, Text, MessageBoxButtons.OK)
            End If
            MsgBox("Alterações feitas com sucesso.")
        Catch ex As Exception
            System.IO.File.Delete(temp)
            Return
        End Try
        System.IO.File.Delete(temp)
        SystemParametersInfo(20, 0, wall, 2) REM Refresh desktop background


Did i translate anything wrong?
Any help will be higly appreciated, this project is due in 2 weeks. :)

Cronicle8
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

The rror code returned should be 0 or non 0? In the first piece of code you ask for non 0 (line 40), while in the second you ask for 0 (line 38).

Also on the first piece of code you miss to call the SysytemParametersInfo.

Hope this helps

lolafuertes
Master Poster
793 posts since Oct 2008
Reputation Points: 120
Solved Threads: 166
 

It returned non 0, and the C# code i downloaded it from the internet, my code is the VB one.

I'm also calling the SystemParameterInfo. Last lines. :)
So nothing yet.

Cronicle8
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: