ocahill
(Just in Town)
2015-12-16 04:39 PM
Desktop Wallpaper VBS to KIX

Hello,
I am new to the forum and would appreciate some help.
We use kix to do most our login scripts and I now need to set the Desktop Wallpaper according to different resoultions. I have been given the VBS Script. Is there a convertor that will do the trick ? I want to merge it into our current Kix Script.

Many Thanks in advance.

The vbs Script is:

'Delete existing wallpaper settings set by local policy
Const HKEY_CURRENT_USER = &H80000001

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Internet Explorer\Desktop\Components\General"

strStringValueName = "Wallpaper"
strStringValueName1 = "BackupWallpaper"


oReg.DeleteValue HKEY_CURRENT_USER,strKeyPath,strStringValueName
oReg.DeleteValue HKEY_CURRENT_USER,strKeyPath,strStringValueName1


Wallpaper1 = "Wallpaper_640x480.bmp"
Wallpaper2 = "Wallpaper_800x600.bmp"
Wallpaper3 = "Wallpaper_1000x982.bmp"
Wallpaper4 = "Wallpaper_1024x768.bmp"
Wallpaper5 = "Wallpaper_1072x982.bmp"
Wallpaper6 = "Wallpaper_1152x864.bmp"
Wallpaper7 = "Wallpaper_1280x768.bmp"
Wallpaper8 = "Wallpaper_1280x960.bmp"
Wallpaper9 = "Wallpaper_1280x1024.bmp"
Wallpaper10 = "Wallpaper_1366x806.bmp"
Wallpaper11 = "Wallpaper_1400x1050.bmp"
Wallpaper12 = "Wallpaper_1440x900.bmp"
Wallpaper13 = "Wallpaper_1536x864.bmp"
Wallpaper14 = "Wallpaper_1600x900.bmp"
Wallpaper15 = "Wallpaper_1600x1200.bmp"
Wallpaper16 = "Wallpaper_1680x1050.bmp"
Wallpaper17 = "Wallpaper_1920x1078.bmp"
Wallpaper18 = "Wallpaper_1920x1080.bmp"
Wallpaper19 = "Wallpaper_1920x1200.bmp"
Wallpaper20 = "Wallpaper_2560x1024.bmp"

Tiled = "1"
Stretched = "2"
Disabled = "0"

'strComputer = "."

'sPath = "c:\program Files\bginfo\bginfo.exe"

'Set wshNetwork = CreateObject("WScript.Network")

Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")

Set filesys = CreateObject("Scripting.FileSystemObject")

'Get Screen Resolution

Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)

For Each objItem In colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Resolution = intHorizontal & "x" & intVertical

'msgbox Resolution

'Set Wallpaper

Next

Select Case Resolution
Case "640x480"
SetWallpaper(Wallpaper1)
Case "800x600"
SetWallpaper(Wallpaper2)
Case "1000x982"
SetWallpaper(Wallpaper3)
Case "1024x768"
SetWallpaper(Wallpaper4)
Case "1072x982"
SetWallpaper(Wallpaper5)
Case "1152x864"
SetWallpaper(Wallpaper6)
Case "1280x768"
SetWallpaper(Wallpaper7)
Case "1280x960"
SetWallpaper(Wallpaper8)
Case "1280x1024"
SetWallpaper(Wallpaper9)
Case "1366x806"
SetWallpaper(Wallpaper10)
Case "1400x1050"
SetWallpaper(Wallpaper11)
Case "1440x900"
SetWallpaper(Wallpaper12)
Case "_1536x864"
SetWallpaper(Wallpaper13)
Case "1600x900"
SetWallpaper(Wallpaper14)
Case "1600x1200"
SetWallpaper(Wallpaper15)
Case "1680x1050"
SetWallpaper(Wallpaper16)
Case "1920x1078"
SetWallpaper(Wallpaper17)
Case "1920x1080"
SetWallpaper(Wallpaper18)
Case "1920x1200"
SetWallpaper(Wallpaper19)
Case "2560x1024"
SetWallpaper(Wallpaper20)
Case Else
SetWallpaper(Wallpaper9)

End Select

' Run BGinfo
'If filesys.FileExists(sPath) Then

' computername = UCase(wshNetwork.ComputerName)

' Set oShell = WScript.CreateObject ("WSCript.shell")

' If (InStr(computername, "HKG") = 1) Or (InStr(computername, "TKO") = 1) Then

' oShell.run Chr(34) & sPath & Chr(34) & " c:\progra~1\bginfo\BGInfoHK.bgi /timer:0", , True

' Else

' oShell.run Chr(34) & sPath & Chr(34) & " c:\progra~1\bginfo\BGInfo.bgi /timer:0", , True

