mIRC Homepage
Posted By: Muffinator COMs - 25/06/10 04:37 AM
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?
Posted By: ziv Re: COMs - 25/06/10 11:16 AM
"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.
Posted By: Riamus2 Re: COMs - 25/06/10 11:34 AM
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.
Posted By: Muffinator Re: COMs - 25/06/10 01:37 PM
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.
Posted By: Riamus2 Re: COMs - 25/06/10 04:23 PM
Are you reading from or writing to COM? If you're just reading, then 'save' it as a variable.
Posted By: qwerty Re: COMs - 25/06/10 06:46 PM
You'll probably find this shortcut snippet instructive.
Posted By: hixxy Re: COMs - 25/06/10 09:17 PM
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
Posted By: Muffinator Re: COMs - 25/06/10 10:44 PM
It works! ^_^ Now, uh...the shortcut...it does nothing!
Posted By: Wims Re: COMs - 25/06/10 11:03 PM
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)
Posted By: Muffinator Re: COMs - 25/06/10 11:33 PM
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...
Posted By: Wims Re: COMs - 26/06/10 12:32 AM
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
Posted By: Muffinator Re: COMs - 26/06/10 12:47 AM
Little change as you said, and it works like a charm. Thanks for all the help, guys! ^_^
© mIRC Discussion Forums