Saleem
(Hey THIS is FUN)
2003-09-22 09:44 AM
keyexist()

code:
$ReturnCode = KeyExist("HKEY_CURRENT_USER\Console")
If $ReturnCode=1
? "Key exists...."
EndIf


Key exist fuction is not returning any thing !! any idea??


Mart
(KiX Supporter)
2003-09-22 10:00 AM
Re: keyexist()

quote:

Key exists....
0 - The operation completed successfully.

No probs here.
This key only exist after logon using win9x if I recall correctly.


Saleem
(Hey THIS is FUN)
2003-09-22 10:00 AM
Re: keyexist()

Now I change the script to read the value but still not working

quote:

Call "d:\kix\udf\netview2.udf"
$computerlist=NetView2()
For Each $computer In $computerlist
$PRODUCTTYPE=ReadValue('\\'+$computer+'\HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\PRODUCTOPTIONS','PRODUCTTYPE')
If $PRODUCTTYPE="WinNT"
$regkey='\\'+$computer+'\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$regvalue='CurrentVersion'
If ReadValue($regkey,$regvalue)='5.0'
? "$computer 2k"
$RDD=ReadValue('\\'+$computer+'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt','DisplayName')
? $rdd
If ($RDD="Microsoft Composite Battery Driver")
? "$computer is laptop"
Open(1,"C:\laptop2k.TXT",5)
WriteLine (1,"$computer"+@CRLF)
Close(1)
EndIf
EndIf
EndIf
Next

This job is very urgent for me pls help...

I am running the script from w2k PC my KIX ver is 4.21


Saleem
(Hey THIS is FUN)
2003-09-22 10:02 AM
Re: keyexist()

it is not returning 0 or 1 [Roll Eyes]

Mart
(KiX Supporter)
2003-09-22 10:04 AM
Re: keyexist()

Change this...
quote:

('\\'+$computer+'\HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\PRODUCTOPTIONS','PRODUCTTYPE')

to this...
quote:

('\\$computer\HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\PRODUCTOPTIONS','PRODUCTTYPE')

This works for me on W2K.

Did a simple check with this

code:
$computer = @WKSTA
$PRODUCTTYPE=ReadValue('\\$computer\HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\PRODUCTOPTIONS','PRODUCTTYPE')
? "$producttype...."
? "@ERROR - @SERROR"

Sleep 3

Why not just use @PRODUCTTYPE

[ 22. September 2003, 10:11: Message edited by: R2D2 ]


Saleem
(Hey THIS is FUN)
2003-09-22 10:10 AM
Re: keyexist()

That line is ok for me

Just runt this line in ur pc

code:
$RDD=KeyExist('\\'+remotepc+'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt')
$RDDL=KeyExist("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt")
? "$rdd"
? "$rddl"

just see $rdd and $rddl is returning "0" or "1"


Saleem
(Hey THIS is FUN)
2003-09-22 10:21 AM
Re: keyexist()

you are right buddy that was the issue, now it is working, basically I am trying to find out laptop's in my network here is my latest code.

code:
 
Call "d:\kix\udf\netview2.udf"
$computerlist=NetView2()
For Each $computer In $computerlist
$PRODUCTTYPE=ReadValue('\\$computer\HKEY_LOCAL_MACHINE\SYSTEM\CURRENTCONTROLSET\CONTROL\PRODUCTOPTIONS','PRODUCTTYPE')
If $PRODUCTTYPE="WinNT"
$regkey='\\'+$computer+'\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$regvalue='CurrentVersion'
If ReadValue($regkey,$regvalue)='5.0'
? "$computer 2k"
$RDD=KeyExist('\\$computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt')
? $rdd
If ($RDD=1)
? "$computer is laptop"
Open(1,"C:\laptop2k.TXT",5)
WriteLine (1,"$computer"+@CRLF)
Close(1)
EndIf
EndIf
EndIf
Next

but I foung the reg. key which I am serching for LAptop is existing in some of my compaq PC's (D51c HP) can some body tell me any uneeque key which is only there in Laptop ??


Mart
(KiX Supporter)
2003-09-22 10:24 AM
Re: keyexist()

Why don't you use @PRODUCTTYPE [Confused]

Saleem
(Hey THIS is FUN)
2003-09-22 10:30 AM
Re: keyexist()