' End If

' Set oShell = Nothing


'End If


Set oShell = WScript.CreateObject ("WSCript.shell")

' set picture display
oShell.RegWrite "HKCU\Control Panel\Desktop\WallpaperStyle", Tiled, "REG_SZ"

' enabling tiling
oShell.RegWrite "HKCU\Control Panel\Desktop\TileWallpaper", Tiled, "REG_SZ"

'Set Sceen Saver
'oShell.RegWrite "HKCU\Control Panel\Desktop\SCRNSAVE.EXE", "C:\Windows\System32\scrnsave.scr", "REG_SZ"
'oShell.RegWrite "HKCU\Control Panel\Desktop\ScreenSaverIsSecure", "1", "REG_SZ"

'Set Background Colour
oShell.RegWrite "HKCU\Control Panel\Colors\Background", "175 160 145", "REG_SZ"

'Turn shuffle off
oShell.RegWrite "HKCU\Control Panel\Personalization\Desktop Slideshow\Shuffle", Disabled, "REG_DWORD"

oShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource", "C:\Windows\BGInfo.bmp", "REG_SZ"

oShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Desktop\General\TileWallpaper", Tiled, "REG_SZ"

'oShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\ActiveDesktop\NoChangingWallPaper", "1", "REG_DWORD"

' let the system know about the change
oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

Set oShell = Nothing

Sub SetWallpaper(ThisWallpaper)

Set oShell = WScript.CreateObject("WScript.Shell")

ThisWallpaper = oShell.ExpandEnvironmentStrings("%WINDIR%") & "\" & ThisWallpaper

' set background image
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", ThisWallpaper
oShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource", ThisWallpaper
'oShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Desktop\Components\General\BackupWallpaper", ThisWallpaper

' set picture display
oShell.RegWrite "HKCU\Control Panel\Desktop\WallpaperStyle", Tiled

' disabling tiling on Windows XP
'oShell.RegWrite "HKCU\Control Panel\Desktop\TileWallpaper", Tiled

' let the system know about the change
oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters",1, True

'WScript.Echo "Wallpaper changed to " & ThisWallpaper
End Sub


NTDOCAdministrator
(KiX Master)
2015-12-16 09:01 PM
Re: Desktop Wallpaper VBS to KIX

Hello and welcome to KiXtart.org

If this is set by a policy then I don't see how a user is able to change it. Users should not be able to change a policy set on a domain.

That said no there is no VBS to KiXtart converter that I'm aware of but most changes are pretty easy. Look up in the manual and some scripts here and you'll find quite a few VBS conversions. (note: use Google to search our site as it has a better search engine)

example:
vbs site:kixtart.org

I get 716 hits for that search myself.

Look up registry reading writing which KiX has it's own native means to do so.
The Select Case is also very similar.

Give that a try and let us know where you get and post back some updated code and we can go from there.

I don't give you pre written code (silver platter) as "learning" will help you much more in the long run than someone just handing out some code for you.

Thanks


Mart
(KiX Supporter)
2015-12-17 10:22 AM
Re: Desktop Wallpaper VBS to KIX

 Originally Posted By: ocahill
Hello,
I am new to the forum and would appreciate some help.
We use kix to do most our login scripts and I now need to set the Desktop Wallpaper according to different resoultions. I have been given the VBS Script. Is there a convertor that will do the trick ? I want to merge it into our current Kix Script.

Many Thanks in advance.

The vbs Script is:
....


Below is a cleaned up and stripped version of what we use. The WMI query to get the screen resolution varies between some Windows versions. The code below works for Windows 7 (x86 and x64) for me.

 Code:
;Get screen resolution.
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_DesktopMonitor")
For Each $wmiObj in $wmiColl
	;Check if the found resolution is for the primary monitor.
	If $wmiObj.DeviceID = "DesktopMonitor1"
		;Combine width and height.
		$screenres = CStr($wmiObj.ScreenWidth) + "x" + CStr($wmiObj.ScreenHeight)
	EndIf
Next

;Copy wallpaper from the server when a local copy does not exist.
If Not Exist("C:\Wallpaper\Wallpaper" + $screenres + ".bmp")
	Copy @LDRIVE + "\wallpaper\Wallpaper" + $screenres + ".bmp" "C:\Wallpaper\*.*"
Else
	;Get the timestamp of the local and remote wallpaper.
	$local = GetFileTime("C:\Wallpaper\Wallpaper" + $screenres + ".bmp")
	$logon = GetFileTime(@LDRIVE + "\wallpaper\Wallpaper" + $screenres + ".bmp")
	;If the timestamps do not match copy the wallpaper from the server. The server is leading.
	If $local <> $logon
		Copy @LDRIVE + "\wallpaper\Wallpaper" + $screenres + ".bmp" "c:\wallpaper\*.*"
	EndIf
