Wscript Error Message #2 
Author Message
 Wscript Error Message #2

Sorry about that.  Enclosed is the code causing the page fault (obtained
from the net)

'
'~~Comment~~.
'Does an on-the-fly change of the desktop wallpaper
'Requires WSH Engine 5.0 and the latest 2.0 beta.
'Will instantly change the desktop wallpaper if a bitmap file
'is passed to it as an argument. You can pass the bitmap file
'to the script in several ways. You can pass it from a command
'line, Start/Run, the SendTo folder or drag-and-drop. If you
'double-click the script to start it, then you will be prompted
'by a Input box. Legitimate arguments are .BMP files. If you
'have IE 4.0 or greater installed you can also pass .HTM, .HTML,
'.JPEG, .JPG or .GIF files to the procedure as arguments. This
'script makes no attempt to find out whether or not you have
'IE 4.0 or greater installed, although it will trap all other
'extensions passed as arguments with an error message.

Dim WallPaper
Dim Checkfile
Dim WinDir
Dim input
Set WallPaper = CreateObject("WScript.Shell")
Set CheckFile = CreateObject("Scripting.FileSystemObject")

If Wscript.Arguments.Count = 0 then
   input = InputBox ("Enter the path of the bitmap" _
              & " file that you wish to use as wallpaper."  _
              & " If you're not using IE 4.0 or greater then" _
              & " this must be a file with a .BMP extension." _
              & " If you have IE 4.0 or greater installed,"  _
              & " then you can also enter the path of a JPEG"  _
              & " GIF or HTML file.")
Else
   input = Wscript.Arguments(0)
End If

If input = "" then WScript.Quit

If not CheckFile.FileExists (input) then
   MsgBox "The file" & " " & input & " " & _
          "does not exist on your system."
   WScript.Quit
End If

Select Case Lcase(Right(input,Len(input)-InstrRev(input,".")))
   Case "htm","gif","jpe","jpg","bmp","html","jpeg"
   Case Else
      Msgbox "The file" & " " & input & " " & _
             "does not have an allowed extension."
      WScript.Quit
End Select

With WallPaper
     .Regwrite "HKCU\Control Panel\Desktop\WallPaper", input
     .Run "control desk.cpl"
     WScript.Sleep 300
     .AppActivate "Display"
     WScript.Sleep 300
     .SendKeys "{up}"
     WScript.Sleep 300
     .SendKeys "{down}"
     WScript.Sleep 300
     .SendKeys "{tab}"
     WScript.Sleep 300
     .SendKeys "{tab}"
     WScript.Sleep 300
     .SendKeys "{tab}"
     WScript.Sleep 300
     .SendKeys "{tab}"
     WScript.Sleep 300
     .SendKeys "{tab}"
     WScript.Sleep 300
     .SendKeys "{tab}"
     WScript.Sleep 300
     .SendKeys "{ENTER}"
     WScript.Sleep 300
     .SendKeys "{ENTER}"
End With

'''''''''''''''''''''



Wed, 29 Jan 2003 03:00:00 GMT  
 Wscript Error Message #2

It doesn't crash for me (win98, wsh2, vbs5.5)...

For one thing, I'm not sure what the extra {enter} is for at the end of the With WallPaper block.
And all of that tabbing around is unnecessary.  For that matter, only one SendKeys is needed...

With WallPaper
  .Regwrite "HKCU\Control Panel\Desktop\WallPaper", input
  .Run "control desk.cpl" : WScript.Sleep 300
  If .AppActivate("Display") Then
    .SendKeys "{up}{down}{enter}"
  End If
End With

--
Michael Harris
Microsoft MVP - Scripting

"It always helps to read the documentation..."


Quote:
> Sorry about that.  Enclosed is the code causing the page fault (obtained
> from the net)

> '
> '~~Comment~~.
> 'Does an on-the-fly change of the desktop wallpaper
> 'Requires WSH Engine 5.0 and the latest 2.0 beta.
> 'Will instantly change the desktop wallpaper if a bitmap file
> 'is passed to it as an argument. You can pass the bitmap file
> 'to the script in several ways. You can pass it from a command
> 'line, Start/Run, the SendTo folder or drag-and-drop. If you
> 'double-click the script to start it, then you will be prompted
> 'by a Input box. Legitimate arguments are .BMP files. If you
> 'have IE 4.0 or greater installed you can also pass .HTM, .HTML,
> '.JPEG, .JPG or .GIF files to the procedure as arguments. This
> 'script makes no attempt to find out whether or not you have
> 'IE 4.0 or greater installed, although it will trap all other
> 'extensions passed as arguments with an error message.

> Dim WallPaper
> Dim Checkfile
> Dim WinDir
> Dim input
> Set WallPaper = CreateObject("WScript.Shell")
> Set CheckFile = CreateObject("Scripting.FileSystemObject")

> If Wscript.Arguments.Count = 0 then
>    input = InputBox ("Enter the path of the bitmap" _
>               & " file that you wish to use as wallpaper."  _
>               & " If you're not using IE 4.0 or greater then" _
>               & " this must be a file with a .BMP extension." _
>               & " If you have IE 4.0 or greater installed,"  _
>               & " then you can also enter the path of a JPEG"  _
>               & " GIF or HTML file.")
> Else
>    input = Wscript.Arguments(0)
> End If

> If input = "" then WScript.Quit

> If not CheckFile.FileExists (input) then
>    MsgBox "The file" & " " & input & " " & _
>           "does not exist on your system."
>    WScript.Quit
> End If

> Select Case Lcase(Right(input,Len(input)-InstrRev(input,".")))
>    Case "htm","gif","jpe","jpg","bmp","html","jpeg"
>    Case Else
>       Msgbox "The file" & " " & input & " " & _
>              "does not have an allowed extension."
>       WScript.Quit
> End Select

> With WallPaper
>      .Regwrite "HKCU\Control Panel\Desktop\WallPaper", input
>      .Run "control desk.cpl"
>      WScript.Sleep 300
>      .AppActivate "Display"
>      WScript.Sleep 300
>      .SendKeys "{up}"
>      WScript.Sleep 300
>      .SendKeys "{down}"
>      WScript.Sleep 300
>      .SendKeys "{tab}"
>      WScript.Sleep 300
>      .SendKeys "{tab}"
>      WScript.Sleep 300
>      .SendKeys "{tab}"
>      WScript.Sleep 300
>      .SendKeys "{tab}"
>      WScript.Sleep 300
>      .SendKeys "{tab}"
>      WScript.Sleep 300
>      .SendKeys "{tab}"
>      WScript.Sleep 300
>      .SendKeys "{ENTER}"
>      WScript.Sleep 300
>      .SendKeys "{ENTER}"
> End With

> '''''''''''''''''''''



Wed, 29 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Wscript Error Message

2. Sending HTML In Body of Outlook Message using VBSCRIPT (WSCRIPT)

3. WScript.exe - Application Error

4. WScript error

5. Help in JavaScript Error WScript is not an Object

6. Newbie: WScript.Shell Error

7. Wierd WScript error

8. WScript.Sleep error in ASP page

9. WScript.Shell Error

10. wscript.timeout causes Out Of Memory error?!?

11. Error: object required: 'WScript'

12. Error with WScript.Shell in ASP

 

 
Powered by phpBB® Forum Software