Sign in to follow this  
Followers 0
netman74501

Need to know how to do stuff while a password prompt is up.

8 posts in this topic

#1 ·  Posted (edited)

The password prompt pause the script, so how would I do things while the prompt is up? I work for a library and have the need to password protect the command prompt so that no one but us can run it. Right now I have a script that checks for the process, pauses it and displays the password box but, if another command prompt is opened while the password box is open then they can do what they please until the password box times out. How do I continue the check for a second existence of the command prompt while the password box is open? I am not a work right now so I don't have the script to post. I will post it tomorrow when I am back at work if it would help to see it. Thanks in advance.

Edit:

I just had a thought. If I could block all input, (including the mouse, ctrl-alt-delete and anything else used to escape things), to everything but the password input box then I wouldn't have the need to check anything as they wouldn't be able to run it. Basically like windows vista's user account control password dialog.

Edited by netman74501

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You could create a custom gui so your script could still run while your custom password prompt was present. I pretty sure you cannot block ctrl alt del.

Edited by qazwsx

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You could create a custom gui so your script could still run while your custom password prompt was present. I pretty sure you cannot block ctrl alt del.

Well, here's my script if it helps:

#NoTrayIcon
#include <Misc.au3>
HotKeySet("^{F9}", "_Run")

Func _Run()
    Run("cmd.exe")
EndFunc

_Singleton("cmdblock")

While 1
    
    If ProcessExists("cmd.exe") Or  ProcessExists("ntvdm.exe") Then

        Do
            If ProcessExists("cmd.exe") Then
                _ProcessSuspend("cmd.exe")
                $proc="cmd"
            ElseIf ProcessExists("ntvdm.exe") Then
                ProcessClose("ntvdm.exe")
                MsgBox(0, "Access Denied", "Command.com is disabled on this computer please use the Command Interpreter instead.", 30)
                $proc="ntvdm"
                ExitLoop
            EndIf
            
            $pass = InputBox ("Enter Password", "Please enter the administrator password to run the ""Command Interpreter"".","","*",150,145,-1,-1,10)
            
            If @error == "1" Or @error == "2" Then
                ProcessClose("cmd.exe")
                ExitLoop
            EndIf
                
            If $pass <> "password" Then
        
                MsgBox (0,"Warning" , "The Password is incorrect." & @CRLF & "Please try again.")
                
            EndIf
        
        Until $pass == "password"
        
        If $proc="cmd" Then
        _ProcessResume("cmd.exe")
        ProcessWaitClose("cmd.exe")
        Endif
    
    EndIf
    
    Sleep(100)
    
WEnd



Func _ProcessSuspend($process)
$processid = ProcessExists($process)
If $processid Then
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid)
    $i_sucess = DllCall("ntdll.dll","int","NtSuspendProcess","int",$ai_Handle[0])
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle)
    If IsArray($i_sucess) Then 
        Return 1
    Else
        SetError(1)
        Return 0
    Endif
Else
    SetError(2)
    Return 0
Endif
EndFunc

Func _ProcessResume($process)
$processid = ProcessExists($process)
If $processid Then
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid)
    $i_sucess = DllCall("ntdll.dll","int","NtResumeProcess","int",$ai_Handle[0])
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle)
    If IsArray($i_sucess) Then 
        Return 1
    Else
        SetError(1)
        Return 0
    Endif
Else
    SetError(2)
    Return 0
Endif
EndFunc

I'm not exactly sure how to add in a custom GUI/Password Box either. I'll see if I can come up with a custom GUI a 'lil later tonight. Work is just killing me right now. No free time. :) What I meant about blocking all input was that, well. Ummm. Basically I envisioned all of the screen being frozen except for the password box for as long as it was up. Meaning they could only interact with the password box. But, I guess that is not possible with autoit. So, for now I need to be able to check if another instance of the command prompt is running and freeze each instance that occurs.

Edit:

I forgot to mention that the process suspend and resume functions were from a UDF I found here on the forums. I am not advanced enough to know anything about dllcalls or that sort. Just thought I'd throw that in in case it was useful to know.

Edit again:

Got some free time. :) It's just not working out for me. I do not know how I can add my own gui to this script and still have it check for other instances of the command prompt at the same time.

Perhaps it is impossible.

Edited by netman74501

Share this post


Link to post
Share on other sites

It's not impossible. Go look at some gui examples.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It's not impossible. Go look at some gui examples.

