Jump to content

Recommended Posts

Posted (edited)

Hi ppl, got a problem with this, It's for a small project i have, it was sugested that i should include an error check, but now im stuck here,

if i only use one string to compare, it works, so im wondering am im missing some operator for this?

I could do multiple checks with each of them, but this way it would be simpler, what am i missing here?

$LastKey1 = ClipGet()
$string = StringRegExp($LastKey1, "HKEY_CLASSES_ROOT" Or "HKEY_CURRENT_USER" Or "HKEY_LOCAL_MACHINE" Or "HKEY_USERS" Or "HKEY_CURRENT_CONFIG", 0)
If $string = 0 Then
MsgBox(4096, "Error", "Clipboard content is not a registry key!")
Exit
ElseIf $string = 1 Then
MsgBox(4096, "ClipGet", "Clipboard content is a registry key!")
;function
EndIf

error check.au3

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

Please have a look at function StringRegExp. The regular expression you have added look wrong to me. Simply use something like this:

If $string = "HKEY_CLASSES_ROOT" Or $string = "HKEY_CURRENT_USER" Or $string = "HKEY_LOCAL_MACHINE" Or $string = "HKEY_USERS" Or $string = "HKEY_CURRENT_CONFIG" Then ..
or shorter
If StringLeft($string, 5) = "HKEY_" Then ..

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

It is wrong as you can't use OR, SRE requires a pattern. Give me 10 mins and I will try to come up with something.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

  On 10/23/2012 at 11:17 AM, 'water said:

Please have a look at function StringRegExp. The regular expression you have added look wrong to me. Simply use something like this:

If $string = "HKEY_CLASSES_ROOT" Or $string = "HKEY_CURRENT_USER" Or $string = "HKEY_LOCAL_MACHINE" Or $string = "HKEY_USERS" Or $string = "HKEY_CURRENT_CONFIG" Then ..
or shorter
If StringLeft($string, 5) = "HKEY_" Then ..

Hello, thanks for the quick answers, although there is a problem with the first option you pointed out, Water, that is, that way the string has to be exactly like one of those strings...using "SRE" i check if there is any of the strings IN the clipboard string...

The second one works fine, as long as i don't copy any " ", in the left, that is. :)

EDIT: I managed to do it in a complicated way, here it goes: (i don't really open any of the "HKEY_USERS" or "HKEY_CURRENT_CONFIG" so left those out)

$LastKey1 = ClipGet()
$string = StringRegExp($LastKey1, "HKEY_CLASSES_ROOT", 0)
If $string = 0 Then
Error1()
ElseIf $string = 1 Then
OK()
EndIf
Func Error1()
$string = StringRegExp($LastKey1, "HKEY_CURRENT_USER", 0)
If $string = 0 Then
Error3()
ElseIf $string = 1 Then
OK()
EndIf
EndFunc ;==>Error1
Func Error3()
$string = StringRegExp($LastKey1, "HKEY_LOCAL_MACHINE", 0)
If $string = 0 Then
Error4()
ElseIf $string = 1 Then
OK()
EndIf
EndFunc ;==>Error3

Func Error4()
MsgBox(4096, "Error", "Clipboard content is not a registry key!")
Exit
EndFunc ;==>Error4

Func OK()
MsgBox(4096, "ClipGet", "Clipboard content is a registry key!")
;function
EndFunc ;==>OK
Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

To handle leading spaces you could use:

If StringLeft(StringStripWS($string, 1), 5) = "HKEY_" Then ..

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)

Thank you, Indeed, that removes the spaces, for the "" i'll have to use something else, like:

$LastKey1 = StringRegExpReplace($LastKey1, '"', '')

Although i have a rudimentar error check, feel free to improve it with smaller, simpler code,

maybe using StringRegExp, meaning im still stuck, because i can't make it work in one sentence with SRE. lol

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

$LastKey1 = StringRegExpReplace($LastKey1, '"', '')

isn't a regular expression.

As you don't seem to be familiar with SRE I would stick with the "basic" functions. So use

$LastKey1 = StringReplace($LastKey1, '"', '')

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

My fail, thanks.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

This >>

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Wow, thanks, it was returning HKEY_LOCAL_MACHINE as false, added |MACHINE to the last part of the SRE. gonna work on this to implement the errors and such, thanks guinness, do you have this somewhere here in the forum? would be a nice snippet adition, don't you think? :)

Return StringRegExp($LastKey1, '^(HK(LM|U|CU|CR|CC|EY)_?(CLASSES|CURRENT|LOCAL)?_?(USER(S)?|ROOT|CONFIG|MACHINE)?)', 0) = 1

Does the question mark act like a concatenate operator? i think im starting to understand this patterns.

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

No, I created it for your use only.

I also fixed the error with MACHINE, realised after I posted it.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Thanks, here it is the result of what im going to include in the project, thanks to Mr. Guinness.

$LastKey1 = ClipGet()
$LastKey1 = StringReplace($LastKey1, '"', '')
$LastKey2 = StringRegExp($LastKey1, '^(HK(LM|U|CU|CR|CC|EY)_?(CLASSES|CURRENT|LOCAL)?_?(USER(S)?|ROOT|CONFIG|MACHINE)?)', 0) = 1
If $LastKey2 = True Then
MsgBox(4096, "ClipGet", "Clipboard content is a registry key!")
Else
MsgBox(4096, "Error", "Clipboard content is NOT a registry key!")
;Exit
EndIf

Edit: typo

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

You're welcome. I may optimise the SRE and post to the examples section in the next couple of days.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

A different approach without using SRE >>

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Thank you, Good job, only a question, "HKEY_LOCAL_MACHINE64" this doesn't exist on my registry, i believe, so why does it appear as valid?

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

  Help File said:

When running on 64-bit Windows if you want to read a value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Alright, thanks.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...