mIRC Home    About    Download    Register    News    Help

Topic Options
#222575 - 25/06/10 05:37 AM COMs
Muffinator Offline
Nutrimatic drinks dispenser

Registered: 25/06/10
Posts: 7
I don't think there's much i don't know about when it comes to mIRC, besides COMs. So I figured, "Oh, I'll learn COMs, it'll be fairly simple, bla bla bla." I was wrong.

http://msdn.microsoft.com/en-us/library/k5x59zft(VS.85).aspx
^In this guide to the Save Method (which I happen to be using for my test COM script), it has oShellLink.Save on one line. oShellLink is a variable, which equals: WshShell.CreateShortcut(strDesktop & "\Shortcut Script.lnk").
WshShell equals WScript.CreateObject("WScript.Shell"), and strDesktop equals WshShell.SpecialFolders("Desktop"). So, if I follow, this comes to:

WScript.Shell.CreateShortcut(WScript.Shell.SpecialFolders("Desktop") & "\Shortcut Script.lnk").Save

I understand all that just fine, up to the .Save. I understand that WScript.Shell is the ProgID, CreateShortcut is the module, but what is the .Save, and how do I use it through mIRC?

Top
#222581 - 25/06/10 12:16 PM Re: COMs [Re: Muffinator]
ziv Offline
Babel fish

Registered: 04/09/09
Posts: 52
"After using the CreateShortcut method to create a shortcut object and set the shortcut object's properties, the Save method must be used to save the shortcut object to disk. "

That's strait from the example page you linked us to.

I assume creating the object merely puts it into memory, thus it must be saved into the disk itself to actually stay where you put it.

At least, this is what I understand from it... xD

Good luck with Coms, not too many people know how to mess with those on mIRC wink

ziv.

Top
#222582 - 25/06/10 12:34 PM Re: COMs [Re: Muffinator]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
Here's just an example using what Invision has for displaying some of the system information. It was given to me in almost the same form on the forum here a long time ago and I've made just some minor changes to make it more flexible.

Code:
iSystem {
  ; $1 = Win32_Class
  ; $2 = Property Requested
  ; $3 = Device Number
  .comopen xpver1 WbemScripting.SWbemLocator
  .comclose xpver1 $com(xpver1,ConnectServer,1,dispatch* xpver2)
  if $com(xpver2) {
    .comclose xpver2 $com(xpver2,ExecQuery,1,bstr*,select $2 from Win32_ $+ $1,dispatch* xpver3)
    if $com(xpver3) {
      var %a = $comval(xpver3,$3,$2)
      .comclose xpver3
      return %a
    }
  }
}


An example use would be:

//echo -a $iSystem(OperatingSystem,Caption,1)

A few notes on this. This alias inserts Win32_ in front of $1 so it doesn't have to be entered every time, so this is really looking at Win32_OperatingSystem. Caption ($2) is what we want and $3 is the device number we want to look at. For OS, the device number not important, but if you were looking at RAM or hard drives or something that can have multiple items, this gives you details on whichever one you want to look at. As a note, using 0 will give you the count of the number of items for what you're looking at.

Now, this is a very general alias and even though it's flexible, it can't do everything you might want it to do. For example, if you want to add up all RAM, you'd either need to loop the entire alias for each chip or you'd need a loop within the alias. So it's a starting place, but you'd want to adjust it as needed. If find that the msdn site gives a good view of all the COM objects you'll ever need and all the properties for them with descriptions and what OS requirements are needed to get that information.

One other thing to keep in mind. Manufacturers don't always provide all of the information you want. For examples, a graphics card's name, caption, or description might only say "ATI 4000 series" or something similar rather than the actual card name. A motherboard may only say "motherboard". COM can only get what the manufacturer provides.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#222587 - 25/06/10 02:37 PM Re: COMs [Re: Muffinator]
Muffinator Offline
Nutrimatic drinks dispenser