I know how to create a GUI but, nevertheless I looked at several GUI examples which did not help. In fact I have already created a replica of what the inputbox command does for the password prompt. The GUI is not really the problem for me. I just don't know how to add it to this script. I don't mean to say that I don't know how to add it to the script at all; I just don't know how to add it in such a way that the script will keep checking for new instances of the command prompt. Maybe it is obvious to you, but if it is, it's not to me. I tried to rewrite the script but got nowhere. I just can't wrap my head around how to have it keep checking for new instances while the GUI is up. I'm pretty sure it will take select and case to a degree, or maybe oneventmode. I just don't know. If you could just point me in the right direction, that would be great.

Edited by netman74501

Share this post


Link to post
Share on other sites

In the main loop of the gui under case else, put in your function to check for the command prompt. If the command prompt is found take appropriate action. Create the gui as hidden and then show it when necessary.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

In the main loop of the gui under case else, put in your function to check for the command prompt. If the command prompt is found take appropriate action. Create the gui as hidden and then show it when necessary.

Well I have tried:

;#NoTrayIcon
#include <Misc.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
HotKeySet("^{F9}", "_Run")
_Singleton("cmdblock")
GUICreate("Enter Password", 180, 110, -1, -1, 0x94CC0A4C, 0x00050100)
GUICtrlCreateLabel("Please enter the administrator password to run the ""Command Interpreter"".", 10, 10, 162, 48)
$pass = GUICtrlCreateInput("", 10, 53, 162, 20, $ES_PASSWORD)
$ok = GUICtrlCreateButton("OK", 13, 78, 75, 23)
$cancel = GUICtrlCreateButton("Cancel", 94, 78, 75, 23)
$proc=""
GUISetState(@SW_HIDE)

While 1
    $msg = GUIGetMsg()
    Select
        
        Case $proc == "cmd"
            GUISetState()
            If $msg == $ok Then
                If $pass == "password" Then
                    _ProcessResume("cmd.exe")
                    GUISetState(@SW_HIDE)
                    $proc = ""
                EndIf
            EndIf
            
        Case $msg == $GUI_EVENT_CLOSE Or $msg == $cancel
            ProcessClose("cmd.exe")
            ExitLoop
            
        Case Else
            If ProcessExists("cmd.exe") Then
                _ProcessSuspend("cmd.exe")
                $proc="cmd"
            ElseIf ProcessExists("ntvdm.exe") Then
                ProcessClose("ntvdm.exe")
                MsgBox(0, "Access Denied", "Command.com is disabled on this computer please use the Command Interpreter instead.", 30)
            EndIf
            
    EndSelect           
    Sleep(100)
WEnd

Func _Run()
    Run("cmd.exe")
EndFunc

Func _ProcessSuspend($process)
$processid = ProcessExists($process)
If $processid Then
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid)
    $i_sucess = DllCall("ntdll.dll","int","NtSuspendProcess","int",$ai_Handle[0])
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle)
    If IsArray($i_sucess) Then 
        Return 1
    Else
        SetError(1)
        Return 0
    Endif
Else
    SetError(2)
    Return 0
Endif
EndFunc

Func _ProcessResume($process)
$processid = ProcessExists($process)
If $processid Then
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid)
    $i_sucess = DllCall("ntdll.dll","int","NtResumeProcess","int",$ai_Handle[0])
    DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle)
    If IsArray($i_sucess) Then 
        Return 1
    Else
        SetError(1)
        Return 0
    Endif
Else
    SetError(2)
    Return 0
Endif
EndFunc

Obviously this doesn't work so I am giving up. Thank you for your time.

Edited by netman74501

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Obviously this doesn't work so I am giving up. Thank you for your time.

Don't give up so easily. There are some problems with your code:

1. You need to get the Process ID of cmd.exe, store it in an array with a state of 'enabled' or 'disabled', OR if you want only one cmd.exe open, get the first cmd.exe's Process ID, store it - then do a ProcessList("cmd.exe") and sort through the array comparing PID's. You can close those that don't match.

2. You should probably set accelerators so that Enter and Esc keys work as normal:

Dim $aAccelerators[2][2]=[ ["{ENTER}",$ok], ["{ESC}", $cancel] ]

GUISetAccelerators($aAccelerators)

3. You aren't reading the password correctly. You need to do it this way:

If GUICtrlRead($pass) = "password" Then...

4. You need to change the logic of the 'Select' statements, and you need to move the check for cmd.exe outside of the Select/EndSelect statements (instead of 'Else')

Plus there's a number of other things.. but remember, Process ID is important to keep on hand - then you can truly identify which process(es) are allowed and which aren't

Edited by Ascend4nt

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