mIRC Homepage
say i run my script first time, it should execute some settings etc and save it

then i send my script to my friend (with my saved settings), and it should also execute the settings for him to as its a different pc

so any ideas how i could make a way for my script to execute some stuff first time for diff pc's?
Code:

on *:START: {
  if (!%firstrun) {
    set %firstrun $true
    ; first run stuff here.
  }
}



~ Edit ~

You can just add it to an existing START event if you have one.
no ur not understanding me.

if i use that code for my script it will have firstrun var set.

then i send it to my friend when i forget to remove the firstrun var. how can his pc detect he is running it first time?
Well why would you send a script to someone with variables already set for your script?
Code:
alias sn { 
  var %a = a $+ $ticks, %b = b $+ $ticks, %result
  .comopen %a wbemscripting.swbemlocator
  if (!$comerr) {
    .comclose %a $com(%a,connectserver,3,dispatch* %b)
    if (!$comerr) {
      .comclose %b $com(%b,execquery,3,bstr,select serialnumber from win32_operatingsystem,dispatch* %a)
      if (!$comerr) {
        %result = $sha1($comval(%a,1,serialnumber))
        .comclose %a
      }
    }
  }
  return %result
}


What this code does is return a SHA-1 hash of your operating system's serial number. So you could do something like this:

Code:
on *:start:{
  if ($sn != %thispc) {
    %thispc = $v1
    ; execute code for first run...
  }
}


The only problem is that it's not very portable. I believe any windows version older than XP comes without WMI installed by default. To do any better you'll probably need a dll.
You don't need WMI, RegRead (Search the board for it if you don't have one) can grab the OS Serial number.

The key to read is

9x: HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductID

NT: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID
Good idea.

Code:
alias regread {
  var %a = a $+ $ticks, %result
  .comopen %a wscript.shell
  if (!$comerr) {
    noop $com(%a,regread,3,bstr,$1-)
    %result = $com(%a).result
    .comclose %a
  }
  return %result
}
alias sn {
  if ($regread(HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductID)) || ($regead(HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID)) { return $sha1($v1) }
}
Slight addition
Code:
alias sn {
  if ($os isin 9598ME && $regread(HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductID)) || ($regead(HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID)) { return $sha1($v1) }
}
nice idea guys, this is exactly the kind of thing i was looking for! i will work on it now! thanks.

by the way, that should also work find on vista shouldnt it?
hey i tried //echo -a $sn and it just give me

* /echo: insufficient parameters
The second $regread has a typo in both of our posts, it should be $regread

Thanks rock laugh
$regread ?
yep, corrected that

still the same problem frown
What version of mIRC are you using?
6.21 here hixxy

Code:
alias regread {
  var %a = a $+ $ticks, %result
  .comopen %a wscript.shell
  if (!$comerr) {
    noop $com(%a,regread,3,bstr,$1-)
    %result = $com(%a).result
    .comclose %a
  }
  return %result
}

alias sn {
  if ($os isin 9598ME && $regread(HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProductID)) || ($regread(HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductID)) { return $sha1($v1) }
}


//echo -a $sn

-
* /echo: insufficient parameters
-
All of this to save typing "/set %firstrun 0"?
You'd send him your script, not your remote.ini, where the variables are.
Anyway, how about:
Code:
on *:LOAD: {
  set %nofirstrunofmyscriptname $true
}

on *:START: {
  if (%nofirstrunofmyscriptname) {
    ; first run stuff
    unset %nofirstrunofmyscriptname
  }
  else {
    ; whatever else
  }
}

Sidenote: I ran the posted script on v6.21 and got a 'no such identifier' error, as $sha1 was only added in v6.3
Changing it to $md5 worked, tho.
Perhaps you have Windows Scripting Host disabled? (I seem to recall once having something that would do that.)
i changed it to

return $v1

and it works fine, why the $sha anyway?
Ok, I'm just curious why you don't just use on LOAD and be done with it? on START won't work because it checks every time, which doesn't make sense when you only want it to occur one time when you first use a script on any given computer. That's what on LOAD is for.

Unless you're including mIRC with the script, I don't see what on LOAD won't do what you need.
$sha1 was added in 6.3. The reason I returned a SHA-1 hash of the serial number is because you shouldn't be handing it out. People will be able to use your serial number to register an illegitimately gained OS if you don't encrypt it.

You could use $md5() instead of $sha1(), which is supported by many more versions.
© mIRC Discussion Forums