mIRC Home    About    Download    Register    News    Help

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

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

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?

Joined: Dec 2002
Posts: 3,547
S
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?

Joined: Sep 2005
Posts: 2,881
H
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.

Joined: Jun 2006
Posts: 508
D
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

Joined: Sep 2005
Posts: 2,881
H
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) }
}

Joined: Jun 2006
Posts: 508
D
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) }
}

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?

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

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

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

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

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
-

Joined: Dec 2002
Posts: 2,962
S
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.
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.)


LonDart
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?

Joined: Oct 2004
Posts: 8,330
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
Joined: Sep 2005
Posts: 2,881
H
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.


Link Copied to Clipboard