RajASP Posted July 11, 2011 Share Posted July 11, 2011 Hi guys,Sorry if I am not very clear, but I was wondering whether I could use cmd directly through AutoIt. To run my batch file as admin, I would use the following code:Run("cmd.exe") Send("elevate mybatfile.bat{ENTER}")This would lead to my batch file run as admin, and I could do things without much of a problem. But the problem here lies in that this script is not bulletproof. If i manage to somehow distract the computer, say ctrl+alt+delete, even if i do lock keys, the script will be disrupted. I want to run the cmd command directly from autoit. I am not exactly good at using @comspec either, if it can somehow be used here. So can someone give me help on how i should use the elevate mybatfile.bat thing directly from autoit? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted July 11, 2011 Share Posted July 11, 2011 Does this help?From the Helpfile:To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE) ; don't forget " " before "/c" - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
RajASP Posted July 11, 2011 Author Share Posted July 11, 2011 I took a look at that. Not too helpful. I tried all variations that i could imagine of the Run command with @COMSPEC. All of them just lead to the hourglass for less than half a second and nothing happens. It doesn't seem to work. Link to comment Share on other sites More sharing options...
JoHanatCent Posted July 12, 2011 Share Posted July 12, 2011 I took a look at that. Not too helpful. I tried all variations that i could imagine of the Run command with @COMSPEC. All of them just lead to the hourglass for less than half a second and nothing happens. It doesn't seem to work. Try this and post back what you see: $CommandName = "mybatfile.bat" Run(@ComSpec & " /k " & $CommandName, "", @SW_SHOW) ; don't forget " " before "/k" Link to comment Share on other sites More sharing options...
RajASP Posted July 12, 2011 Author Share Posted July 12, 2011 (edited) Wow man, thanks! It works! But can you explain to me how and why this works? And also how to use @comspec? What does the /k switch do? Thanks a million bud! Edited July 12, 2011 by RajASP Link to comment Share on other sites More sharing options...
RajASP Posted July 12, 2011 Author Share Posted July 12, 2011 Wow man now i understood, but we must use a switch. Why is that? The mistake i was doing was i was omitting the space, and putting quotes there instead (silly me). But it doesn't work without a switch. Link to comment Share on other sites More sharing options...
JoHanatCent Posted July 12, 2011 Share Posted July 12, 2011 Wow man now i understood, but we must use a switch. Why is that? The mistake i was doing was i was omitting the space, and putting quotes there instead (silly me). But it doesn't work without a switch.Some reading material? Link to comment Share on other sites More sharing options...
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