Navigation

1/15/2015

Visual basic to access CMD or Shell commands

Wanted to run CMD   NET USER /DOMAIN  
from vb script, and return password expiration date:



Dim objShell, objWshScriptExec, objStdOut, strLine, bolFoundFlag
bolFoundFlag = FALSE

Set objShell = CreateObject("WScript.Shell")
'Set objWshScriptExec = objShell.Exec("ipconfig /all")
Set objWshScriptExec = objShell.Exec("NET USER /DOMAIN " & strName)

Set objStdOut = objWshScriptExec.StdOut

While Not objStdOut.AtEndOfStream
   strLine = objStdOut.ReadLine
   ' english windows
   If InStr(strLine,"Password expires") Then
       response.Write(strName & ":&nbsp;&nbsp; " & strLine & "<p>")
       bolFoundFlag = TRUE
   ' french windows      
   ElseIf InStr(strLine,"found") Then
      response.Write( strLine & "<p>")  
   End If
  
'   response.Write(strLine & " <br>")
Wend

No comments:

Post a Comment