Vbscript Error: Illegal Assignment: 'shell' Using Appactivate

Author Message
stevemarks59

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 4/8/2010
  • Status: offline
Vbscript Error: Illegal Assignment: 'shell' Using Appactivate Saturday, December 24, 2011 1:12 AM (permalink)
0
My OS is Windows XP Pro SP3

How can I combine these two VBScripts, StartYahoo.vbs and MinYahoo.vbs into one VBScript,
StartYahooMin.vbs without getting an "Illegal Assignment 'shell" Error from the line below?

set shell = createobject("wscript.shell"


These two scripts when run as separate vbs files work fine.,

StartYahoo.vbs:
'START Yahoo Messenger
 sub shell(cmd)
 dim objShell
 Set objShell = WScript.CreateObject( "WScript.Shell" )
 objShell.Run(cmd)
 Set objShell = Nothing
 end sub
 
shell """C:\Program Files\Yahoo!\Messenger\YahooMessenger.exe"""


MinYahoo.vbs:
Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.popup "MINIMIZE Yahoo Messenger", 5
 
'MINIMIZE Yahoo Messenger
set shell = createobject("wscript.shell")
shell.AppActivate "Yahoo! Messenger"
 
wscript.sleep 1000
success = shell.appactivate("Yahoo! Messenger")
if success then shell.sendkeys "% r"  '...restore
 
wscript.sleep 1000
success = shell.appactivate("Yahoo! Messenger")
if success then shell.sendkeys "% n"  '...minimize
 
wscript.sleep 1000
success = shell.appactivate("Yahoo! Messenger")
if success then shell.sendkeys "% n"  '...minimize



But produces an error when combined into one vbs file,

StartYahooMin.vbs:
'START Yahoo Messenger
 sub shell(cmd)
 dim objShell
 Set objShell = WScript.CreateObject( "WScript.Shell" )
 objShell.Run(cmd)
 Set objShell = Nothing
 end sub
 
shell """C:\Program Files\Yahoo!\Messenger\YahooMessenger.exe"""
 
wscript.sleep 25000
 
Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.popup "MINIMIZE Yahoo Messenger", 5
 
'MINIMIZE Yahoo Messenger
set shell = createobject("wscript.shell")
shell.AppActivate "Yahoo! Messenger"
 
wscript.sleep 1000
success = shell.appactivate("Yahoo! Messenger")
if success then shell.sendkeys "% r"  '...restore
 
wscript.sleep 1000
success = shell.appactivate("Yahoo! Messenger")
if success then shell.sendkeys "% n"  '...minimize
 
wscript.sleep 1000
success = shell.appactivate("Yahoo! Messenger")
if success then shell.sendkeys "% n"  '...minimize




Windows Script Host Error:
-----------------------------
Script: C:\Program Files\Yahoo!\Messenger\StartYahooMin.vbs
Line: 17
Char: 1
Error: Illegal assignment: 'shell'
Code: 800A01F5
Source: Microsoft VBScript runtime error

Thank you and I will appreciate your help.

NOTE:
I realize I can just call "StartYahoo.vbs" from code added to the beginning of
MinYahoo and that is what I currently do using this:

Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run """C:\Program Files\Yahoo!\Messenger\Y\StartYahooVBS.vbs""",  True

 
#1
    stevemarks59

    • Total Posts : 5
    • Scores: 0
    • Reward points : 0
    • Joined: 4/8/2010
    • Status: offline
    Re:Vbscript Error: Illegal Assignment: 'shell' Using Appactivate Saturday, December 24, 2011 3:00 AM (permalink)
    0
    I was given this working code by "PHV" who posted the complete
    code with his modifications here:
    http://www.tek-tips.com/viewthread.cfm?qid=1670345



    'START Yahoo Messenger
    sub shell(cmd)
    dim objShell
    Set objShell = WScript.CreateObject( "WScript.Shell" )
    objShell.Run(cmd)
    Set objShell = Nothing
    end sub

    shell """C:\Program Files\Yahoo!\Messenger\YahooMessenger.exe"""

    wscript.sleep 25000

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.popup "MINIMIZE Yahoo Messenger", 5

    'MINIMIZE Yahoo Messenger
    '''''set shell = createobject("wscript.shell")
    WshShell.AppActivate "Yahoo! Messenger"

    wscript.sleep 1000
    success = WshShell.appactivate("Yahoo! Messenger")
    if success then WshShell.sendkeys "% r"  '...restore

    wscript.sleep 1000
    success = WshShell.appactivate("Yahoo! Messenger")
    if success then WshShell.sendkeys "% n"  '...minimize

    wscript.sleep 1000
    success = WshShell.appactivate("Yahoo! Messenger")
    if success then WshShell.sendkeys "% n"  '...minimize
     
    #2
      59cobalt

      • Total Posts : 981
      • Scores: 91
      • Reward points : 0
      • Joined: 7/17/2011
      • Status: offline
      Re:Vbscript Error: Illegal Assignment: 'shell' Using Appactivate Tuesday, January 03, 2012 2:37 AM (permalink)
      0
      You get the error because you define a function and a variable with the same name ("shell"):
      sub shell(cmd)
       '...
      end sub
      '...
      set shell = createobject("wscript.shell")

       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9