mIRC Home    About    Download    Register    News    Help

Print Thread
how to tell when a script is run 1st time on a pc #186625 24/09/07 11:57 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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?

Re: how to tell when a script is run 1st time on a pc [Re: pouncer] #186626 24/09/07 12:00 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
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.

Re: how to tell when a script is run 1st time on a pc [Re: RoCk] #186637 24/09/07 01:17 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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?

Re: how to tell when a script is run 1st time on a pc [Re: pouncer] #186640 24/09/07 01:23 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Well why would you send a script to someone with variables already set for your script?

Re: how to tell when a script is run 1st time on a [Re: pouncer] #186642 24/09/07 01:32 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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.

Re: how to tell when a script is run 1st time on a [Re: hixxy] #186643 24/09/07 01:52 PM
Joined: Jun 2006
Posts: 508
D
deegee Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
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

Re: how to tell when a script is run 1st time on a [Re: deegee] #186644 24/09/07 01:58 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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) }
}

Re: how to tell when a script is run 1st time on a [Re: hixxy] #186645 24/09/07 02:04 PM
Joined: Jun 2006
Posts: 508
D
deegee Offline
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
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) }
}

Re: how to tell when a script is run 1st time on a [Re: deegee] #186648 24/09/07 02:57 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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?

Re: how to tell when a script is run 1st time on a [Re: pouncer] #186649 24/09/07 03:03 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
hey i tried //echo -a $sn and it just give me

* /echo: insufficient parameters

Re: how to tell when a script is run 1st time on a [Re: pouncer] #186654 24/09/07 03:39 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
The second $regread has a typo in both of our posts, it should be $regread

Thanks rock laugh

Last edited by hixxy; 24/09/07 03:47 PM.
Re: how to tell when a script is run 1st time on a [Re: hixxy] #186655 24/09/07 03:46 PM
Joined: Dec 2002
Posts: 2,021
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,021
$regread ?

Re: how to tell when a script is run 1st time on a [Re: RoCk] #186659 24/09/07 04:37 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
yep, corrected that

still the same problem frown

Re: how to tell when a script is run 1st time on a [Re: pouncer] #186660 24/09/07 05:09 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
What version of mIRC are you using?

Re: how to tell when a script is run 1st time on a [Re: hixxy] #186664 24/09/07 05:44 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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
-

Re: how to tell when a script is run 1st time on a [Re: pouncer] #186665 24/09/07 05:59 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
All of this to save typing "/set %firstrun 0"?


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: how to tell when a script is run 1st time on a [Re: pouncer] #186666 24/09/07 06:20 PM
Joined: Jul 2006
Posts: 107
L
LonDart Offline
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
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.)


LonDart
Re: how to tell when a script is run 1st time on a [Re: LonDart] #186667 24/09/07 06:39 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
i changed it to

return $v1

and it works fine, why the $sha anyway?

Re: how to tell when a script is run 1st time on a [Re: pouncer] #186677 24/09/07 08:40 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Re: how to tell when a script is run 1st time on a [Re: pouncer] #186680 24/09/07 09:10 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
$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.