Registered: 25/06/10
Posts: 7
I get all that, I just can't seem to grasp this .Save. It's a method, but it belongs to no object, or class. I need to execute something similar to .comopen Example WScript.Shell.CreateShortcut, then use $com(Example,Save,1), but that just isn't possible.

Top
#222588 - 25/06/10 05:23 PM Re: COMs [Re: Muffinator]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
Are you reading from or writing to COM? If you're just reading, then 'save' it as a variable.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#222593 - 25/06/10 07:46 PM Re: COMs [Re: Muffinator]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
You'll probably find this shortcut snippet instructive.
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#222594 - 25/06/10 10:17 PM Re: COMs [Re: Muffinator]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
The .Save is just another method, or "module" as you called it. The "CreateShortcut" method returns an OBJECT variable type, so it's an entirely new object which has its own methods and properties.

In mIRC, when something returns an object you must use dispatch* or unknown* to open a new COM object.

The equivalent of that code in mIRC script would look like this:

Code:
alias createshortcut {

  .comopen WshShell WScript.Shell
  
  noop $com(WshShell,SpecialFolders,3,bstr,Desktop)
  
  var %Desktop = $com(WshShell).result
  
  noop $com(WshShell,CreateShortcut,3,bstr,$+(%Desktop,\,Shortcut Script.lnk),dispatch* oShellLink)
  
  noop $com(oShellLink,Save,3)
  
  .comclose oShellLink
  
  .comclose WshShell

}


Using unknown* in place of dispatch* will do the exact same thing in this situation, so use whichever you prefer.

There's a description of the different data types (bstr,int,dispatch,etc) and what the number (in both of these cases - "3") means in the help file.

I've spread it out so it's easier to read smile

Top
#222596 - 25/06/10 11:44 PM Re: COMs [Re: Muffinator]
Muffinator Offline
Nutrimatic drinks dispenser

Registered: 25/06/10
Posts: 7
It works! ^_^ Now, uh...the shortcut...it does nothing!

Top
#222597 - 26/06/10 12:03 AM Re: COMs [Re: Muffinator]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3494
Loc: France
Hixxy's example is just creating a basic shortcut, it is not filling any parameters, but from qwerty's post, you have a link to a snippet that does exactly what you want, for example this is how to set the target path :

Code:
$com(com_name,targetpath,4,bstr*,value)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#222598 - 26/06/10 12:33 AM Re: COMs [Re: Wims]
Muffinator Offline
Nutrimatic drinks dispenser

Registered: 25/06/10
Posts: 7
So, I tried replicating the example (I'm a DIY type of person), and the line .comclose $com(WshShell,CreateShortcut,1,bstr,%Desktop,dispatch* oShellLink) returns an error about the COM '0' not being open. Any ideas? o_o

EDIT: Silly me, I see the error.

EDIT #2: The next line, proceeding .comclose WshShell $com(WshShell,CreateShortcut,1,bstr,%Desktop,dispatch* oShellLink), is noop $com(oShellLink,TargetPath,4,bstr,%Desktop), and it returns an error that COM 'oShellLink' is not open...


Edited by Muffinator (26/06/10 12:43 AM)

Top
#222599 - 26/06/10 01:32 AM Re: COMs [Re: Muffinator]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3494
Loc: France
Code:
alias createshortcut {

  .comopen WshShell WScript.Shell

  noop $com(WshShell,SpecialFolders,3,bstr,Desktop)

  var %Desktop = $com(WshShell).result

  noop $com(WshShell,CreateShortcut,3,bstr,$+(%Desktop,\,Shortcut Script.lnk),dispatch* oShellLink)

  noop $com(oShellLink,targetpath,4,bstr*,%desktop)

  noop $com(oShellLink,Save,3)

  .comclose oShellLink

  .comclose WshShell

}
This works fine, just add others proprieties according to the snippet
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#222600 - 26/06/10 01:47 AM Re: COMs [Re: Wims]
Muffinator Offline
Nutrimatic drinks dispenser

Registered: 25/06/10
Posts: 7
Little change as you said, and it works like a charm. Thanks for all the help, guys! ^_^

Top