ASut Posted August 24, 2011 Posted August 24, 2011 Hi, I need to perform some adminstrative tasks in win 7 by using cmd.exe, but some of them need admin right (e.g netsh interface ipv4 set subinterface). The following code don't work,since it do not have admin right #include <Process.au3> _RunDos("netsh interface ipv4 set subinterface") so how can I run the cmd with admin right.
jvanegmond Posted August 24, 2011 Posted August 24, 2011 #RequireAdmin #include <Process.au3> _RunDos("netsh interface ipv4 set subinterface") github.com/jvanegmond
LurchMan Posted August 24, 2011 Posted August 24, 2011 (edited) Hi, I need to perform some adminstrative tasks in win 7 by using cmd.exe, but some of them need admin right (e.g netsh interface ipv4 set subinterface). The following code don't work,since it do not have admin right #include <Process.au3> _RunDos("netsh interface ipv4 set subinterface") so how can I run the cmd with admin right. Try this: $sUser = "username" $sPass = "pass" $sDomain = "domain" $sCMD = "netsh interface ipv4 set subinterface" RunAs ($sUser, $sDomain, $sPass, 0, "cmd /c " & $sCMD) Edited August 24, 2011 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
ASut Posted August 25, 2011 Author Posted August 25, 2011 #RequireAdmin #include <Process.au3> _RunDos("netsh interface ipv4 set subinterface") Thanks for the help, #RequireAdmin seems it require Admin right to run the au3, but not the cmd command.
ASut Posted August 25, 2011 Author Posted August 25, 2011 Try this: $sUser = "username" $sPass = "pass" $sDomain = "domain" $sCMD = "netsh interface ipv4 set subinterface" RunAs ($sUser, $sDomain, $sPass, 0, "cmd /c " & $sCMD) Since the computers are not belong to the domain, and the admin accounts of the pc are not the same, so how can I modify the code to make it more convenience to use, suppose all the currently logged on users have admin right and do not have password? The currently logged on users name can be obtain by $sUser = @UserName.
LurchMan Posted August 25, 2011 Posted August 25, 2011 (edited) Since the computers are not belong to the domain, and the admin accounts of the pc are not the same, so how can I modify the code to make it more convenience to use, suppose all the currently logged on users have admin right and do not have password?The currently logged on users name can be obtain by $sUser = @UserName.Are you able to just right click on the script and choose "Run as Administrator"? I guess I'm not fully understanding what it is that you want. Edited August 25, 2011 by LurchMan Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
ASut Posted August 25, 2011 Author Posted August 25, 2011 Are you able to just right click on the script and choose "Run as Administrator"? I guess I'm not fully understanding what it is that you want.Sure, I was able to right click on the script and choose "Run as Administrator", I just want to Disable Autotuning in win 7 by use "netsh interface tcp set global autotuning=disabled", this command needs to run command prompt as administrator.Sorry for me poor English.
LurchMan Posted August 25, 2011 Posted August 25, 2011 Sure, I was able to right click on the script and choose "Run as Administrator", I just want to Disable Autotuning in win 7 by use "netsh interface tcp set global autotuning=disabled", this command needs to run command prompt as administrator.Sorry for me poor English.So why not just build a simple CMD file and use right click run as admin when you need to run it? This would be the same as opening up a cmd prompt as administrator and typing it in as far as I know. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
ASut Posted August 26, 2011 Author Posted August 26, 2011 Because it is one of the functions of the program, other functions include change computer name, set computer IP address etc, so I want to make all function in one file. Moreover, I want to write more code as practice. Btw, thanks for the help.
LurchMan Posted August 26, 2011 Posted August 26, 2011 With windows 7 you might just have to use IsAdmin () and check at the start of your script to make sure they have admin rights before you run it like so: If Not IsAdmin () Then MsgBox (16, "Error", "Admin rights are required to run this program.") Exit EndIf Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.
revertex Posted August 26, 2011 Posted August 26, 2011 I use autoit a lot do do something close you want, not in a domain enviroment, but to allow regular users to run certain things under admin credentials without know admin password. Some commands works in win7, others don't, it's a trial and error. Local $sUserName = "admin" Local $sPassword = "passwd" RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c " & 'netsh interface ipv4 set subinterface', "", @SW_HIDE)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now