WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Vista

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

RegSetValue HKEY_LOCAL_MACHINE Error 1452 on Vista

 Keywords:  

Question:

I wnt to see if the current user has administrative rights. So, I am attempting to write to the HKEY_LOCAL_MACHINE registry key on Vista using RegSetValue. Yet even though I am running as administrator I am getting the error 1452: RegOpenKey unable to Open (Create) registry key. Why?
:CheckLocalAdmin
RegOpenFlags(2)
LocalAdmin=@TRUE
Admin="0"
ErrorMode(@Off)
RegSetValue(@REGMACHINE,"System\CurrentControlSet\Control[Admin]","1")
Admin=RegQueryValue(@REGMACHINE,"System\CurrentControlSet\Control[Admin]")
RegDelValue(@REGMACHINE,"System\CurrentControlSet\Control[Admin]")
ErrorMode(@Cancel)
If Admin!="1"
	LocalAdmin=@FALSE
endif
Return

Answer:

Looks likes Windows Vista is clamping down on Windows applications that require administrative privileges. Specifically applications that 'unnecessarily' write to the HKEY_LOCAL_MACHINE (HKLM) or system parts of the file system.

For example, HKEY_LOCAL_MACHINE only grants KEY_WRITE to administrators and SYSTEM Accounts. An application that requests KEY_WRITE to HKEY_LOCAL_MACHINE will not work with UAC enabled. Reference: http://msdn2.microsoft.com/en-us/library/aa480150.aspx I am not sure you will be able to use that script to determine Administrative privileges any longer. I was able to get the RegSetValue to work if I included a manifest with the Requested Execution Level of 'RequireAdministrator'. However the script will then prompt for an administrator user name and password. Which kind of defies the purpose of a script determining administrative rights.

I just spoke to the developers. Currently there is no built in function to check if the current user has administrator privileges on Vista. However, we are currently developing some UAC functions that should be available in the next release of WinBatch (2007C). One of these functions should be able to tell you if the current logged in user has administrative privileges.

What exactly are you trying to accomplish? Currently you can still use ErrorMode or IntControl 73 to capture errors for the specific administrative operation, if the function errors then you might be able to assume it doesn't have the adminstrative rights depending on the operation. Keep your eye out for the next release of WinBatch 2007C.


Article ID:   W17298
File Created: 2007:07:03:14:29:24
Last Updated: 2007:07:03:14:29:24