Jump to content

Recommended Posts

Posted

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?

Posted

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.

Posted

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"
Posted (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 by RajASP
Posted

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.

Posted

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?

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...