Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Registry key check failing in Win 2003, works fine in other OSs ?

$
0
0

Hi,

My script does the below;

-takes a registry key input as a parameter from user with option k

-checks if the registry entered exists than exports that into a text file.

-if registry key doesn't exist than says: unable to open reg.......

The script below works fine in almost all operating systems except in Windows 2003.

The KeyExists function always returns a false result even though the entered key is correct and only in Win 2003 OS.

Set colNamedArguments = WScript.Arguments.Named
Set winsh = CreateObject("WScript.Shell")
StrFileName = "C:\reg.log"

If colNamedArguments.Exists("k") Then
  StrKey = colNamedArguments.Item("k")
  If KeyExists(StrKey) = True Then
    Wscript.echo "Scanning entered registry: " & StrKey & "..."
    StrKey = trim(StrKey)
    winsh.run "regedit /e " & chr(34) & StrFileName & chr(34) & " """& StrKey &"""",0,True
  Else
    Wscript.echo "Unable to open reg entered: " & StrKey
  End If
End If

Function KeyExists(ByVal key)
 If right(key, 1) <> "\" Then key = key & "\"
 On Error Resume Next
 winsh.RegRead trim(key)
 If Err.Number <> 0 Then
   keyExists = False
 Else
   keyExists = True
 End If
End Function

Any help please ?

Thanks!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>