Sign in to follow this  
Followers 0
sandman

Su: Simulate the Linux 'su' command in CMD

9 posts in this topic

#1 ·  Posted (edited)

This is a little snippet that I just made. I got the idea from the implementation of something like apt-get called win-get, which was a pretty good idea. Now this is nowhere near as good, but it's somewhere.

The bad (and maybe good) thing is that when you use the command, it opens it in a new window.

Compile to su.exe and put in "C:\WINDOWS" or whatever for your OS.

; SU

; Become a super-user through CMD!! The 'su' command, kinda, for Windows.

#AutoIt3Wrapper_outfile=su.exe

Opt("RunErrorsFatal", 0)

If $cmdline[1] = "" Then
    Exit
Else
    $input = InputBox("Su", "Please enter the password for " & $cmdline[1] & ".")
    RunAsSet($cmdline[1], @ComputerName, $input)
    Run("cmd")
    If @error Then MsgBox(0, "Su", "Invalid username or password.")
EndIf

To use, for example:

C:\> su Administrator
An input box will pop up, asking you for the password. I wish I could make the prompt occur inside the CMD window, but I've no idea how.

Obviously I have to put a second parameter there.. because I don't think Windows has a user similar to root by default. This can be used for installing things with administrative levels while on a limited account... or just switching into another account quickly.

Happy su'ing! :):P:) :) (!) (!) (!) (!)

Edited by sandman

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites



Any comments??


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

Hello? Please?


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

Hello? Please?

Comment hungry? :) It looks nice.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Hi!

An alternate way is to use the windows command RunAs (help: runas /?)

But RunAs is not develop with AutoIt...

Share this post


Link to post
Share on other sites

Yeah, I would use runas if my intention was to get a command prompt:

CODE
C:\> runas /user:MyAdmin cmd

Enter the password for MyAdmin:

This will open the command window as a separate process. The first thing I usually do is run "color 4f" as my first command, just so I can easily tell that this is a "special" command prompt.

You might want to also check out MakeMeAdmin. I have long wanted to make an AutoIt version of MakeMeAdmin, but haven't gotten a Round Tuit. :)


BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

but haven't gotten a Round Tuit. :P

Here ya go :)

#include <GUIConstants.au3>
Opt("GUICoordMode", 1)

$Form1 = GUICreate("AForm1", 400, 400, -1, -1, BitOR($WS_SYSMENU,$WS_POPUPWINDOW,$WS_BORDER), 0)
GUISetBkColor(0xC0DCC0)
GUICtrlCreateLabel("A Round Tuit !", 50, 40, 300, 50, $SS_CENTER)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1,0xff0000)
GUICtrlCreateLabel("At Long Last, we have a" & @CRLF & "sufficient quantity for each of you" & @CRLF & "to have your own. Guard it with your life." & @CRLF & "These tuits are hard to come by, especially" & @CRLF & "the round ones. This is an idespensable item." & @CRLF & "It will help you become a more efficient worker." & @CRLF & "For years we have heard people say" & @CRLF & """I'll do it as soon as I get a Round Tuit""" & @CRLF & " Now that you have a round tuit of your" & @CRLF & "very own, many things that have been" & @CRLF & "needing to be accomplished" & @CRLF & "will get done", 50, 100, 300, 250, $SS_CENTER)
GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1,0xff0000)
_GuiRoundCorners($Form1, 0, 0, 400, 400)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
   ;;;;;;;
    EndSelect
WEnd

Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
   Dim $pos, $ret, $ret2
   $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long",  $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3,  "long", $i_y3)
   If $ret[0] Then
      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
      If $ret2[0] Then
         Return 1
      Else
         Return 0
      EndIf
   Else
      Return 0
   EndIf
EndFunc;==>_GuiRoundCorners


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

A Round Tuit !

Pretty. And pretty sweet. :)


BlueBearrOddly enough, this is what I do for fun.

Share this post


Link to post
Share on other sites

I made this because I thought RunAs was a bit too long. And now, since I am a cross-OS guy, I only have to remember one command :)

Also, I've been trying to make a 'sudo' command also, but I've been a bit idle in the programming sense.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

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  
Followers 0