@PRODUCTTYPE wont say the PC is LAPTOP or normal !!
quote:

@PRODUCTTYPE
OS type. Possible values:
"Windows 95"
"Windows 98"
"Windows Me"
"Windows NT Workstation"
"Windows NT Server"
"Windows NT Domain Controller"
"Windows 2000 Professional"
"Windows 2000 Server"
"Windows 2000 Domain Controller"
"Windows XP Home Edition"
"Windows XP Professional"
"Windows XP Server"
"Windows XP Domain Controller"



Mart
(KiX Supporter)
2003-09-22 10:38 AM
Re: keyexist()

Yep. But I donít see you using the producttype to find out if itís a laptop or not.

This...
quote:

$RDD=KeyExist('\\$computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt')

...is used to see if it's a laptop or not. So I don't see any reason why the @PRODUCTTYPE can't be used. But everybody has its own preferences so if you like it better this way it's OK [Embarrassed]

BTW,
Thereís still one little error in your script [Wink]

quote:

$regkey='\\'+$computer+'\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'



[ 22. September 2003, 10:38: Message edited by: R2D2 ]


Saleem
(Hey THIS is FUN)
2003-09-22 10:56 AM
Re: keyexist()

As i said @producttype will not say the Machine is LAPTOP or normal PC then waht is the point of using it ?

another thing

quote:

$RDD=KeyExist('\\$computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt')


I found this key in few desktop PC's too, what else I can do to find out LAPTOP's??


Mart
(KiX Supporter)
2003-09-22 11:14 AM
Re: keyexist()

In your script the productype is checked by looking into the registry and used to startup the laptop or desktop check. Checking on @PRODUCTTYPE will also give you Windows NT, 2000, XP or whatever. Saved the time to create a script that looks into the registry and eliminates possible errors.

I've seen some people doing a check in the registry is any PCMCIA ports are installed (I think Radimus said some words about this some a few weeks ago). A standard desktop pc will not have PCMCIA ports installed.

A check on @CPU might also do the trick. If you're laptops are recent there is a good change that they have a Pentium Mobile CPU. Not sure if @CPU returns the correct value for a mobile CPU because I can't test this now.


LonkeroAdministrator
(KiX Master Guru)
2003-09-23 12:53 AM
Re: keyexist()

ja.
my laptop is already 2 years old. [Frown]
it says "Intel Pentium III"


Mart
(KiX Supporter)
2003-09-22 02:05 PM
Re: keyexist()

OK, that sucks. There must be some other way then.
I'm almost sure I've seen something about checking for PCMCIA ports using WMI or reg checks or something. A few weeks ago.


Radimus
(KiX Supporter)
2003-09-22 02:25 PM
Re: keyexist()

http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=2;t=004556

basically, compbatt, will exist on laptops and desktops with smart UPSs

pcmcia cards are usually only in laptops, but not all... some PCs have them for smartcard readers.

and some laptops bios may or may not provide the case type... like old inspiron 7000s, but newer ones will.


LonkeroAdministrator
(KiX Master Guru)
2003-09-22 04:39 PM
Re: keyexist()

I thought I saw the discussion at the end of last week.

Kdyer
(KiX Supporter)
2003-09-22 05:35 PM
Re: keyexist()

Here you go..
code:
BREAK ON
CLS
;Requires WMIQuery > http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000117
;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_systemenclosure.asp
;Thanks Radimus for the inspiration!!
$casetype=WMIQuery('ChassisTypes','Win32_SystemEnclosure')[0]

?$casetype

FOR EACH $lt IN split($casetype, '8,9,10,11')
$lt="Lap"
NEXT

IF $lt<>""
?'PORTABLE'
ELSE
?'DESKTOP'
ENDIF

get $k

;Portable units would be
;--
;8 Portable
;9 Laptop
;10 Notebook
;11 Hand Held

;Desktops would be
;--
;1 Other
;2 Unknown
;3 Desktop
;4 Low Profile Desktop
;5 Pizza Box
;6 Mini Tower
;7 Tower
;12 Docking Station
;13 All in One
;14 Sub Notebook
;15 Space-Saving
;16 Lunch Box
;17 Main System Chassis
;18 Expansion Chassis
;19 SubChassis
;20 Bus Expansion Chassis
;21 Peripheral Chassis
;22 Storage Chassis
;23 Rack Mount Chassis
;24 Sealed-Case PC

