sparkie
(Getting the hang of it)
2010-12-14 09:35 AM
Urgent request - key lookup

I need to create a registry lookup of a key to somehow contact ICT if it exists. I currently use this command to lookup for another item.

IF ReadValue

Is this possible?

Many thanks


sparkie
(Getting the hang of it)
2010-12-14 09:59 AM
Re: Urgent request - key lookup

Digging further maybe I can use the sendmessage to identify the user sending the message

sparkie
(Getting the hang of it)
2010-12-14 11:30 AM
Re: Urgent request - key lookup

Ok, I'm getting nowhere fast with this. Using this context but it seems the lookup is not working. If I omit the KeyExist the messge gets submitted locally.

IF KeyExist ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook”)
$RC = SendMessage("ELWY", "Test")
ELSE
?"do nothing"
ENDIF


Richard H.Administrator
(KiX Supporter)
2010-12-14 01:19 PM
Re: Urgent request - key lookup

That double-quote character at the end of the KeyExist line is not a normal double quote, it is a "smart" quote.

You get these if you copy'n'paste from the manual or if you use something like Word to edit your script.

Replace it with a normal quote character and you should get a better result.


sparkie
(Getting the hang of it)
2010-12-14 04:06 PM
Re: Urgent request - key lookup

Thanks Richard, I had a play around and reverted to this but I have a couple of issues.

;$ReturnCode = KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Default Outlook Profile")
$ReturnCode = KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook")
If $ReturnCode
SHELL "sc config messenger start= demand"
SHELL "NET START Messenger"
SHELL "sc config messenger start= disabled"
$RC = SendMessage("MATAURA", "Test")
ELSE
?"Do nothing"

Endif

It seems to work (sending test message to itself at the moment) but since my PC is Vista, it doesn't have the messenger service so it's becoming difficult to test.

Any ideas?


Mart
(KiX Supporter)
2010-12-14 04:30 PM
Re: Urgent request - key lookup

Have a look at Blat.exe. A simple command line e-mail tool. I use it a lot and it works great.

 Code:
$Sender = "sender@@yourdomain.com"
;Set a recipient address.
$Recipients = "recipient@@yourdomain.com"
;Set the subject.
$Subject = '"Subject"'
;SMTP server to be used for sending the message.
$smtpserver = "mailserver"
;Create the body text.
$Body = '"Message body"'
;Send the message.
$Send = BlatMailerNoAttachment($Recipients, $Sender, $Subject, $Body, $smtpserver)

Function BlatMailerNoAttachment($Recipient, $Sender, $Subject, $Body, $smtpserver)
	Dim $MailerLine
	$MailerLine = 'patht\blat.exe -' + ' -to ' + $recipient + ' -f ' + $sender + ' -subject ' + $subject + ' -body ' + $body + ' -server ' + $smtpserver + ' -q '
	Shell $MailerLine
EndFunction


Glenn BarnasAdministrator
(KiX Supporter)
2010-12-14 05:40 PM
Re: Urgent request - key lookup

There's actually an easy method for using Blat from a central server illustrated in fair detail in the Script Vault. This allows any kix script to send email simply by writing a file and moving it to a central file share. There, a Kix script monitors the folder for new files and extracts the information, using it as arguments to Blat. Blat then sends the message file contents as the email body.

This allows any computer to send an automated message without anything more than Kixtart available. No need to have Blat, configure it's registry settings, or anything else on the PC. Depending on how fast you cycle the monitor script, messages can arrive in your inbox within 30 seconds or so.

Glenn


sparkie
(Getting the hang of it)
2010-12-14 06:06 PM
Re: Urgent request - key lookup

I had a quick play with Blat and it didn't work. All I want to do is send a message to either a computer or an email address (internal domain) when a domain user logs in on a PC and a certain key exists.

I'm open to suggestions


Glenn BarnasAdministrator
(KiX Supporter)
2010-12-14 06:57 PM
Re: Urgent request - key lookup

To send email, you need Blat or an equivelent application.

To send a message, you need the messaging service running (security risk) or need to write your own (complex).

Taking the time to properly configure Blat on a central server will be worth the 30 minutes of effort to install and configure it. Once done, any script can easily send a message via email.

Some things to consider with email - Blat needs to know the proper SMTP server address and may require a valid user account to send mail. The server sending mail via Blat may need to be configured on the mail server as an authorized relay host. This is just part of configuring email within your network.

