Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Why not try something innocuous, like:

%SystemRoot%\System32\net.exe file | %SystemRoot%\System32\findstr /l /c:"Access is denied."
if %ERRORLEVEL% NEQ 0 (
echo Not an admin.
exit
)

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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