Log Windows username from HTML file into txt file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Log Windows username from HTML file into txt file

  1. #1
    Join Date
    Apr 2009
    Posts
    3

    Log Windows username from HTML file into txt file

    Hi, I have the following code on and html file, but i cant make it work,
    Any Ideas ??? Please help : )
    -------------------------------------------
    Code:
    <script language="vbscript">
    
    function DoOnLoad()
    
    Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long 
    
    On Error GoTo LogFail
        
        Dim filenum As Integer
        Dim i As Integer
        Dim fic As String
        filenum = FreeFile
        logfile = "C:\over.log"
        Open logfile For Append As filenum
        Print #filenum, Date & " " & Time & ";" & Environ("UserName") & ";" & Environ("ComputerName") & ";"
        
        Close filenum
    
    LogFail:
    
    MsgBox "Errors has been detected.", vbExclamation, "Warning"
    
    end function
    
    </script>
    <html>
    <head>
    </head>
    <body onload="vbscript:DoOnLoad">
    Este archivo deberia logear en c:\over.log
    </body>
    </html>
    Last edited by Frlecube; April 27th, 2009 at 12:24 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Log Windows username from HTML file into txt file

    Not sure where you're getting the ENVIRON() variables, but
    Code:
    Date & " " & Time & ";"
    would be the same thing as NOW, although you could use FORMAT() to create the correct format.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009
    Posts
    3

    Re: Log Windows username from HTML file into txt file

    Done, just in case any1 need this:

    Code:
    <Script Language="VBScript">
    
    Option Explicit
    Dim objFSO, objFolder, objShell, objTextFile, objFile
    Dim strDirectory, strFile, strText
    Dim objNet
    strDirectory = "C:\test"
    strFile = "\log.txt"
    
    On Error Resume Next 
    
    Set objNet = CreateObject("WScript.NetWork")
    
    strText = Now & ";" & objNet.UserName & ";" &objNet.ComputerName & ";;;"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    If objFSO.FolderExists(strDirectory) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
    Else
       Set objFolder = objFSO.CreateFolder(strDirectory)
       WScript.Echo "Just created " & strDirectory
    End If
    
    If objFSO.FileExists(strDirectory & strFile) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
    Else
       Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
       Wscript.Echo "Just created " & strDirectory & strFile
    End If 
    
    set objFile = nothing
    set objFolder = nothing
    Const ForAppending = 8
    
    Set objTextFile = objFSO.OpenTextFile _
    (strDirectory & strFile, ForAppending, True)
    
    objTextFile.WriteLine(strText)
    objTextFile.Close
    
    Set objNet = Nothing 
    WScript.Quit
    
    
    </Script>
    <HTML>
    <HEAD> <title>UserInfo</title>
    </HEAD>
    <body scroll="no" leftmargin="0" topmargin="0"
    This Should Log your username on a txt file called log.txt located in c:\test
    </body>
    
    </HTML>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center