Another solution, also in the Script Vault, would be to drop message files in the share of a central server. A script running there would process the dropped files, either sending email (again, with blat or similar tool), printing a report, or displaying a popup message. This way, all of the complex configuration is done on one computer.

Glenn


Richard H.Administrator
(KiX Supporter)
2010-12-15 09:21 AM
Re: Urgent request - key lookup

Blat it a 3rd party application, did you install it?

http://www.blat.net/

Also bear in mind that many companies (including mine) block outgoing SMTP on desktops for security reasons to stop mass mailers and virus propogation. McAfee's AV product does this out of the box for example.

You can test SMTP connectivity by telnet-ing from your desktop to port 25 on your SMTP server. If you can open the connection and get a response from EHLO then you're OK. Here is an example:
 Quote:
[root@xxx00006 ~]# telnet smtp.xxx.com 25
Trying 99.99.99.99...
Connected to smtp.xxx.com (99.99.99.99).
Escape character is '^]'.
220 xxx.xxx.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Wed, 15 Dec 2010 08:09:56 +0000
ehlo
250-xxx.xxx.com Hello [99.99.99.99]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK
quit
221 2.0.0 smtp.xxx.com Service closing transmission channel


Glenn BarnasAdministrator
(KiX Supporter)
2010-12-15 12:13 PM
Re: Urgent request - key lookup

 Originally Posted By: Richard H.
...bear in mind that many companies (including mine) block outgoing SMTP on desktops for security reasons to stop mass mailers and virus propogation. McAfee's AV product does this out of the box for example.
Exactly why the Kix mail service demonstrated in the script vault was developed. Even if servers aren't permitted to send mail, allowing a single server to send mail (or running the service on the mail server itself) is easy to configure. It all comes down to the security configuration and policies of the environment.

Glenn


sparkie
(Getting the hang of it)
2010-12-15 05:46 PM
Re: Urgent request - key lookup

No I haven't installed Blat. I downloaded the files and thought maybe I could copy the files to a folder and the script above could then be edited with the relevant credentials to run the .exe file. I'm thinking this is not the case.

I just want a simple way of reporting if a key exists when a user logs in based upon a current user key and since Messenger is disabled on everyones computer, it sounds like this is a problem.

Is there an alternative to a message?


Glenn BarnasAdministrator
(KiX Supporter)
2010-12-15 06:19 PM
Re: Urgent request - key lookup

Again, look in the script vault - there's a package for centralized reporting. It requires a bit of customization to your specific needs, but it would be minimal (client side - read the value and write the result, server side, read the value, add to a table, database, or some report document). The hard stuff is done - managing the reciept of many individual updates and consolidating the information. Not as real-time as message or email, but effective.

Glenn


sparkie
(Getting the hang of it)
2010-12-16 10:00 AM
Re: Urgent request - key lookup

Ok, Blat seems to be working when I login to our Terminal Servers (2008) as a domain user, but not when I login to an XP domain PC.

One thing I need to do is have the email encorporate some kind of info to advise us which user/computer the email was sent from.


Richard H.Administrator
(KiX Supporter)
2010-12-16 10:05 AM
Re: Urgent request - key lookup

Did you run the test as I advised earlier from your client PC?

If you are blocking port 25 from the client you will not be able to do simple direct mail and will have to use a different technique.

If you want something very simple then just write the status to a file on a server share, then just review the file regularly. If you have a lot of clients you might want to use multiple files.


sparkie
(Getting the hang of it)
2010-12-16 10:10 AM
Re: Urgent request - key lookup

Richard,

That's exectly the one I'm running. Also I need to define who the email was coming from


sparkie
(Getting the hang of it)
2010-12-16 11:48 AM
Re: Urgent request - key lookup

I'm going to scrap this idea since the workstations are locked down and too much time is being spent firefighting a simple email solution. Blat works using an out of box scenario, but not if ports/ etc aren't available.

BradV
(Seasoned Scripter)
2010-12-16 11:57 AM
Re: Urgent request - key lookup

Have the script write an INI file on a central server. Use the workstation name as the file name. Then write parameters as needed. Such as "user=fred", etc.

Then you can have a server process enumerate the directory; read the files it finds; send the e-mail; delete the file.


sparkie
(Getting the hang of it)
2010-12-16 12:20 PM
Re: Urgent request - key lookup

 Originally Posted By: BradV
Have the script write an INI file on a central server. Use the workstation name as the file name. Then write parameters as needed. Such as "user=fred", etc.