EndIf

;Set the wallpaper.
$rc = SetWallpaper("C:\Wallpaper\Wallpaper" + $screenres + ".bmp", 1)
;Set the way the wallpaper is displayed.
;Stretched: WallpaperStyle = 2, TileWallpaper = 0.
;Centered: WallpaperStyle = 0, TileWallpaper = 0.
;Tiled: WallpaperStyle = 0, TileWallpaper = 1.
$rc = WriteValue("HKU\" + @SID + "\Control Panel\Desktop", "TileWallpaper", "0", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Control Panel\Desktop", "WallpaperStyle", "2", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "TileWallpaper", "0", "REG_SZ")
$rc = WriteValue("HKU\" + @SID + "\Software\Microsoft\Internet Explorer\Desktop\General", "WallpaperStyle", "2", "REG_SZ")


ocahill
(Just in Town)
2015-12-17 11:07 AM
Re: Desktop Wallpaper VBS to KIX

Thank you Mart.

Arend_
(MM club member)
2015-12-17 08:18 PM
Re: Desktop Wallpaper VBS to KIX

Mart's script is obviously better but I like translating stuff so here is your original code in Kix. Keep in mind this is a LITERAL translation, nothing is optimized for Kix.
Do yourself a favor and learn from this translated script and Mart's code to see how KiX can be optimized.

 Code:
;Delete existing wallpaper settings set by local policy
$HKEY_CURRENT_USER = &80000001
$strComputer = "."
$oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\default:StdRegProv")
$strKeyPath = "Software\Microsoft\Internet Explorer\Desktop\Components\General"
$strStringValueName = "Wallpaper"
$strStringValueName1 = "BackupWallpaper"
$oReg.DeleteValue($HKEY_CURRENT_USER,$strKeyPath,$strStringValueName)
$oReg.DeleteValue($HKEY_CURRENT_USER,$strKeyPath,$strStringValueName1)

$Wallpaper1 = "Wallpaper_640x480.bmp"
$Wallpaper2 = "Wallpaper_800x600.bmp"
$Wallpaper3 = "Wallpaper_1000x982.bmp"
$Wallpaper4 = "Wallpaper_1024x768.bmp"
$Wallpaper5 = "Wallpaper_1072x982.bmp"
$Wallpaper6 = "Wallpaper_1152x864.bmp"
$Wallpaper7 = "Wallpaper_1280x768.bmp"
$Wallpaper8 = "Wallpaper_1280x960.bmp"
$Wallpaper9 = "Wallpaper_1280x1024.bmp"
$Wallpaper10 = "Wallpaper_1366x806.bmp"
$Wallpaper11 = "Wallpaper_1400x1050.bmp"
$Wallpaper12 = "Wallpaper_1440x900.bmp"
$Wallpaper13 = "Wallpaper_1536x864.bmp"
$Wallpaper14 = "Wallpaper_1600x900.bmp"
$Wallpaper15 = "Wallpaper_1600x1200.bmp"
$Wallpaper16 = "Wallpaper_1680x1050.bmp"
$Wallpaper17 = "Wallpaper_1920x1078.bmp"
$Wallpaper18 = "Wallpaper_1920x1080.bmp"
$Wallpaper19 = "Wallpaper_1920x1200.bmp"
$Wallpaper20 = "Wallpaper_2560x1024.bmp"

$Tiled = "1"
$Stretched = "2"
$Disabled = "0"

;$strComputer = "."
;$sPath = "c:\program Files\bginfo\bginfo.exe"
;$wshNetwork = CreateObject("WScript.Network")
$objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
$filesys = CreateObject("Scripting.FileSystemObject")

;Get Screen Resolution
$colItems = $objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)

For Each $objItem In $colItems 
  $intHorizontal = $objItem.ScreenWidth 
  $intVertical = $objItem.ScreenHeight 
  $Resolution = $intHorizontal + "x" + $intVertical

  ;msgbox Resolution
  ;Set Wallpaper
Next

