im trying coding metin2 bot but it dont work. Because that python script not working with admin permissions. How do i run script with admin perm?
I just tried some code blocks. First one:
import admin
if not admin.isUserAdmin():
admin.runAsAdmin()
else:
print("I am not root :(")
But it dont work. It gave me an error like this:
Traceback (most recent call last):
File "c:\Users\...\Desktop\...\testmetin.py", line 3, in <module>
if not admin.isUserAdmin():
AttributeError: module 'admin' has no attribute 'isUserAdmin'
Second one:
import os
import sys
import win32com.shell.shell as shell
ASADMIN = 'asadmin'
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] sys.argv[1:] [ASADMIN])
shell.ShellExecuteEx(lpVerb='runas', lpFile=sys.executable, lpParameters=params)
sys.exit(0)
print ("I am root now.")
Again its gave me an error like this: "Import "win32com.shell.shell" could not be resolved"
It is keep continue like this. Please help me guys. I spent 2 days for this.
CodePudding user response:
In Windows:
Start->Task Scheduler
Action->Create Task
Run whether user is logged on or not
Change User or Group
And then under Actions
point it to your program. This will launch the job as your user you have picked, with those permissions.
Note, under Actions
after you point to your program, you may have to fill the Start in
section. For me if my program live here:
d:\git\code\python\test.py
I have to put:
d:\git\code\python
in the Start in