> The application as to re-run itself using ShellExecute so it has to > know > if it already runs elevated or not. > > To do this I must use : > GetTokenInformation( > hToken, > TokenElevationType > )
What about: >>> from win32com.shell import shell >>> shell.IsUserAnAdmin() True ? See the docs though, to ensure you correctly handle the win2k etc cases (and it requires build 211) Alterntively, it seems to me that you can maybe *assume* you are not elevated first time you are run, and always attempt to re-execute yourself. For example: %python -c "import win32api;win32api.ShellExecute(0, 'runas', 'notepad.exe', None, '', 1)" If run from a normal command prompt, it will prompt for elevation - but if the command prompt is already elevated, it silently opens notepad. So, you could try something like: * Arrange for 'myprogram.exe' to be started. * myprogram.exe checks for a '-no-elevate' command line - if not there, it just re-executes itself, but *with* the '-no-elevate' param. Although this will always execute your program twice, it will only prompt for elevation when necessary. As you imply that the most common case is likely to *not* be elevated in the first instance, the net result is the same. Cheers, Mark _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32