mistral
Fri Jul 14 04:35:08 CDT 2006
D R =D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0):
> Mistral, I use this to download a file. I'm not sure, but you might be a=
ble
> to tweak it to download an image...
>
> Sub s_get_zip_file( ps_from, ps_to )
> Const cs_fac =3D "%s_get_zip_file, "
> Const adSaveCreateOverWrite =3D 2
> Const adTypeBinary =3D 1
>
> Dim lo_XMLHTTP, lo_stream
> Dim ls_status, lo_zip_file
>
> Call s_log( cs_fac & "Attempting to fetch `" & ps_from & "`..." )
>
> gb_download_successful =3D False
>
> Set lo_XMLHTTP =3D CreateObject( "Microsoft.XMLHTTP" )
> lo_XMLHTTP.Open "GET", ps_from, False
> lo_XMLHTTP.Send
>
> ls_status =3D lo_XMLHTTP.StatusText
> Select Case ls_status
> Case "Not Found"
> Call s_log( cs_fac & "File status `" & ls_status & "` from `" & ps_fr=
om
> & "`." )
> Exit Sub
>
> Case "OK"
> Set lo_stream =3D CreateObject( "ADODB.Stream" )
> lo_stream.Type =3D adTypeBinary
> lo_stream.Open
> lo_stream.Write lo_XMLHTTP.ResponseBody
> lo_stream.SaveToFile ps_to, adSaveCreateOverWrite
> lo_stream.Close
>
> Case Else
> Call s_abort( cs_fac & "Failed to retrieve file `" & ps_from & "`,
> status `" & ls_status & "`." )
> End Select
>
> Set lo_zip_file =3D go_fso.GetFile( ps_to )
> If Err.Number <> 0 Then
> Call s_error( cs_fac & "Failed to retrieve file size of `" & ps_from &
> "`." )
> End If
> Call s_log( cs_fac & "File size `" & lo_zip_file.Size & "`." )
>
> gb_download_successful =3D True
> End Sub
>
>
>
> And I call it like this;
>
> Call s_get_zip_file( "
http://www.site.com/folder/image.jpg",
> "C:\Temp\image.jpg" )
>
> and then check global variable "gb_downnload_successful" afterwards.
>
>
>
> As for converting the image, I'll get on to that later. First I build a
> temp file name, and get the screen size.
>
> The image size/type conversion below needs "gl_screen_height" and
> "gl_screen_width", and I use this to get the values;
>
> Dim go_wmi
> Set go_wmi =3D GetObject( "WinMgmts://./root/cimv2" )
> Dim lo_displays, lo_display
> Set lo_displays =3D go_wmi.ExecQuery( "Select * from
> Win32_DisplayConfiguration", , 48 )
> For Each lo_display In lo_displays
> gl_screen_width =3D lo_display.PelsWidth
> gl_screen_height =3D lo_display.PelsHeight
> Next
>
>
>
> And I use this to build a temporary file name;
>
> Const ci_temporary_folder =3D 2
> Dim go_fso
> Set go_fso =3D CreateObject( "Scripting.FileSystemObject" )
> Dim gs_script_spec, gs_script_path, gs_script_name
> gs_script_spec =3D Wscript.ScriptFullName
> gs_script_path =3D go_fso.GetParentFolderName( gs_script_spec )
> gs_script_name =3D go_fso.GetBaseName( gs_script_spec )
> Dim gs_temp_path, gs_temp_file, gs_temp_spec
> gs_temp_path =3D go_fso.GetSpecialFolder( ci_temporary_folder )
> gs_temp_spec =3D gs_temp_path & "\" & gs_script_name & ".bmp"
>
>
>
> If you are downloading an JPG image, then you'll need to convert the image
> to a BMP before it can be used as wallpaper. I use WIA 2.0 (Windows Image
> Automation 2.0) for Windows XP SP2. You can download it (about 600kb) fr=
om
> MS site, and just copy a DLL and regsrv it - see the instructions in the =
zip
> file that you d/l from MS.
>
> This page has a bit of an overview;
>
http://www.ilixis.com/developer/wia.html
>
> You can d/l it here;
>
http://www.microsoft.com/downloads/details.aspx?FamilyID=3Da332a77a-01b8-=
4de6-91c2-b7ea32537e29&DisplayLang=3Den
>
> And I use this to convert the image - you'll have to tweak/modify the cod=
e -
> it works in my larger script - but won't work if you just cut and paste i=
t,
> you'll have to work on it to get it to work for you, so it's here purely =
as
> a starter for you....
>
> Dim lo_image_file, lo_image_process
>
> Set lo_image_file =3D CreateObject( "WIA.ImageFile" )
> Set lo_image_process =3D CreateObject( "WIA.ImageProcess" )
>
> Const wiaFormatBMP =3D "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
> Const wiaFormatPNG =3D "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
> Const wiaFormatGIF =3D "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
> Const wiaFormatJPEG =3D "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
> Const wiaFormatTIFF =3D "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"
>
> lo_image_file.LoadFile po_file.Path
>
> lo_image_process.Filters.Add lo_image_process.FilterInfos(
> "Scale" ).FilterID
> lo_image_process.Filters(1).Properties( "MaximumHeight" ) =3D
> gl_screen_height
> lo_image_process.Filters(1).Properties( "MaximumWidth" ) =3D
> gl_screen_width
> lo_image_process.Filters(1).Properties( "PreserveAspectRatio" ) =3D True
>
> lo_image_process.Filters.Add lo_image_process.FilterInfos(
> "Convert" ).FilterID
> lo_image_process.Filters(2).Properties( "FormatID" ).Value =3D wiaForma=
tBMP
>
> Set lo_image_file =3D lo_image_process.Apply( lo_image_file )
>
> If go_fso.FileExists( gs_temp_spec ) Then go_fso.DeleteFile gs_temp_spec
> lo_image_file.SaveFile gs_temp_spec
>
> Call s_set_wallpaper_image( gs_temp_spec )
>
>
>
>
> And I use this to set the wallpaper;
>
> Sub s_set_wallpaper_image( ps_image )
> Const cs_fac =3D "%s_set_wallpaper_image, "
> go_wsh.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", ps_image
> go_wsh.Run "%windir%\System32\RUNDLL32.EXE user32.dll,
> UpdatePerUserSystemParameters", 1, False
> End Sub
>
>
>
> Hope this helps a bit.
> Regards,
> Dave.
"mistral" <polychrom@softhome.net> wrote in message
news:1152794400.603083.268430@75g2000cwc.googlegroups.com...
I want set Windows desktop Wallpaper picture via vbscript.
Here is two scripts, but both take image from local drive; instead, I
want upload image from URL. How to implement this?
'--------------------8<----------------------
Set oShell =3D CreateObject("WScript.Shell")
Set oFSO =3D CreateObject("Scripting.FileSystemObject")
sWinDir =3D oFSO.GetSpecialFolder(0)
sWallPaper =3D sWinDir & "\Coffee Bean.bmp"
' update in registry
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
' let the system know about the change
oShell.Run _
"%windir%\System32\RUNDLL32.EXE
user32.dll,UpdatePerUserSystemParameters", _
1, True
'--------------------8<----------------------
'---------------------8<------------------------
Dim WshShell
Set WshShell =3D WScript.CreateObject("Wscript.Shell")
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", mybitmap.bmp
WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,
UpdatePerUserSystemParameters", 1, False
Set WshShell =3D Nothing
'--------------------8<----------------------
thanks. Looks complicated enough for me. My task is a bit simpler in my
case - I will download BMP image, so no conversion will
required(dimensions also will be prepared 800 x 600).
thanks
mistral