I have recently been working on a project that requires the user's password to be copied to the clipboard. I have this much:
set usr to short user name of (system info)
repeat
display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
set pswd to text returned of the result
try
set a to do shell script "echo test" user name usr password pswd with administrator privileges
exit repeat
end try
end repeat
set the clipboard to a
However, the clipboard simply sets to "test," presumably from where it says "echo test"
How do I fix this problem to set the password entered to the clipboard?
Try:
set the clipboard to pswd
Related
I have a login system that works well, using XML files to store logins, and then I can read the users and passwords, see if it matches, if it does, move to the next form, if it doesn't, error message.
However, when the form switches over, I want to be able to display the username in the to left corner, so the user knows who they are displayed as. But I don't know how to memorise the specific user that logged in on the previous form onto the new form now?
I tried making a "public variable" (sort of hard to do for me, not sure if i even did it right), which will read the textbok that the user inputs their name in if the username was correct, and gets dipaslayed for the next form. I don't thin the public vairable worked very well.
If BlnUserFound = True Then
'ActiveUser is the "public vairable"
ActiveUser = tbxUser.Text
'Open the main screen
Me.Hide()
Home.Show()
Else
MessageBox.Show("User Details Not found" & vbCrLf _
& "Please Try Again", "Login Error")
End If
What am I doing wrong?!
Just simply connect it to another new variable name and use it in form 2 e.g
dim ActiveUser2 as string
ActiveUser2 = Form1.ActiveUser then just simply easiest way would be have a label or something on your form, set it to not visible and then just apply ActiveUser2.text to the Label.Text
I'm trying to update some data into a SharePoint document and while trying this in local environment I do not face any issue.
But when I try to do the same in virtual desktop, I couldn't make it. I'm being populated with Windows Alert to key-in username & password. I've tried using 'SendKeys' for this scenario, but it doesn't make sense.
....
SendKeys "abc\ATX123",5
SendKeys "Password1",5
SendKeys "{ENTER}",5
....
This snippet is just passing 'ENTER' without entering ID & Pwd. Can anyone suggest me some possible solution, please?
Finally, I've found a way to achieve this requirement,,,,, bit indirect, but that was the only way I could find at the end.
What I did is simple - just created one windows scripted file 'Logon.vbs' to handle that popup screen and called the vbs in VBA.
Refer to the sample below, if you're looking for something like this:
Windows Script:
'Creating an script object
Set oWSH = WScript.CreateObject("WScript.Shell")
'Activating alert screen
oWSH.AppActivate ("Windows Security")
'Passing the value UserName/UserID
oWSH.SendKeys "USERNAME" 'ensure to complete the username with apropriate domain e.g., abc/A123456
'Changing the focus to password textbox
oWSH.SendKeys "{TAB}"
'Passing the value password
oWSH.SendKeys "PASSWORD"
'Clicking enter to complete the screen
oWSH.SendKeys "{ENTER}"
'Releasing the script object
Set oWSH = Nothing
VBA code to call the VBS script - Logon.vbs:
Shell "WScript C:\Users\ABC\Desktop\Logon.vbs", vbNormalFocus
First of all you'll want to SendKeys "yourString", Boolean. As I know the SendKeys command wants a True or a False as second input.
You could also try "tabbing" from a field to another:
SendKeys "abc\ATX123", True
SendKeys "{TAB}", True
SendKeys "Password1", True
SendKeys "{ENTER}", True
if the first one didn't get get written, maybe the focus is on another component of the userform. Try "tabbing" to find out if your "Username" textbox is yet activated as the UserForm appears. In case it isn't you could also try to set some focus
I was recently working on an AppleScript project that would require the user's password to be copied to the clipboard for later use. I already have the part where the user is prompted for their password but how do I set the text returned (their password) to the clipboard. My current code gives me the error: Can’t make text returned of «script» into type text. This is what I have so far:
set usr to short user name of (system info)
repeat
display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
set pswd to text returned of the result
try
do shell script "echo test" user name usr password pswd with administrator privileges
exit repeat
end try
end repeat
set a to (text returned) as list
set AppleScript's text item delimiters to linefeed
set a to a as text
set the clipboard to a
When running shell scripts via do shell script I typically use a variable within the applescript to capture the result. I'm not sure if there is a "right" way to do this, but with your script I removed
set a to (text returned) as list
set AppleScript's text item delimiters to linefeed
set a to a as text
and captured the result of the do shell script command as the variable a, which I then put on the clipboard. Here is the modified script:
set usr to short user name of (system info)
repeat
display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
set pswd to text returned of the result
try
set a to do shell script "echo test" user name usr password pswd with administrator privileges
exit repeat
end try
end repeat
set the clipboard to a
If you wanted to slim it down even more, you could eliminate the variable a altogether and capture the result of the do shell script command directly to the clipboard:
set usr to short user name of (system info)
repeat
display dialog "Please enter login password to continue:" default answer "" buttons {"Submit"} with title "Enter password" with icon stop with hidden answer
set pswd to text returned of the result
try
set the clipboard to (do shell script "echo test" user name usr password pswd with administrator privileges)
exit repeat
end try
end repeat
I am trying to get the logged in username of the user by using VBS.
I tried some codes which works when I run the script directly (Double Clicking it)
Set wshNetwork = CreateObject("WScript.Network")
strUser = wshNetwork.Username
WScript.Echo "Current User: " & strUser
However, what I need to do is to use CMD to run a scheduled task using the AT command.
When it ran, the username would be the computer's name instead of the logged in user.
This problem also occurs when I run CMD as administrator and use wscript to run the script.
Is there any way to bypass this context and get the logged in user instead of the one that runs the script?
The command
query session console
should provide what you need
For an easier to parse
quser console
EDITED - Included sample vbs code
Dim strCmd
strCmd = "cmd /q /c ""quser console | find /i ""console"" "" "
Dim buffer
buffer = WScript.CreateObject("WScript.Shell").Exec(strCmd).StdOut.ReadAll()
Dim c, consoleUserName
c = InStr(buffer,"console")
If c > 2 Then
consoleUserName = Trim(Mid(buffer,2,c-2))
Else
consoleUserName = ""
End If
WScript.Echo consoleUserName
I suggest you execute the command
set
from the prompt. It may reveal a few items that are set in the environment that may be of interest.
set user
will censor the list so that only variables that start user will be displayed.
I am making an app that requires root privileges. I am new to applscript and apologize if this is a dumb question but what I am trying to do is check whether a password is correct. I get the password string from a prompt like this:
set thePass to the text returned of (display dialog "I need you to enter your password" default answer "" buttons {"Okay"} default button 1 with icon file ((path to resource "Icon.icns") as text) with hidden answer)
I need to check whether thePass is actually their password before proceeding. I do not want to just use the default password prompt. Is there a way to do this?
I already tried a try, on error statement to test the password, it just prompts for the password with the default prompt if the one entered is incorrect.
Okay here is how I just solved it:
1) Get the password in a variable
2) Try to use sudo to run a command (using stdin as input), this will fail if the password is incorrect
try
do shell script "echo '" & thePass & "' | sudo -S :"
onerror
display alert "Incorrect Password!"
end try
No idea what you're trying to do, but if you want to execute a shell script using sudo you should do
do shell script shellScriptVariable with administrator privileges
without the "sudo" in the shell script. You'll automatically get an error dialog if the password is wrong.