We use batch files to do simple installations of COM servers - mainly a few file copies and regsvr32s. Since regsvr32 writes to the registry's local machine hive, the batch must be run with administrative privileges. I'd like to be able to recognize when this is not the case, and let the user know before the installation fails.

A possible solution would be to try to create a file in system32, and then check if it exists. If it does, the user most probably (always?) has permissions to write to the registry as well. Otherwise, let the user know the installation will fail. However, I'm not sure how accurate the check is - I don't really want to be able to create (and then delete) files in system32, just install a COM server. Is there a better way?

The problem is most common with Windows 7 and 2008 - if there's a solution that will only work for them, so be it. I would, however, like to keep using simple batch files.


Why not try something innocuous, like:

%SystemRoot%\System32\net.exe file | %SystemRoot%\System32\findstr /l /c:"Access is denied."
echo Not an admin.

  • That sounds reasonable, thanks. Do you have any idea if the "Access is denied" string will remain so on localized versions of Windows, where English is not the main UI language? – eran Oct 13 '10 at 19:43
  • Sorry, no I don't. You could try just net file, followed by an %ERRORLEVEL% check. – Simon Catlin Oct 13 '10 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.