Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Login Script

Status
Not open for further replies.

Souptard

Programmer
Sep 13, 2015
2
0
0
IE
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:
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.
 
 http://files.engineering.com/getfile.aspx?folder=4d2b46c8-baf2-45d7-b576-add649c4caa2&file=Pass.vbs
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.
 
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

...
...
 
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.
 
>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?
 
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
Work SMARTER not HARDER.
 
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
Work SMARTER not HARDER.
 
Here is how to enter a password using IE as the means to mask the characters.

Code:
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
Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top