Thanks,

Kent

[ 22. September 2003, 17:36: Message edited by: kdyer ]


ShaneEP
(MM club member)
2003-09-22 08:31 PM
Re: keyexist()

Does WMI work on Win9x? If not here is the code I have used in the past. Seems to always work for me.

code:
 
If KeyExist("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ACPI\PNP0C0A") or KeyExist("HKEY_LOCAL_MACHINE\Enum\ACPI\*PNP0C0A")
$msg = messagebox ("This is a laptop!!","laptop",0)
Else
$msg = messagebox ("This is not a laptop!!","laptop",0)
Endif



Kdyer
(KiX Supporter)
2003-09-22 11:55 PM
Re: keyexist()

Work on 9x, natively - no.

You will need to download the following files for 9x/NT.

WMI9X.EXE/WMINT4.EXE

2k/XP/2K3 have WMI built-in.

Kent


marck1
(Fresh Scripter)
2003-09-23 12:33 AM
Re: keyexist()

Hi,

The following code is used to determine a W2K laptop:

$PCMCIA=READVALUE("HKLM\SYSTEM\CurrentControlSet\Services\Pcmcia","Start")
? "If Value PCMCIA Is 0 Than This Is A Laptop, Else A Desktop, Value Is $PCMCIA"

The following is used for W9x

$PCMCIA=EXISTKEY("HKLM\System\CurrentControlSet\Services\Class\PCMCIA\0000")
IF $PCMCIA=0
? "This Is A Laptop"
ENDIF

I hope this is useful.

regards,

Marck


Kdyer
(KiX Supporter)
2003-09-23 12:37 AM
Re: keyexist()

PCMCIA and Battery are not always good reliable detection for a Laptop vs. Desktop.

Kent


LonkeroAdministrator
(KiX Master Guru)
2003-09-23 12:37 AM
Re: keyexist()

kinda.
but that is not trustable.
like said already in THIS topic, pcmcia is not just for laptops.
it normal standard, just like PCI and it is foundable in desktops too.


marck1
(Fresh Scripter)
2003-09-23 12:51 AM
Re: keyexist()

We have about 2500 desktops and 1500 laptops and this script does the job. But Kent you are right, it wonít work in EVERY situation. We are not using any desktops with cardreaders, so....

[ 23. September 2003, 00:54: Message edited by: marck1 ]


NTDOCAdministrator
(KiX Master)
2003-09-23 02:36 AM
Re: keyexist()

Please see this posting for an update to this code.

http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=004591


ShaneEP
(MM club member)
2003-09-23 04:11 PM
Re: keyexist()

marck1...

The code I posted above has never failed. It also does not depend on PCMCIA or power mgmt software. The key...as far as I know will only be there if there is a physical battery in the machine.

Everyone else...

If someone could prove it wrong I would really apreciate it. Dont know why you would use some big WMI script when all you have to do is check for a registry key. Besides...I wish I could say we wont have any Win9x machines soon...But Im sure they will be around for a while. And IS is not going to spend the resources in adding WMI capabilities to them.

[ 23. September 2003, 16:13: Message edited by: CitrixMan ]


Sealeopard
(KiX Master)
2003-09-23 04:17 PM
Re: keyexist()

A UPS connected to a computer will also be detected as a battery. PCMCIA cards can be present in computers as well. The case type in WMI is not always set to the correct value.

ScriptLogic has looked into this extensively and the best they could come up with is a proprietary solution, which they plan to patent.


ShaneEP
(MM club member)
2003-09-23 04:31 PM
Re: keyexist()

Yes but a UPS connector will not show up in the registry key I specified. I have tested with PCs that have UPS connected...Like I said...If anyone can prove it to be faulty, Please do so.

Sealeopard
(KiX Master)
2003-09-23 05:52 PM
Re: keyexist()

Everybody, please give this UDF a try: IsLaptop() - Determines whether a local/remote computer is a laptop .

The code below will display all computers in a domain and whether they're laptops or not. Windows 9x computers must have remote registry access enabled to be classified as laptop.
code:
$sComps=NetView2()
for each $sComp in $sComps
$iRC=IsLaptop($sComp,1)
select
case $iRC=-1
? $sComp+' is unknown'
case $iRC=1
? $sComp+' is a laptop'
case $iRC=0
? $sComp+' is not a laptop'
case 1
? 'undefined'
endif
next
exit 0



