mIRC Home    About    Download    Register    News    Help

Print Thread
P
pouncer
pouncer
P
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?

Joined: Dec 2002
Posts: 1,995
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 1,995
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.

P
pouncer
pouncer
P
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?

Joined: Dec 2002
Posts: 3,534
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,534
Well why would you send a script to someone with variables already set for your script?

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
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.

Joined: Jun 2006
Posts: 506
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 506
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

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
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) }
}

Joined: Jun 2006
Posts: 506
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 506
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) }
}

P
pouncer
pouncer
P
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?

P
pouncer
pouncer
P
hey i tried //echo -a $sn and it just give me

* /echo: insufficient parameters

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
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.
Joined: Dec 2002
Posts: 1,995
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 1,995
$regread ?

P
pouncer
pouncer
P
yep, corrected that

still the same problem frown

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
What version of mIRC are you using?

P
pouncer
pouncer
P
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
-

Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
All of this to save typing "/set %firstrun 0"?

Joined: Jul 2006
Posts: 107
L
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.)

P
pouncer
pouncer
P
i changed it to

return $v1

and it works fine, why the $sha anyway?

Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
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.

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
$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.


Link Copied to Clipboard