Then you can have a server process enumerate the directory; read the files it finds; send the e-mail; delete the file.


That seems to be my best solution, are there any examples here so I'm not re-inventing the wheel.

I'll need to to only run if domain user login OS is XP or Vista


Glenn BarnasAdministrator
(KiX Supporter)
2010-12-16 08:07 PM
Re: Urgent request - key lookup

Once again, check the script vault for a mostly ready to run app. The core logic is there, you'll need to use the functions in your own code, since only you know what data you need to collect and write.

The article is titled "Central Data Collection - Kix as a Service" - it's exactly what you need. I mentioned this a few days ago as an alternative to email.

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2010-12-16 08:10 PM
Re: Urgent request - key lookup

Oh - and RESIST the temptation to
  • write directly to the server.. the monitor service can find and read your file before you've completely written it. Create it locally and then move it to the share.
  • Short-cut and try to write directly to a single central file. There's no file locking, so its possible for you to lose data this way.

Glenn


Richard H.Administrator
(KiX Supporter)
2010-12-17 08:50 AM
Re: Urgent request - key lookup

It depends on your need. In this case small INI files on a central server are fine, even a monolithic file is fine as long as the total user base and concurrent login count is small. If it doesn't matter so much whether you are alerted the first time someone logs in or the third time that they log in then it doesn't warrant significant additional coding complexity which has to be maintained. If you do need to know first time then validate by reading back and re-doing the WriteValue() in a simple loop. Definately use INI files though, flat text files are more of a problem and require more complex coding from the start.

Sometimes good enough is all that is needed to do the job.


sparkie
(Getting the hang of it)
2010-12-17 10:23 AM
Re: Urgent request - key lookup

Ok, I've managed to get Blat working when the XP domain user logs on, how do I define the message so we know which computer has sent the email?

Mart
(KiX Supporter)
2010-12-17 11:17 AM
Re: Urgent request - key lookup

In my example above I use the $Body variable for the body text of the message. You can out your data in there.

sparkie
(Getting the hang of it)
2010-12-17 12:08 PM
Re: Urgent request - key lookup

Mart, I'm using your edited example with $body, but we have no idea which PC the email is coming from

 Code:
$ReturnCode = KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Default Outlook Profile")
;$ReturnCode = KeyExist("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook")
	If $ReturnCode
	$Sender = "ICT@@blah.com"
	;Set a recipient address.
	$Recipients = "ICT@@blah.com"
	;Set the subject.
	$Subject = '"TEST - Outlook Profile details"'
	;SMTP server to be used for sending the message.
	$smtpserver = "IP Adresss"
	;Create the body text.
	$Body = '"My Outlook Profile is Outlook"'
	;Send the message.
	$Send = BlatMailerNoAttachment($Recipients, $Sender, $Subject, $Body, $smtpserver)
	Function BlatMailerNoAttachment($Recipient, $Sender, $Subject, $Body, $smtpserver)
	Dim $MailerLine
	$MailerLine = '\\artic\Blat\blat.exe -' + ' -to ' + $recipient + ' -f ' + $sender + ' -subject ' + $subject + ' -body ' + $body + ' -server ' + $smtpserver + ' -q '
	Shell $MailerLine
	EndFunction
	ELSE
	?"do nothing"
ENDIF


Richard H.Administrator
(KiX Supporter)
2010-12-17 12:14 PM
Re: Urgent request - key lookup

You can declare it in the body using the "From:" SMTP header, but also look at the BLAT "-i" and "-f" options which allow you to specify the sender, or use the more granular envelope options that are available.

From the BLAT documentation:
 Originally Posted By: BLAT documentation
Note that if the '-i' option is used, <sender> is included in 'Reply-to:'
and 'Sender:' fields in the header of the message.

Optionally, the following options can be used instead of the -f and -i
options:

-mailfrom <addr> The RFC 821 MAIL From: statement
-from <addr> The RFC 822 From: statement
-replyto <addr> The RFC 822 Reply-To: statement
-returnpath <addr> The RFC 822 Return-Path: statement
-sender <addr> The RFC 822 Sender: statement

For backward consistency, the -f and -i options have precedence over these
RFC 822 defined options. If both -f and -i options are omitted then the
RFC 821 MAIL FROM statement will be defaulted to use the installation-defined
default sender address.


For example you could:
 Code:
blat -i %USERNAME%@%COMPUTERNAME% ...


