×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help With Login Script

Help With Login Script

Help With Login Script

(OP)
Hey guys, first time poster.

I'm trying to create a script that I can put in my startup folder so whenever I login to Windows explorer.exe is closed until a password is entered and if entered incorrectly, you're logged out. Essentially I'm having trouble with the Inputbox code, I want my password to be masked with an asterisks or bullet point as it usually is when you enter your password on an online site.

CODE --> VBS

password = "PasswordExample"
strComputer = "."
strExe = "taskkill /F /IM explorer.exe"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")

' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe

'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
Do 
returnvalue = InputBox ( "Welcome back, John","Please enter your password:")
Select case returnvalue
Case Password
MsgBox "Password Accepted"

strComputer = "."
strExe = "explorer.exe"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")

' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe

'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
Exit Do
Case Else
MsgBox "Error",0,"Oops"
strComputer = "."
strExe = "shutdown.exe -l"
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
WScript.echo "Created: " & strExe & " on " & strComputer
WSCript.Quit
End select
Loop 


Line 18 is where I'm having trouble, I'm not sure what code to enter.
Thanks in advance guyz.

RE: Help With Login Script

What is it you are trying to achieve?

RE: Help With Login Script

(OP)
I want my password to be masked with an asterisks or bullet point as it usually is when you enter your password on an online site. So as opposed to "ExamplePassword" showing up in the field, I want "***************" to come up as I type.

RE: Help With Login Script

IMO with Inputbox() it's not possible.
I'm using on command line this function:

CODE

function getpass( myPrompt )
  ' read password from command line
  dim objPassword
  set objPassword = CreateObject( "ScriptPW.Password" )
  WScript.StdOut.write myPrompt
  ' return password
  getpass = objPassword.GetPassword()
  WScript.StdOut.writeline
end function 

Usage example:

CODE

'## Enter Login-Data
WScript.StdOut.write("AS/400 name : ") : csebk  = WScript.StdIn.readline()
WScript.StdOut.write("User Id     : ") : userid = WScript.StdIn.readline()
' Using getpass for getting password
pwd = getpass("Password    : ") : WScript.StdOut.writeline

'## using ADO
' Connection String
connection_string =  "PROVIDER=IBMDA400;DATA SOURCE=" & csebk & _
                     "; USER ID=" & userid & "; PASSWORD=" & pwd

...
... 

RE: Help With Login Script

Btw, for the method I posted you will need scriptpw.dll, which is no more available on Windows 7.
I downloaded it from Windows XP and registered with

CODE

regsvr32 scriptpw.dll 
and my old scripts work on Windows 7 too.

RE: Help With Login Script

>I want my password to be masked

Yeah, I can see what the code is trying to do, but what I really wanted to know is what you were actually hoping to achieve with this code. Why, for example, do you need to close explorer?

RE: Help With Login Script

To mask the password you can use Internet Explorer. There are a ton of samples out there if you google vbscript password prompt InternetExplorer.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Help With Login Script

Another option is to simply use PowerShell which has the Get-Cred cmdlet for doing this exact task. Should you want to try that I can help with code int he PowerShell forum.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: Help With Login Script

Here is how to enter a password using IE as the means to mask the characters.

CODE --> VBScript

strPw = GetPassword( "Please enter Admin password:" )
WScript.Echo "Your password is: " & strPw

Function GetPassword( myPrompt )
    Set objIE = CreateObject( "InternetExplorer.Application" )
    objIE.Navigate "about:blank"
    objIE.Document.Title = "Password " & String( 100, "." )
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 320
    objIE.Height         = 180
    Do While objIE.Busy
        WScript.Sleep 200
    Loop
    ' Insert the HTML code to prompt for a password
    objIE.Document.Body.InnerHTML = "<div align=""center""><p>" & myPrompt _
                                  & "</p><p><input type=""password"" size=""20"" " _
                                  & "id=""Password""></p><p><input type=" _
                                  & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
                                  & "<input type=""submit"" value="" OK "" " _
                                  & "onclick=""VBScript:OK.Value=1""></p></div>"
    
    objIE.Document.Body.Style.overflow = "auto"
    objIE.Visible = True
    objIE.Document.All.Password.Focus

    On Error Resume Next
    Do While objIE.Document.All.OK.Value = 0
        WScript.Sleep 200
        If Err Then    'user clicked red X (or alt-F4) to close IE window
            IELogin = Array( "", "" )
            objIE.Quit
            Set objIE = Nothing
            Exit Function
        End if
    Loop
    On Error Goto 0

    ' Read the password from the dialog window
    GetPassword = objIE.Document.All.Password.Value

    ' Close and release the object
    objIE.Quit
    Set objIE = Nothing
End Function 

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close