Select
  Case $Resolution = "640x480" 
    SetWallpaper($Wallpaper1)
  Case $Resolution = "800x600" 
    SetWallpaper($Wallpaper2)
  Case $Resolution = "1000x982" 
    SetWallpaper($Wallpaper3)
  Case $Resolution = "1024x768" 
    SetWallpaper($Wallpaper4)
  Case $Resolution = "1072x982" 
    SetWallpaper($Wallpaper5)
  Case $Resolution = "1152x864" 
    SetWallpaper($Wallpaper6)
  Case $Resolution = "1280x768" 
    SetWallpaper($Wallpaper7)
  Case $Resolution = "1280x960" 
    SetWallpaper($Wallpaper8)
  Case $Resolution = "1280x1024" 
    SetWallpaper($Wallpaper9)
  Case $Resolution = "1366x806" 
    SetWallpaper($Wallpaper10)
  Case $Resolution = "1400x1050" 
    SetWallpaper($Wallpaper11)
  Case $Resolution = "1440x900" 
    SetWallpaper($Wallpaper12)
  Case $Resolution = "_1536x864" 
    SetWallpaper($Wallpaper13)
  Case $Resolution = "1600x900" 
    SetWallpaper($Wallpaper14)
  Case $Resolution = "1600x1200" 
    SetWallpaper($Wallpaper15)
  Case $Resolution = "1680x1050" 
    SetWallpaper($Wallpaper16)
  Case $Resolution = "1920x1078" 
    SetWallpaper($Wallpaper17)
  Case $Resolution = "1920x1080" 
    SetWallpaper($Wallpaper18)
  Case $Resolution = "1920x1200" 
    SetWallpaper($Wallpaper19)
  Case $Resolution = "2560x1024" 
    SetWallpaper($Wallpaper20)
  Case 1
    SetWallpaper(Wallpaper9)
EndSelect	

; Run BGinfo
;If $filesys.FileExists($sPath)
;  $computername = UCase($wshNetwork.ComputerName)
;  $oShell = CreateObject("WSCript.shell")
;  If (InStr($computername, "HKG") = 1) Or (InStr($computername, "TKO") = 1)
;    $oShell.run(Chr(34) + $sPath + Chr(34) + " c:\progra~1\bginfo\BGInfoHK.bgi /timer:0", , 1)
;  Else
;    $oShell.run(Chr(34) + $sPath + Chr(34) + " c:\progra~1\bginfo\BGInfo.bgi /timer:0", , 1)
;  EndIf
;  $oShell = ""
;EndIf

$oShell = CreateObject("WScript.shell")

; set picture display
$oShell.RegWrite("HKCU\Control Panel\Desktop\WallpaperStyle", $Tiled, "REG_SZ")

; enabling tiling
$oShell.RegWrite("HKCU\Control Panel\Desktop\TileWallpaper", $Tiled, "REG_SZ")

;Set Sceen Saver
;$oShell.RegWrite("HKCU\Control Panel\Desktop\SCRNSAVE.EXE", "C:\Windows\System32\scrnsave.scr", "REG_SZ")
;$oShell.RegWrite("HKCU\Control Panel\Desktop\ScreenSaverIsSecure", "1", "REG_SZ")

;Set Background Colour
$oShell.RegWrite("HKCU\Control Panel\Colors\Background", "175 160 145", "REG_SZ")

;Turn shuffle off
$oShell.RegWrite("HKCU\Control Panel\Personalization\Desktop Slideshow\Shuffle", $Disabled, "REG_DWORD")
$oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource", "C:\Windows\BGInfo.bmp", "REG_SZ")
$oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\TileWallpaper", $Tiled, "REG_SZ")
;$oShell.RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\ActiveDesktop\NoChangingWallPaper", "1", "REG_DWORD")

; let the system know about the change
$oShell.Run("%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, 1)
$oShell = ""

Function SetWallpaper($ThisWallpaper)
  $oShell = CreateObject("WScript.Shell")
  $ThisWallpaper = $oShell.ExpandEnvironmentStrings("%WINDIR%") + "\" + $ThisWallpaper

  ;set background image
  $oShell.RegWrite("HKCU\Control Panel\Desktop\Wallpaper", $ThisWallpaper)
  $oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\General\WallpaperSource", $ThisWallpaper)
  ;$oShell.RegWrite("HKCU\Software\Microsoft\Internet Explorer\Desktop\Components\General\BackupWallpaper", $ThisWallpaper)

  ;set picture display
  $oShell.RegWrite("HKCU\Control Panel\Desktop\WallpaperStyle", $Tiled)

  ;disabling tiling on Windows XP
  ;$oShell.RegWrite("HKCU\Control Panel\Desktop\TileWallpaper", $Tiled)

  ;let the system know about the change
  $oShell.Run("%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters",1, 1)

  ;? "Wallpaper changed to " + $ThisWallpaper 
EndFunction


ocahill
(Just in Town)
2015-12-18 10:56 AM
Re: Desktop Wallpaper VBS to KIX

Thank you Arend. I am currently looking at the Kix documents.