NTDOCAdministrator
(KiX Master)
2003-09-23 11:46 PM
Re: keyexist()

Don't want to really run against my entire Domain right now as that takes hours to run, but so far on about a dozen computers it appears to work well.

Hopefully CitrixMan is correct.

I know WMI is a pig, but since you have to use it for some other things, nice to have another method of getting data.

This Reg method is quicker for sure, but if you want to get back the other data then this looks good too.
http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=004591

[ 24. September 2003, 00:23: Message edited by: NTDOC ]


Sealeopard
(KiX Master)
2003-09-24 05:00 PM
Re: keyexist()

I just wanted a quick binary IsLaptop check for the client-side, primarily login scripts. The WMI approach is more better suited for admin scripts, IMHO.

NTDOCAdministrator
(KiX Master)
2003-09-24 06:53 PM
Re: keyexist()

Well I haven't gotten there yet, but I'm hoping to run silent scripts with WKIX32.EXE and I want to probably sleep the script for maybe a couple minutes after logon before it starts to really do anything.

At that point as long as you are not stealing all the CPU cycles and bandwidth of the client, you should be able to do similar things like MS SMS does and do background processing.

I am currently re-writing my entire logon script (thus all the recent posts about repairing scripts and UDFs to support the NoVarInStrings)

Nice posting by Howard about the SetOptions. Seems some things are not a clear as one would initially think.

I'm assuming that this will be the best practice for my new script.

DIM $Set1,$Set2
$Set1=SetOption('Explicit','ON')
$Set2=SetOption('NoVarsInStrings','ON')


Sealeopard
(KiX Master)
2003-09-24 07:15 PM
Re: keyexist()

My standard script header:
code:
DEBUG OFF
BREAK OFF
if instr(@scriptdir,'beta') or instr(@scriptdir,'test')
BREAK ON
endif

Dim $iRC
$iRC=SETOPTION('Explicit','ON')
$iRC=SETOPTION('NoVarsInStrings','ON')
$iRC=SETOPTION('WrapAtEOL','ON')

$iRC=SETTITLE('Script Title')

$iRC=Main()

exit 0



Saleem
(Hey THIS is FUN)
2003-09-25 06:20 AM
Re: keyexist()

I had two days off from Office, It is glad to know that the topic is still hot. Any ways I checked Citrix man's script and sorry to say that I found that key(PNPOCOA) in 4 desktop PC's in my company which is Compaq D51C/P253. thees PC was having COMPBATT key too where my script failed first time.

I found NTDOC (WMI query) was only Possible but as somebody said WMI is good only for admin script, I found that if I add WMI script in my login script and machine doesnít have WMI installed the entire script is failing to proceed.

I'll say what is my actual requirement to find laptop, My laptop users are taking their machines at home this is causing a virus threat, so we decided to write a script to check the dat version in laptop if it is old show a message to call help desk and log them off without further mercy !!

Pls let me know is there any other way to do this ... this is the requirement from or Vice president of I.T.

I'll post my old code

code:
$laptop=KeyExist("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\CompBatt")
If $laptop=1
$datver=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Network Associates\TVD\VirusScan Enterprise\CurrentVersion","szVirDefVer")
$srvdat=ReadProfileString("\\qasrvho\updates$\update.ini","SuperDat-IA32","DATVersion")
If ($datver=$srvdat)
? "same version"
Else
? "vier. is diffrent"
$msg=MessageBox ("Your virus deffnition files are old, Please call IT help desk immediatly!! You wont be able to login to network unless you have latest deffnition file","Virus file allert",16)
Logoff (1)
EndIf
EndIf



Kdyer
(KiX Supporter)
2003-09-25 06:58 AM
Re: keyexist()

quote:

was only Possible but as somebody said WMI is good only for admin script

If that is the case, install WMINT4.EXE/WMI9X.EXE to address this..

Kent


Saleem
(Hey THIS is FUN)
2003-09-25 11:03 AM
Re: keyexist()

It's a long way I guss, I have to find out the PC's which dosent have WMI and install it.....

I am looking for a quick solution.