Jump to content
Sign in to follow this  
RajASP

Help with cmd through autoit

Recommended Posts

RajASP

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?

Share this post


Link to post
Share on other sites
somdcomputerguy

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.

Share this post


Link to post
Share on other sites
RajASP

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.

Share this post


Link to post
Share on other sites
JoHanatCent

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"

Share this post


Link to post
Share on other sites
RajASP

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 by RajASP

Share this post


Link to post
Share on other sites
RajASP

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.

Share this post


Link to post
Share on other sites
JoHanatCent

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?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×