Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript Error: Illegal Assignment: 'shell' Using Appactivate 1

Status
Not open for further replies.

stevemarks59

Technical User
Apr 8, 2010
22
US
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?

Code:
set shell = createobject("wscript.shell"

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

StartYahoo.vbs:
Code:
'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:
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
	WshShell.popup "MINIMIZE Yahoo Messenger", 5
 
'MINIMIZE Yahoo Messenger
[b]set shell = createobject("wscript.shell")[/b]
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:
Code:
'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
[b]set shell = createobject("wscript.shell")[/b]
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

The line above producing the error is in BOLD type.
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

 
Hi Try this code :
Code:
'START Yahoo Messenger
dim WshShell
Set WshShell = CreateObject("WScript.Shell")   
WshShell.Run """C:\Program Files\Yahoo!\Messenger\YahooMessenger.exe"""
wscript.sleep 25000
WshShell.popup "MINIMIZE Yahoo Messenger", 5
'MINIMIZE Yahoo Messenger
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
 
Code:
'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

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the quick replies and your help! I tried PHV's code and it worked perfectly. Thank you very much. Since that code worked I didn't try others. This forum and you members are great!
 
Do you understand why PHV commented out [tt]
set shell = createobject("wscript.shell")[/tt]?

It's because you have already defined a sub routine named "shell". You can't set a sub routine to an object (essentially, you can't reuse the name.)


-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top