notta Posted March 10, 2008 Share Posted March 10, 2008 (edited) Global Const $adminkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion";Key used for checking admin rights Global Const $adminval = "SystemRoot";Value used for checking admin rights Global Const $key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\KeyS" Global Const $value = "DisplayName" Ping($name,250) if @error Then; Could not even ping. Don't even waste time return "noPing" Else if RegRead("\\" & $name & "\" & $adminkey, $adminval) Then;Check if have admin rights on the machine if RegRead("\\" & $name & "\" & $key, $value) Then;Check if key[value] exists return "installed" Else return "notInstalled" EndIf Else return "noAdmin" EndIf EndIf Ok, I edited this because I was a little wordy. Can someone tell me how to handle if I don't have admin rights to read a key and the key not existing? Even if I use: $test = if RegRead("\\" & $name & "\" & $adminkey, $adminval) Then;Check if have admin rights on the machine if @error = 1 Or @error = 2 Or @error = 3 or @error = -1 or @error = -2 Then $test still gives a value of " ". The problem is that's the returned value of $notInstalled, so how can I tell the difference? Thanks. Edited March 10, 2008 by notta Link to comment Share on other sites More sharing options...
MHz Posted March 10, 2008 Share Posted March 10, 2008 I would expect the @error to be set to 3 if you do not have correct access rights to access a remote registry. Yopu can read the remarks about RegRead() for more information. To cover all @error values, use If RegRead("\\" & $name & "\" & $adminkey, $adminval) And Not @error ThenoÝ÷ Øò¢æ«z¶)àj·º¹è~«¨¶z-"{-jY^v«¨¶Ø^ EæÂ+aºÈ§·¦¢×«z¬¶¼¬y鬶ÞÂäx,¢ØZ¶ÇËajÛaz«¨´8¬¦V²5©ªê-½©nyÚ²z-{¬¶Þr )දj[¡÷«®æk*Þ¶êçÞwè®fèØ^q«¬zíç«®ìzÔëÊÚuÖ²èÅ·¢·êÞ¶êç¡ú®¢Ùè´ìµ©eyÚ®¢Ûh¶¶©¶®º+¶zØ^Ë.y«¢+Ù5Í ½à À°Ìäí¹½Ñ%¹Íѱ±Ìäì°ÉɽȤ And $test is not the condition that tests "notInstalled" but the following condition? If the value is not an empty string, then RegRead() will succeed and you can further test the value for it's contents for expected value returned. Link to comment Share on other sites More sharing options...
GEOSoft Posted March 10, 2008 Share Posted March 10, 2008 (edited) You can not use an If statement on the same line that you declared a variable so $test = if will fail. $test = RegRead("\\" & $name & "\" & $adminkey, $adminval);Check if have admin rights on the machine If @Error Then MsgBox(0, "Error", "The error returned was " & @Error) MsgBox(0, "Return", "The return value of the RegRead is " & $Test") Edited March 10, 2008 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
notta Posted March 10, 2008 Author Share Posted March 10, 2008 (edited) You can not use an If statement on the same line that you declared a variable so $test = if will fail. $test = RegRead("\\" & $name & "\" & $adminkey, $adminval);Check if have admin rights on the machine If @Error Then MsgBox(0, "Error", "The error returned was " & @Error) MsgBox(0, "Return", "The return value of the RegRead is " & $Test") Thanks guys. Geo, haha sorry about that, in my script I had it correctly formed, but I added the $test in my post just to show that I tested to see the value returned. Anyway, I'm banging my head on this one. The bottom line is I'm looking to check for admin rights if I don't have it return noAdmin. If I do have admin rights, check to see if the key[value] exists. If the value exists return installed and if not return notInstalled. My logic with the combination of regread is not working Edited March 10, 2008 by notta Link to comment Share on other sites More sharing options...
GEOSoft Posted March 10, 2008 Share Posted March 10, 2008 Thanks guys. Geo, haha sorry about that, in my script I had it correctly formed, but I added the $test in my post just to show that I tested to see the value returned. Anyway, I'm banging my head on this one. The bottom line is I'm looking to check for admin rights if I don't have it return noAdmin. If I do have admin rights, check to see if the key[value] exists. If the value exists return installed and if not return notInstalled. My logic with the combination of regread is not working We all do things like that. What happens when you run the code I gave you? George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
notta Posted March 10, 2008 Author Share Posted March 10, 2008 (edited) We all do things like that.What happens when you run the code I gave you? I ran it and this is what I get:"The returned value of the RegRead is c:\Windows"That is one of the weird things. $name is my co-workers machine. I don't have admin rights on his machine. As a matter of fact, if I open regedit and choose "connect to network registry" I connect, but the minute I arrow down onto local machine I receive "cannot open HKEY_LOCAL_MACHINE Error opening key"How can I retrieve that admin value then?Further yet, why can't I retrieve the $value value then if I can retrieve the $adminval? I checked his machine and the $value is installed, but I receive a blank string when I msgbox $value. Weird. Edited March 10, 2008 by notta Link to comment Share on other sites More sharing options...
notta Posted March 10, 2008 Author Share Posted March 10, 2008 Well I figured it out. I used currentcontrolset key for the admin key and it works like a charm now. I have a new problem though. When I build an exe and try to "run as" a user with more rights I receive the error "Error: Expected a "=" operator in assignment statement." Our admin accounts start with a # sign, so when I run the .exe as myself the exe works fine, but when I run with my account that has the # sign in front I receive the error above. I tried logging in with the #account so I didn't have to use the runas feature but I still received the same error. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now