mIRC Home    About    Download    Register    News    Help

Print Thread
COMs #222575 25/06/10 04:37 AM
Joined: Jun 2010
Posts: 7
M
Muffinator Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2010
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?

Re: COMs [Re: Muffinator] #222581 25/06/10 11:16 AM
Joined: Sep 2009
Posts: 52
Z
ziv Offline
Babel fish
Offline
Babel fish
Z
Joined: Sep 2009
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.

Re: COMs [Re: Muffinator] #222582 25/06/10 11:34 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: COMs [Re: Muffinator] #222587 25/06/10 01:37 PM
Joined: Jun 2010
Posts: 7
M
Muffinator Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2010
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.

Re: COMs [Re: Muffinator] #222588 25/06/10 04:23 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: COMs [Re: Muffinator] #222593 25/06/10 06:46 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You'll probably find this shortcut snippet instructive.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: COMs [Re: Muffinator] #222594 25/06/10 09:17 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
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

Re: COMs [Re: Muffinator] #222596 25/06/10 10:44 PM
Joined: Jun 2010
Posts: 7
M
Muffinator Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2010
Posts: 7
It works! ^_^ Now, uh...the shortcut...it does nothing!

Re: COMs [Re: Muffinator] #222597 25/06/10 11:03 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
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
Re: COMs [Re: Wims] #222598 25/06/10 11:33 PM
Joined: Jun 2010
Posts: 7
M
Muffinator Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2010
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...

Last edited by Muffinator; 25/06/10 11:43 PM.
Re: COMs [Re: Muffinator] #222599 26/06/10 12:32 AM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
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
Re: COMs [Re: Wims] #222600 26/06/10 12:47 AM
Joined: Jun 2010
Posts: 7
M
Muffinator Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2010
Posts: 7
Little change as you said, and it works like a charm. Thanks for all the help, guys! ^_^