Hi together
I try to use the commands "FileDelete" and "FileCreateShortcut" but they only work, if I start the program as administrator. I know that there's the possibility to use the "Run as" command, but this one only works for executing other programs, I guess. So my question is... is there a way to use these commands "FileDelete" and "FileCreateShortcut" as an administrator without starting the entire program as administrator? I can also write the username and password of the administrator inside the programs. So any help would be very appreciated.
Thanks,
Thomas
How to use Autohotkey commands with admin rights?
-
- Posts: 1
- Joined: 19 Jan 2017, 09:49
Re: How to use Autohotkey commands with admin rights?
No.
The script is a program. You can have the script run itself as administrator, as you would for any other program. See A_IsAdmin.
The script is a program. You can have the script run itself as administrator, as you would for any other program. See A_IsAdmin.
Re: How to use Autohotkey commands with admin rights?
Hm okay.
I try to delete a file with administrator rights. I start cmd (comspec) after I used RunAs to introduce the administrator credentials. Starting the device manager for example works like a charm. But when I try to delete a file it always says, "Access denied" in the cmd window, even though I have the administrator rights. When I do it "by hand", so not using the autohotkey script, I don't get the error and the file is deleted.
Can someone help me what's going on here?
Thanks,
Thomas
I try to delete a file with administrator rights. I start cmd (comspec) after I used RunAs to introduce the administrator credentials. Starting the device manager for example works like a charm. But when I try to delete a file it always says, "Access denied" in the cmd window, even though I have the administrator rights. When I do it "by hand", so not using the autohotkey script, I don't get the error and the file is deleted.
Can someone help me what's going on here?
Thanks,
Thomas
Re: How to use Autohotkey commands with admin rights?
Chances are that you are on a system with UAC, where RunAs is not sufficient to elevate a process. Again,
... and follow the links from there.
Or you could read the remarks in the documentation for RunAs, which tell you the same thing.
... by which, I mean look it up in the help file/documentation index.I wrote:See A_IsAdmin.
... and follow the links from there.
Or you could read the remarks in the documentation for RunAs, which tell you the same thing.
Re: How to use Autohotkey commands with admin rights?
add this head of script
RunAsAdmin()
and this function
RunAsAdmin()
and this function
Code: Select all
RunAsAdmin() {
Loop, %0% {
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
params .= A_Space . param
}
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
if not A_IsAdmin
{
If A_IsCompiled
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
Else
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
ExitApp
}
}
Re: How to use Autohotkey commands with admin rights?
@Lexikos
Problem is, even running the entire script or compiled program as administrator doesn't work.
I'll try the suggestion by masheen although I don't understand it because I'm a beginner. Do I have to change something to my needs?
Thanks,
Thomas
Problem is, even running the entire script or compiled program as administrator doesn't work.
I'll try the suggestion by masheen although I don't understand it because I'm a beginner. Do I have to change something to my needs?
Thanks,
Thomas
Re: How to use Autohotkey commands with admin rights?
I try to use the commands "FileDelete" and "FileCreateShortcut" but they only work, if I start the program as administrator.
These two statements are contradictory. Which is it?Problem is, even running the entire script or compiled program as administrator doesn't work.
Re: How to use Autohotkey commands with admin rights?
I tried two different ways. First I used the command from autohotkey which works when I start the program as administrator. I then hoped that starting cmd as an administrator from the script would do the trick. When I try to use cmd from the script even starting the program as an administrator the file isn't deleted. I don't understand that...
Re: How to use Autohotkey commands with admin rights?
"used the command from autohotkey [...] when I start the program as administrator" and "use cmd from the script [...] starting the program as an administrator" mean the same thing, yet you say one "works" and the other "doesn't".
If you can't give a better explanation, post both versions of your script.
If you can't give a better explanation, post both versions of your script.
Re: How to use Autohotkey commands with admin rights?
If I use the commands "FileDelete" and "FileCreateShortcut", then it will work when I run the script as administrator.
If I use the commands "comspec" and "del xy" it won't work even when I run the script as administrator.
If I use the commands "comspec" and "del xy" it won't work even when I run the script as administrator.
Re: How to use Autohotkey commands with admin rights?
So use FileDelete.
Re: How to use Autohotkey commands with admin rights?
Yeah I know, but I was looking for a way to not have it to run as administrator. Is there no way to put the administrator password inside the script so it will work?
Re: How to use Autohotkey commands with admin rights?
If the file permissions only allow an administrator to delete the file, you must run as administrator. There is no getting around it, only different methods of running as administrator.
See the pointer I gave in my first reply, which leads to having the script re-launching itself as administrator.
See the pointer I gave in my first reply, which leads to having the script re-launching itself as administrator.
Who is online
Users browsing this forum: alawsareps, mebelantikjaya, mikeyww, RussF and 305 guests