Richard H.Administrator
(KiX Supporter)
2010-12-17 12:21 PM
Re: Urgent request - key lookup

In your sample script you may change the following variables accordingly:
 Code:
	$Sender = @USERID+"@@"+@WKSTA+".blah.com"
	$Body = '"My Outlook Profile is Outlook, I am workstation '+@WKSTA+'"


BradV
(Seasoned Scripter)
2010-12-17 12:23 PM
Re: Urgent request - key lookup

Following Glen's suggestion, here is some untested code:

 Code:
Dim $Key, $ReturnCode, $Wks, $Val, $User, $File, $DataPath
;
$Key = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook"
;
$ReturnCode = KeyExist($Key)
If $ReturnCode
   ; The key does exist.  Write the information to the central server.
   $Wks      = @WkSta
   $val      = ReadValue($Key,"")
   $User     = @USERID
   $File     = "%TEMP%" + "\" + $Wks + "-" + @TIME + ".ini"
   $DataPath = "\\server\share\profile_folder"
   ;
   $ReturnCode = WriteProfileString($File, $Wks, "Profile Key Exists", "True")
   $ReturnCode = WriteProfileString($File, $Wks, "User", $User)
   $ReturnCode = WriteProfileString($File, $Wks, "Workstation", $Wks)
   $ReturnCode = WriteProfileString($File, $Wks, "Default Value", $Val)
   ;
   Move $File $DataPath
EndIf


Then you just need to write a script on the central server to check the contents of the directory periodically. You may not even need blat.


sparkie
(Getting the hang of it)
2010-12-17 01:40 PM
Re: Urgent request - key lookup

 Originally Posted By: Richard H.
In your sample script you may change the following variables accordingly:
 Code:
	$Sender = @USERID+"@@"+@WKSTA+".blah.com"
	$Body = '"My Outlook Profile is Outlook, I am workstation '+@WKSTA+'"


This is what I went for, but thanks to everyone. Btw you missed a ' but you can be excused for that \:\)

Is there a list of all the permitations of 'equal/not equal to' because I want it to email if the key does not equal 'Outlook'?


Les
(KiX Master)
2010-12-17 02:54 PM
Re: Urgent request - key lookup

 Originally Posted By: sparkie
Is there a list of all the permitations of 'equal/not equal to' because I want it to email if the key does not equal 'Outlook'?
Huh? The function tests whether or not it "Exists". If it exists, it is "equal to", if it doesn't it is "not equal to". There is no in between. It is a true/false.


Richard H.Administrator
(KiX Supporter)
2010-12-17 04:18 PM
Re: Urgent request - key lookup

 Code:
Is there a list of all the permitations of 'equal/not equal to' because I want it to email if the key does not equal 'Outlook'?


I think you mis-understand the registry keys.

Within "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles" you can have many profilses, not just one. Most people will only have one on their work machine, but they may have more. To check what keys are present you have to enumerate them.

There is a value which defines which (if any) of the messaging profiles is the default.

The important thing to note is that the profile name is not fixed and is not significant - it could be "Outlook" or "Billy's mail" or just about anything.

If you want to check the default profile here is an example of how you might do it:
 Code:
$sProfileKey="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
$sDefaultProfileValue="DefaultProfile"
$sExpectedProfile="Default Outlook Profile"

$sProfile=ReadValue($sProfileKey,$sDefaultProfileValue)

If $sProfile=$sExpectedProfile
	"Your default messaging profile matches the expected '"+$sExpectedProfile+"'"+@CRLF
Else
	"Your default messaging profile is '"+$sProfile+"' which does not match the expected '"+$sExpectedProfile+"'"+@CRLF
EndIf


You will get better answers from us if you explain what you are checking for and why, otherwise we may send you off down an inappropriate route.


sparkie
(Getting the hang of it)
2010-12-17 04:31 PM
Re: Urgent request - key lookup

 Originally Posted By: Les
 Originally Posted By: sparkie
Is there a list of all the permitations of 'equal/not equal to' because I want it to email if the key does not equal 'Outlook'?
Huh? The function tests whether or not it "Exists". If it exists, it is "equal to", if it doesn't it is "not equal to". There is no in between. It is a true/false.


Sorted now, used this

If NOT $ReturnCode

If the key does not equal to the $ReturnCode I get the email, if it does we get nothing. Just as we wanted.

Thanks everyone for their help and have a Happy Christmas