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. :)