Hello, I’m having problems with windows permission with my addon. I need to copy a few files into window’s startup folder. Non relevant but those scripts starts a server sockets. I’ve found ctypes.windll.shell32.ShellExecuteW.
The fowolling code actually opens a blender in background as admin but it’s not entering my main function. Is there any other way to run blender python as admin on windows??? Thx!
import bpy
import ctypes,sys
import os
from shutil import copyfile
class Install_script_Operator(bpy.types.Operator):
bl_idname = "scene.install_script"
bl_label = "Install_script"
def execute(self, context):
if self.is_admin():
# Code of your program here
pass
else:
# Re-run the program with admin rights
args = ['-b',
'-p',
__file__
]
ctypes.windll.shell32.ShellExecuteW(None, "runas", bpy.app.binary_path, " ".join(args), None, 1)
return {'FINISHED'}
def is_admin(self):
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def copy_scripts(self):
cur_dir = os.path.dirname(os.path.abspath(__file__))
files_to_copy = [cur_dir+'\\sockets\\server.py',cur_dir+'\\sockets\\server_render.py']
dst = os.path.expanduser("~") + '\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs'
for src in files_to_copy:
copyfile(src, dst)
if __name__ == '__main__':
'''
argv = sys.argv
dekstop=os.path.expanduser('~') + '\\Desktop\\'
os.chdir(dekstop)
with open(dekstop+'testtest.txt','w') as f:
f.write(str(argv) +"\n")
'''
cur_dir = os.path.dirname(os.path.abspath(__file__))
files_to_copy = [cur_dir+'\\sockets\\server.py',cur_dir+'\\sockets\\server_render.py']
dst = os.path.expanduser("~") + '\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs'
for src in files_to_copy:
copyfile(src, dst)