Request UAC from pyp/pypv
merkvilson last edited by merkvilson
Hello PluginCafe! :)
Is it possible to request UAC from python plugin to write/generate/download files into C4D's main plugins directory?
I know that this is possible without admin access in C4D's preferences folder, but this is not exactly what I need.
I'm trying to write a plugin which will be capable of downloading updates from the internet and replace itself with the new one.
I also need to use os.mkdir functions to create new dirs in the res folder.
On Pc as well as on Mac.
Traceback (most recent call last): File "'test plugin.pyp'", line 6, in <module> WindowsError: [Error 5] Access is denied: 'C:\\Program Files\\MAXON\\CINEMA 4D R18\\plugins\\Test 1 (Simple)\\New Folder'
merkvilson last edited by
btw, I don't know why the first line is sooo BIG
seems like I accidentally passed some symbol.
merkvilson last edited by
I found this code on stackoverflow but it has no effect in C4D.
Am I doing something wrong?
import ctypes, sys, os dirr = r"C:\Program Files\MAXON\Cinema 4D R20 Demo\new folder" def is_admin(): try: return ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1) except: return False if is_admin(): os.mkdir(dirr) else: ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(__file__), None, 1) os.mkdir(dirr)
a_block last edited by
no worries, the first line is so big because of a stray "=" on the next line, underlining the first to be interpreted as a heading.
I'll move this thread to the General Programming & Plugin Discussions category, because in the end C4D does not provide any means to provoke UAC, nor do we deem it necessary inside our API as it is a pretty system specific thing. Yet, the discussion might lead back to C4D related questions, and then I'll either happily move it back or we'll have a new thread in the Cinema 4D Development category.
In general I think, it would probably be better to convince your users to install the plugin into either the plugins folder in the "user folder" or even (assuming R20+) a completely separate directory added to the users prefs.
Another thought, while definitely possible with Python, I'd say an update mechanism should change/replace files while the main application is running. After all you can not be completely sure, which files the application decides to lock at certain points off time, in which case your updater would probably run into issues. My recommendation is to rather update by restarting the main app (for C++ it's inevitable anyway).